Your IP : 216.73.217.112


Current Path : /home/zieirix/www/libraries/gantry5/src/classes/Gantry/Joomla/Object/
Upload File :
Current File : /home/zieirix/www/libraries/gantry5/src/classes/Gantry/Joomla/Object/Collection.php

<?php

/**
 * @package   Gantry5
 * @author    RocketTheme http://www.rockettheme.com
 * @copyright Copyright (C) 2007 - 2021 RocketTheme, LLC
 * @license   GNU/GPLv2 and later
 *
 * http://www.gnu.org/licenses/gpl-2.0.html
 */

namespace Gantry\Joomla\Object;

use \Gantry\Component\Collection\Collection as BaseCollection;

/**
 * Class Collection
 * @package Gantry\Joomla\Object
 */
class Collection extends BaseCollection
{
    /**
     * Collection constructor.
     * @param array $items
     */
    public function __construct(array $items)
    {
        $this->items = $items;
    }

    /**
     * @param string $property
     * @return array
     */
    public function get($property)
    {
        $list = [];

        if ($property === 'id') {
            return array_keys($this->items);
        }

        foreach ($this as $object) {
            $list[$object->id] = $object->{$property};
        }

        return $list;
    }

    /**
     * @param string $name
     * @param array $arguments
     * @return array
     */
    public function __call($name, $arguments)
    {
        $list = [];

        foreach ($this as $object) {
            $list[$object->id] = method_exists($object, $name) ? \call_user_func_array([$object, $name], $arguments) : null;
        }

        return $list;
    }
}