Skip to content

Commit

Permalink
Add the JSON API library to the repository (#24)
Browse files Browse the repository at this point in the history
  • Loading branch information
wilsonge authored Aug 3, 2017
1 parent 63acd7a commit 7d191de
Show file tree
Hide file tree
Showing 24 changed files with 2,031 additions and 8 deletions.
5 changes: 3 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@
"paragonie/random_compat": "~2.0",
"phpmailer/phpmailer": "~6.0@rc",
"symfony/polyfill-php56": "~1.0",
"symfony/yaml": "2.*"
"symfony/yaml": "2.*",
"tobscure/json-api": "^0.4.1"
},
"require-dev": {
"phpunit/phpunit": "^4.8.35",
Expand All @@ -74,4 +75,4 @@
"squizlabs/php_codesniffer": "~1.5",
"pear/cache_lite": "1.8.0"
}
}
}
62 changes: 56 additions & 6 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions libraries/vendor/composer/autoload_psr4.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

return array(
'Zend\\Diactoros\\' => array($vendorDir . '/zendframework/zend-diactoros/src'),
'Tobscure\\JsonApi\\' => array($vendorDir . '/tobscure/json-api/src'),
'Symfony\\Polyfill\\Util\\' => array($vendorDir . '/symfony/polyfill-util'),
'Symfony\\Polyfill\\Php56\\' => array($vendorDir . '/symfony/polyfill-php56'),
'Symfony\\Component\\Yaml\\' => array($vendorDir . '/symfony/yaml'),
Expand Down
8 changes: 8 additions & 0 deletions libraries/vendor/composer/autoload_static.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ class ComposerStaticInit423c8facdf90155590c7b49e979f3a1e
array (
'Zend\\Diactoros\\' => 15,
),
'T' =>
array (
'Tobscure\\JsonApi\\' => 17,
),
'S' =>
array (
'Symfony\\Polyfill\\Util\\' => 22,
Expand Down Expand Up @@ -81,6 +85,10 @@ class ComposerStaticInit423c8facdf90155590c7b49e979f3a1e
array (
0 => __DIR__ . '/..' . '/zendframework/zend-diactoros/src',
),
'Tobscure\\JsonApi\\' =>
array (
0 => __DIR__ . '/..' . '/tobscure/json-api/src',
),
'Symfony\\Polyfill\\Util\\' =>
array (
0 => __DIR__ . '/..' . '/symfony/polyfill-util',
Expand Down
52 changes: 52 additions & 0 deletions libraries/vendor/composer/installed.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
]
}
]
21 changes: 21 additions & 0 deletions libraries/vendor/tobscure/json-api/LICENSE
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.
35 changes: 35 additions & 0 deletions libraries/vendor/tobscure/json-api/composer.json
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 libraries/vendor/tobscure/json-api/src/AbstractSerializer.php
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;
}
}
Loading

0 comments on commit 7d191de

Please sign in to comment.