- md5
- 36b182952af67fcbef46254f57d729fd
- sha1
- b17dd1eb5429402ced96e74f7a35f0f148770a70
- sha256
- 38359f2cbb7d21f02b6b7e0a81119a1e046d561322c93daeba0651f96641ef58
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
<?php
/**
* Joomla! Content Management System
*
* @copyright Copyright (C) 2005 - 2019 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace Joomla\CMS\Serializer;
\defined('_JEXEC') or die;
use Joomla\CMS\Object\CMSObject;
use Joomla\CMS\Table\Table;
use Tobscure\JsonApi\AbstractSerializer;
/**
* Temporary serializer
*
* @since 4.0.0
*/
class JoomlaSerializer extends AbstractSerializer
{
/**
* Constructor.
*
* @param string $type The content type to be loaded
*
* @since 4.0.0
*/
public function __construct(string $type)
{
$this->type = $type;
}
/**
* Get the attributes array.
*
* @param Table|array|\stdClass|CMSobject $post The model
* @param array $fields The fields can be array or null
*
* @return array
*
* @since 4.0.0
*/
public function getAttributes($post, array $fields = null)
{
if (!($post instanceof Table) && !($post instanceof \stdClass) && !(\is_array($post))
&& !($post instanceof CMSObject))
{
$message = sprintf(
'Invalid argument for TableSerializer. Expected array or %s. Got %s',
Table::class,
\gettype($post)
);
throw new \InvalidArgumentException($message);
}
// The response from a standard ListModel query
if ($post instanceof \stdClass)
{
$post = (array) $post;
}
// The response from a standard AdminModel query
if ($post instanceof CMSObject)
{
$post = $post->getProperties();
}
// TODO: Find a way to make this an instance of TableInterface instead of the concrete class
if ($post instanceof Table)
{
$post = $post->getProperties();
}
return \is_array($fields) ? array_intersect_key($post, array_flip($fields)) : $post;
}
}
No other release has this exact content. See every version of this file.