# packeta/1.6.1/deps/nette/utils/src/Utils/ArrayList.php

Packeta, version 1.6.1. 93 lines.

- Page: https://pluginprobe.com/plugins/packeta/1.6.1/code/deps/nette/utils/src/Utils/ArrayList.php
- Raw: https://pluginprobe.com/plugins/packeta/1.6.1/raw/deps/nette/utils/src/Utils/ArrayList.php
- Modified: 2023-08-30T08:36:18+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/packeta/1.6.1/code/deps/nette/utils/src/Utils/ArrayList.php#L10-L20`.

```php
<?php

/**
 * This file is part of the Nette Framework (https://nette.org)
 * Copyright (c) 2004 David Grudl (https://davidgrudl.com)
 */
declare (strict_types=1);
namespace Packetery\Nette\Utils;

use Packetery\Nette;
/**
 * Provides the base class for a generic list (items can be accessed by index).
 */
class ArrayList implements \ArrayAccess, \Countable, \IteratorAggregate
{
    use \Packetery\Nette\SmartObject;
    /** @var mixed[] */
    private $list = [];
    /**
     * Returns an iterator over all items.
     */
    public function getIterator() : \ArrayIterator
    {
        return new \ArrayIterator($this->list);
    }
    /**
     * Returns items count.
     */
    public function count() : int
    {
        return \count($this->list);
    }
    /**
     * Replaces or appends a item.
     * @param  int|null  $index
     * @param  mixed  $value
     * @throws \Packetery\Nette\OutOfRangeException
     */
    public function offsetSet($index, $value) : void
    {
        if ($index === null) {
            $this->list[] = $value;
        } elseif (!\is_int($index) || $index < 0 || $index >= \count($this->list)) {
            throw new \Packetery\Nette\OutOfRangeException('Offset invalid or out of range');
        } else {
            $this->list[$index] = $value;
        }
    }
    /**
     * Returns a item.
     * @param  int  $index
     * @return mixed
     * @throws \Packetery\Nette\OutOfRangeException
     */
    public function offsetGet($index)
    {
        if (!\is_int($index) || $index < 0 || $index >= \count($this->list)) {
            throw new \Packetery\Nette\OutOfRangeException('Offset invalid or out of range');
        }
        return $this->list[$index];
    }
    /**
     * Determines whether a item exists.
     * @param  int  $index
     */
    public function offsetExists($index) : bool
    {
        return \is_int($index) && $index >= 0 && $index < \count($this->list);
    }
    /**
     * Removes the element at the specified position in this list.
     * @param  int  $index
     * @throws \Packetery\Nette\OutOfRangeException
     */
    public function offsetUnset($index) : void
    {
        if (!\is_int($index) || $index < 0 || $index >= \count($this->list)) {
            throw new \Packetery\Nette\OutOfRangeException('Offset invalid or out of range');
        }
        \array_splice($this->list, $index, 1);
    }
    /**
     * Prepends a item.
     * @param  mixed  $value
     */
    public function prepend($value) : void
    {
        $first = \array_slice($this->list, 0, 1);
        $this->offsetSet(0, $value);
        \array_splice($this->list, 1, 0, $first);
    }
}

```
