[ Index ]

PHP Cross Reference of Joomla 4.2.2 documentation

title

Body

[close]

/libraries/src/Serializer/Events/ -> OnGetApiRelation.php (source)

   1  <?php
   2  
   3  /**
   4   * Joomla! Content Management System
   5   *
   6   * @copyright  (C) 2020 Open Source Matters, Inc. <https://www.joomla.org>
   7   * @license    GNU General Public License version 2 or later; see LICENSE.txt
   8   */
   9  
  10  namespace Joomla\CMS\Serializer\Events;
  11  
  12  use Joomla\CMS\Event\AbstractImmutableEvent;
  13  use Tobscure\JsonApi\Relationship;
  14  
  15  // phpcs:disable PSR1.Files.SideEffects
  16  \defined('_JEXEC') or die;
  17  // phpcs:enable PSR1.Files.SideEffects
  18  
  19  /**
  20   * Event for getting information on an API Relationship
  21   *
  22   * @since  4.0.0
  23   */
  24  final class OnGetApiRelation extends AbstractImmutableEvent
  25  {
  26      /**
  27       * The relationship
  28       *
  29       * @var     Relationship
  30       * @since   4.0.0
  31       */
  32      private $relationship;
  33  
  34      /**
  35       * Constructor.
  36       *
  37       * Mandatory arguments:
  38       * model        mixed           The model being used to render the resource.
  39       * field        string          The field name we wish to obtain a relationship for.
  40       * context      string          The content type of the api resource.
  41       *
  42       * @param   string  $name       The event name.
  43       * @param   array   $arguments  The event arguments.
  44       *
  45       * @since   4.0.0
  46       * @throws  \BadMethodCallException
  47       */
  48      public function __construct($name, array $arguments = array())
  49      {
  50          if (!\array_key_exists('model', $arguments)) {
  51              throw new \BadMethodCallException("Argument 'model' is required for event $name");
  52          }
  53  
  54          if (!\array_key_exists('field', $arguments)) {
  55              throw new \BadMethodCallException("Argument 'field' is required for event $name");
  56          }
  57  
  58          if (!\array_key_exists('context', $arguments)) {
  59              throw new \BadMethodCallException("Argument 'context' is required for event $name");
  60          }
  61  
  62          parent::__construct($name, $arguments);
  63      }
  64  
  65      /**
  66       * Get properties to render.
  67       *
  68       * @return  Relationship
  69       *
  70       * @since   4.0.0
  71       */
  72      public function getRelationship(): ?Relationship
  73      {
  74          return $this->relationship;
  75      }
  76  
  77      /**
  78       * Set relationship object that should be rendered.
  79       *
  80       * @param   Relationship  $relationship  The relationship object that should be rendered.
  81       *
  82       * @return  void
  83       * @since   4.0.0
  84       */
  85      public function setRelationship(Relationship $relationship): void
  86      {
  87          $this->relationship = $relationship;
  88      }
  89  }


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