[ Index ]

PHP Cross Reference of Joomla 4.2.2 documentation

title

Body

[close]

/libraries/vendor/tobscure/json-api/src/ -> Relationship.php (source)

   1  <?php
   2  
   3  /*
   4   * This file is part of JSON-API.
   5   *
   6   * (c) Toby Zerner <[email protected]>
   7   *
   8   * For the full copyright and license information, please view the LICENSE
   9   * file that was distributed with this source code.
  10   */
  11  
  12  namespace Tobscure\JsonApi;
  13  
  14  class Relationship
  15  {
  16      use LinksTrait;
  17      use MetaTrait;
  18  
  19      /**
  20       * The data object.
  21       *
  22       * @var \Tobscure\JsonApi\ElementInterface|null
  23       */
  24      protected $data;
  25  
  26      /**
  27       * Create a new relationship.
  28       *
  29       * @param \Tobscure\JsonApi\ElementInterface|null $data
  30       */
  31      public function __construct(ElementInterface $data = null)
  32      {
  33          $this->data = $data;
  34      }
  35  
  36      /**
  37       * Get the data object.
  38       *
  39       * @return \Tobscure\JsonApi\ElementInterface|null
  40       */
  41      public function getData()
  42      {
  43          return $this->data;
  44      }
  45  
  46      /**
  47       * Set the data object.
  48       *
  49       * @param \Tobscure\JsonApi\ElementInterface|null $data
  50       *
  51       * @return $this
  52       */
  53      public function setData($data)
  54      {
  55          $this->data = $data;
  56  
  57          return $this;
  58      }
  59  
  60      /**
  61       * Map everything to an array.
  62       *
  63       * @return array
  64       */
  65      public function toArray()
  66      {
  67          $array = [];
  68  
  69          if (! empty($this->data)) {
  70              $array['data'] = $this->data->toIdentifier();
  71          }
  72  
  73          if (! empty($this->meta)) {
  74              $array['meta'] = $this->meta;
  75          }
  76  
  77          if (! empty($this->links)) {
  78              $array['links'] = $this->links;
  79          }
  80  
  81          return $array;
  82      }
  83  }


Generated: Wed Sep 7 05:41:13 2022 Chilli.vc Blog - For Webmaster,Blog-Writer,System Admin and Domainer