__  __    __   __  _____      _            _          _____ _          _ _ 
 |  \/  |   \ \ / / |  __ \    (_)          | |        / ____| |        | | |
 | \  / |_ __\ V /  | |__) | __ ___   ____ _| |_ ___  | (___ | |__   ___| | |
 | |\/| | '__|> <   |  ___/ '__| \ \ / / _` | __/ _ \  \___ \| '_ \ / _ \ | |
 | |  | | |_ / . \  | |   | |  | |\ V / (_| | ||  __/  ____) | | | |  __/ | |
 |_|  |_|_(_)_/ \_\ |_|   |_|  |_| \_/ \__,_|\__\___| |_____/|_| |_|\___V 2.1
 if you need WebShell for Seo everyday contact me on Telegram
 Telegram Address : @jackleet
        
        
For_More_Tools: Telegram: @jackleet | Bulk Smtp support mail sender | Business Mail Collector | Mail Bouncer All Mail | Bulk Office Mail Validator | Html Letter private



Upload:

Command:

[email protected]: ~ $
<?php

/**
 * Joomla! Content Management System
 *
 * @copyright  (C) 2020 Open Source Matters, Inc. <https://www.joomla.org>
 * @license    GNU General Public License version 2 or later; see LICENSE.txt
 */

namespace Joomla\CMS\MVC\View\Event;

use Joomla\CMS\Event\AbstractImmutableEvent;

// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects

/**
 * Event for getting extra API Fields and Relations to render with an entity
 *
 * @since  4.0.0
 */
final class OnGetApiFields extends AbstractImmutableEvent
{
    /**
     * List of types of view supported
     *
     * @since  4.0.0
     */
    public const LIST = 'list';

    /**
     * List of types of view supported
     *
     * @since  4.0.0
     */
    public const ITEM = 'item';

    /**
     * List of names of properties that will be rendered as relations
     *
     * @var    string[]
     * @since  4.0.0
     */
    private $extraRelations = [];

    /**
     * List of names of properties that will be rendered as data
     *
     * @var    string[]
     * @since  4.0.0
     */
    private $extraAttributes = [];

    /**
     * Constructor.
     *
     * Mandatory arguments:
     * type         string          The type of the field. Should be a constant from static::VIEW_TYPE
     * fields       fields          The list of fields that will be rendered in the API.
     *
     * @param   string  $name       The event name.
     * @param   array   $arguments  The event arguments.
     *
     * @throws  \BadMethodCallException
     */
    public function __construct($name, array $arguments = [])
    {
        if (!\array_key_exists('type', $arguments)) {
            throw new \BadMethodCallException("Argument 'type' is required for event $name");
        }

        if (!\array_key_exists('fields', $arguments)) {
            throw new \BadMethodCallException("Argument 'fields' is required for event $name");
        }

        if (!\array_key_exists('context', $arguments)) {
            throw new \BadMethodCallException("Argument 'context' is required for event $name");
        }

        parent::__construct($name, $arguments);
    }

    /**
     * Setter for the type argument
     *
     * @param   integer  $value  The constant from VIEW_TYPE
     *
     * @return  mixed
     *
     * @throws  \BadMethodCallException  if the argument is not of the expected type
     */
    protected function setType($value)
    {
        if (!\in_array($value, [static::ITEM, static::LIST])) {
            throw new \BadMethodCallException("Argument 'type' of event {$this->name} must be a valid value");
        }

        return $value;
    }

    /**
     * Setter for the fields argument
     *
     * @param   mixed  $value  The value to set
     *
     * @return  array
     *
     * @throws  \BadMethodCallException  if the argument is not a non-empty array
     */
    protected function setFields($value)
    {
        if (!\is_array($value) || \is_array($value) && empty($value)) {
            throw new \BadMethodCallException("Argument 'fields' of event {$this->name} must be be an array and not empty");
        }

        return $value;
    }

    /**
     * Setter for the relations argument
     *
     * @param   mixed  $value  The value to set
     *
     * @return  array
     *
     * @throws  \BadMethodCallException  if the argument is not a non-empty array
     */
    protected function setRelations($value)
    {
        if (!\is_array($value)) {
            throw new \BadMethodCallException("Argument 'relations' of event {$this->name} must be be an array");
        }

        return $value;
    }

    /**
     * Allows the user to add names of properties that will be interpreted as relations
     * Note that if there is an existing data property it will also be displayed as well
     * as the relation due to the internal implementation (this behaviour is not part of this API
     * however and should not be guaranteed)
     *
     * @param   string[]  $fields  The array of additional fields to add to the data of the attribute
     *
     * @return  void
     */
    public function addFields(array $fields): void
    {
        $this->extraAttributes = array_merge($this->extraAttributes, $fields);
    }

    /**
     * Allows the user to add names of properties that will be interpreted as relations
     * Note that if there is an existing data property it will also be displayed as well
     * as the relation due to the internal implementation (this behaviour is not part of this API
     * however and should not be guaranteed)
     *
     * @param   string[]  $fields  The array of additional fields to add as relations
     *
     * @return  void
     */
    public function addRelations(array $fields): void
    {
        $this->extraRelations = array_merge($this->extraRelations, $fields);
    }

    /**
     * Get properties to render.
     *
     * @return  array
     */
    public function getAllPropertiesToRender(): array
    {
        return array_merge($this->getArgument('fields'), $this->extraAttributes);
    }

    /**
     * Get properties to render.
     *
     * @return  array
     */
    public function getAllRelationsToRender(): array
    {
        return array_merge($this->getArgument('relations'), $this->extraRelations);
    }
}

Filemanager

Name Type Size Permission Actions
OnGetApiFields.php File 5.21 KB 0664
Filemanager