[ Index ]

PHP Cross Reference of Joomla 4.2.2 documentation

title

Body

[close]

/administrator/components/com_media/src/Event/ -> FetchMediaItemEvent.php (source)

   1  <?php
   2  
   3  /**
   4   * @package     Joomla.Administrator
   5   * @subpackage  com_media
   6   *
   7   * @copyright   (C) 2021 Open Source Matters, Inc. <https://www.joomla.org>
   8   * @license     GNU General Public License version 2 or later; see LICENSE.txt
   9   */
  10  
  11  namespace Joomla\Component\Media\Administrator\Event;
  12  
  13  // phpcs:disable PSR1.Files.SideEffects
  14  \defined('_JEXEC') or die;
  15  // phpcs:enable PSR1.Files.SideEffects
  16  
  17  /**
  18   * Event object for fetch media item.
  19   *
  20   * @since  4.1.0
  21   */
  22  final class FetchMediaItemEvent extends AbstractMediaItemValidationEvent
  23  {
  24      /**
  25       * Constructor.
  26       *
  27       * @param   string  $name       The event name.
  28       * @param   array   $arguments  The event arguments.
  29       *
  30       * @throws  \BadMethodCallException
  31       *
  32       * @since  4.1.0
  33       */
  34      public function __construct($name, array $arguments = array())
  35      {
  36          parent::__construct($name, $arguments);
  37  
  38          // Check for required arguments
  39          if (!\array_key_exists('item', $arguments) || !is_object($arguments['item'])) {
  40              throw new \BadMethodCallException("Argument 'item' of event $name is not of the expected type");
  41          }
  42      }
  43  
  44      /**
  45       * Validate $item to have all attributes with a valid type
  46       *
  47       * Validation based on \Joomla\Component\Media\Administrator\Adapter\AdapterInterface::getFile()
  48       *
  49       * Properties validated:
  50       * - type:          The type can be file or dir
  51       * - name:          The name of the item
  52       * - path:          The relative path to the root
  53       * - extension:     The file extension
  54       * - size:          The size of the file
  55       * - create_date:   The date created
  56       * - modified_date: The date modified
  57       * - mime_type:     The mime type
  58       * - width:         The width, when available
  59       * - height:        The height, when available
  60       *
  61       * Generation based on \Joomla\Plugin\Filesystem\Local\Adapter\LocalAdapter::getPathInformation()
  62       *
  63       * Properties generated:
  64       * - created_date_formatted:  DATE_FORMAT_LC5 formatted string based on create_date
  65       * - modified_date_formatted: DATE_FORMAT_LC5 formatted string based on modified_date
  66       *
  67       * @param   \stdClass  $item  The item to set
  68       *
  69       * @return \stdClass
  70       *
  71       * @since   4.1.0
  72       *
  73       * @throws \BadMethodCallException
  74       */
  75      protected function setItem(\stdClass $item): \stdClass
  76      {
  77          // Make immutable object
  78          $item = clone $item;
  79  
  80          $this->validate($item);
  81  
  82          return $item;
  83      }
  84  }


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