HEX
Server: Apache
System: Linux server1.ariadata.co 4.18.0-553.120.1.el8_10.x86_64 #1 SMP Mon Apr 20 18:04:27 EDT 2026 x86_64
User: nepi (1051)
PHP: 7.4.33
Disabled: exec,passthru,shell_exec,system,show_source,popen,proc_open
Upload Files
File: /home/nepi/public_html/src/core/Directus/Collection/Collection.php
<?php

namespace Directus\Collection;

use Directus\Util\ArrayUtils;

class Collection implements CollectionInterface, \Iterator
{
    /**
     * Collection items
     *
     * @var array
     */
    protected $items = [];

    /**
     * Collection constructor.
     *
     * @param array $items
     */
    public function __construct($items = [])
    {
        $this->items = $items;
    }

    /**
     * @inheritDoc
     */
    public function toArray()
    {
        return $this->items;
    }

    /**
     * @inheritDoc
     */
    public function set($key, $value)
    {
        $this->items[$key] = $value;
    }

    /**
     * @inheritDoc
     */
    public function get($key, $default = null)
    {
        return ArrayUtils::get($this->items, $key, $default);
    }

    /**
     * @inheritDoc
     */
    public function has($key)
    {
        return ArrayUtils::has($this->items, $key);
    }

    /**
     * @inheritDoc
     */
    public function remove($key)
    {
        if ($this->has($key)) {
            unset($this->items[$key]);
        }
    }

    /**
     * @inheritDoc
     */
    public function isEmpty()
    {
        return $this->count() === 0;
    }

    /**
     * @inheritDoc
     */
    public function clear()
    {
        $this->items = [];
    }

    /**
     * @inheritDoc
     */
    public function replace(array $items)
    {
        $this->clear();
        $this->appendArray($items);
    }

    /**
     * @inheritDoc
     */
    public function appendArray(array $items)
    {
        $this->items = array_merge($this->items, $items);

        return $this->items;
    }

    /**
     * @inheritDoc
     */
    public function appendCollection(Collection $collection)
    {
        return $this->appendArray($collection->toArray());
    }

    /**
     * @inheritDoc
     */
    public function offsetExists($offset)
    {
        return $this->has($offset);
    }

    /**
     * @inheritDoc
     */
    public function offsetGet($offset)
    {
        return $this->get($offset);
    }

    /**
     * @inheritDoc
     */
    public function offsetSet($offset, $value)
    {
        $this->set($offset, $value);
    }

    /**
     * @inheritDoc
     */
    public function offsetUnset($offset)
    {
        $this->remove($offset);
    }

    /**
     * @inheritDoc
     */
    public function count()
    {
        return count($this->items);
    }

    /**
     * @inheritDoc
     */
    public function current()
    {
        return current($this->items);
    }

    /**
     * @inheritDoc
     */
    public function next()
    {
        return next($this->items);
    }

    /**
     * @inheritDoc
     */
    public function key()
    {
        return key($this->items);
    }

    /**
     * @inheritDoc
     */
    public function valid()
    {
        return $this->key() !== null;
    }

    /**
     * @inheritDoc
     */
    public function rewind()
    {
        return reset($this->items);
    }
}