CoreFiles by mySites.guru
Relationship.php83 lines, 1,528 bytes, from Joomla_5.2.0-Stable-Full_Package.zip
Raw History Compare with 5.1.4
md5
ece90682c577e30dfc51931d4e91a5e6
sha1
672bca7b96bc5e098956fc671c9a7ee5e22808fd
sha256
70ce7faaabb131ef6d398a5af55a75ced1017fbb8d591836aa7dc222cb22c13f
<?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;

class Relationship
{
    use LinksTrait;
    use MetaTrait;

    /**
     * The data object.
     *
     * @var \Tobscure\JsonApi\ElementInterface|null
     */
    protected $data;

    /**
     * Create a new relationship.
     *
     * @param \Tobscure\JsonApi\ElementInterface|null $data
     */
    public function __construct(ElementInterface $data = null)
    {
        $this->data = $data;
    }

    /**
     * Get the data object.
     *
     * @return \Tobscure\JsonApi\ElementInterface|null
     */
    public function getData()
    {
        return $this->data;
    }

    /**
     * Set the data object.
     *
     * @param \Tobscure\JsonApi\ElementInterface|null $data
     *
     * @return $this
     */
    public function setData($data)
    {
        $this->data = $data;

        return $this;
    }

    /**
     * Map everything to an array.
     *
     * @return array
     */
    public function toArray()
    {
        $array = [];

        if (! empty($this->data)) {
            $array['data'] = $this->data->toIdentifier();
        }

        if (! empty($this->meta)) {
            $array['meta'] = $this->meta;
        }

        if (! empty($this->links)) {
            $array['links'] = $this->links;
        }

        return $array;
    }
}

The same content is in 225 releases, Joomla 4.0.0-alpha7 to 6.0.0-beta3. See them all, or every version of this file.