- md5
- fb72e5d8ded0c9011f1fca66f6621f3a
- sha1
- 5456398864f5e75f745069faa1c8a19241f586f1
- sha256
- a5afe8bd7f88052a40d158dcdc5a4a0c1447e9683e5b965a370f855129a0b0fc
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
<?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;
}
}
The same content is in 201 releases, Joomla 4.0.0-alpha7 to 5.3.0-beta3. See them all, or every version of this file.