forked from joomla/joomla-cms
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add the JSON API library to the repository (#24)
- Loading branch information
Showing
24 changed files
with
2,031 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1697,5 +1697,57 @@ | |
"joomla", | ||
"router" | ||
] | ||
}, | ||
{ | ||
"name": "tobscure/json-api", | ||
"version": "v0.4.1", | ||
"version_normalized": "0.4.1.0", | ||
"source": { | ||
"type": "git", | ||
"url": "https://github.com/tobscure/json-api.git", | ||
"reference": "d4ba8437977c33a5189d95d9ffa751997f13b104" | ||
}, | ||
"dist": { | ||
"type": "zip", | ||
"url": "https://api.github.com/repos/tobscure/json-api/zipball/d4ba8437977c33a5189d95d9ffa751997f13b104", | ||
"reference": "d4ba8437977c33a5189d95d9ffa751997f13b104", | ||
"shasum": "" | ||
}, | ||
"require": { | ||
"php": "^5.5.9 || ^7.0" | ||
}, | ||
"require-dev": { | ||
"phpunit/phpunit": "^4.8 || ^5.0" | ||
}, | ||
"time": "2017-03-05T21:16:24+00:00", | ||
"type": "library", | ||
"extra": { | ||
"branch-alias": { | ||
"dev-master": "1.0-dev" | ||
} | ||
}, | ||
"installation-source": "dist", | ||
"autoload": { | ||
"psr-4": { | ||
"Tobscure\\JsonApi\\": "src/" | ||
} | ||
}, | ||
"notification-url": "https://packagist.org/downloads/", | ||
"license": [ | ||
"MIT" | ||
], | ||
"authors": [ | ||
{ | ||
"name": "Toby Zerner", | ||
"email": "[email protected]" | ||
} | ||
], | ||
"description": "JSON-API responses in PHP", | ||
"keywords": [ | ||
"api", | ||
"json", | ||
"jsonapi", | ||
"standard" | ||
] | ||
} | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
The MIT License (MIT) | ||
|
||
Copyright (c) 2014-2016 Toby Zerner <[email protected]> | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
{ | ||
"name": "tobscure/json-api", | ||
"description": "JSON-API responses in PHP", | ||
"keywords": ["json", "api", "standard", "jsonapi"], | ||
"license": "MIT", | ||
"authors": [ | ||
{ | ||
"name": "Toby Zerner", | ||
"email": "[email protected]" | ||
} | ||
], | ||
"require": { | ||
"php": "^5.5.9 || ^7.0" | ||
}, | ||
"require-dev": { | ||
"phpunit/phpunit": "^4.8 || ^5.0" | ||
}, | ||
"autoload": { | ||
"psr-4": { | ||
"Tobscure\\JsonApi\\": "src/" | ||
} | ||
}, | ||
"autoload-dev": { | ||
"psr-4": { | ||
"Tobscure\\Tests\\JsonApi\\": "tests/" | ||
} | ||
}, | ||
"extra": { | ||
"branch-alias": { | ||
"dev-master": "1.0-dev" | ||
} | ||
}, | ||
"minimum-stability": "dev", | ||
"prefer-stable": true | ||
} |
106 changes: 106 additions & 0 deletions
106
libraries/vendor/tobscure/json-api/src/AbstractSerializer.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of JSON-API. | ||
* | ||
* (c) Toby Zerner <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Tobscure\JsonApi; | ||
|
||
use LogicException; | ||
|
||
abstract class AbstractSerializer implements SerializerInterface | ||
{ | ||
/** | ||
* The type. | ||
* | ||
* @var string | ||
*/ | ||
protected $type; | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function getType($model) | ||
{ | ||
return $this->type; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function getId($model) | ||
{ | ||
return $model->id; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function getAttributes($model, array $fields = null) | ||
{ | ||
return []; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function getLinks($model) | ||
{ | ||
return []; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function getMeta($model) | ||
{ | ||
return []; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
* | ||
* @throws \LogicException | ||
*/ | ||
public function getRelationship($model, $name) | ||
{ | ||
$method = $this->getRelationshipMethodName($name); | ||
|
||
if (method_exists($this, $method)) { | ||
$relationship = $this->$method($model); | ||
|
||
if ($relationship !== null && ! ($relationship instanceof Relationship)) { | ||
throw new LogicException('Relationship method must return null or an instance of Tobscure\JsonApi\Relationship'); | ||
} | ||
|
||
return $relationship; | ||
} | ||
} | ||
|
||
/** | ||
* Get the serializer method name for the given relationship. | ||
* | ||
* snake_case and kebab-case are converted into camelCase. | ||
* | ||
* @param string $name | ||
* | ||
* @return string | ||
*/ | ||
private function getRelationshipMethodName($name) | ||
{ | ||
if (stripos($name, '-')) { | ||
$name = lcfirst(implode('', array_map('ucfirst', explode('-', $name)))); | ||
} | ||
|
||
if (stripos($name, '_')) { | ||
$name = lcfirst(implode('', array_map('ucfirst', explode('_', $name)))); | ||
} | ||
|
||
return $name; | ||
} | ||
} |
Oops, something went wrong.