# packeta/2.3.2/deps/nette/component-model/src/ComponentModel/ArrayAccess.php

Packeta, version 2.3.2. 57 lines.

- Page: https://pluginprobe.com/plugins/packeta/2.3.2/code/deps/nette/component-model/src/ComponentModel/ArrayAccess.php
- Raw: https://pluginprobe.com/plugins/packeta/2.3.2/raw/deps/nette/component-model/src/ComponentModel/ArrayAccess.php
- Modified: 2025-03-10T10:47:38+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/2.3.2/code/deps/nette/component-model/src/ComponentModel/ArrayAccess.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\ComponentModel;

use Packetery\Nette;
/**
 * Implementation of \ArrayAccess for IContainer.
 */
trait ArrayAccess
{
    /**
     * Adds the component to the container.
     * @param  string|int  $name
     * @param  IComponent  $component
     */
    public function offsetSet($name, $component) : void
    {
        $name = \is_int($name) ? (string) $name : $name;
        $this->addComponent($component, $name);
    }
    /**
     * Returns component specified by name. Throws exception if component doesn't exist.
     * @param  string|int  $name
     * @throws \Packetery\Nette\InvalidArgumentException
     */
    public function offsetGet($name) : IComponent
    {
        $name = \is_int($name) ? (string) $name : $name;
        return $this->getComponent($name);
    }
    /**
     * Does component specified by name exists?
     * @param  string|int  $name
     */
    public function offsetExists($name) : bool
    {
        $name = \is_int($name) ? (string) $name : $name;
        return $this->getComponent($name, \false) !== null;
    }
    /**
     * Removes component from the container.
     * @param  string|int  $name
     */
    public function offsetUnset($name) : void
    {
        $name = \is_int($name) ? (string) $name : $name;
        if ($component = $this->getComponent($name, \false)) {
            $this->removeComponent($component);
        }
    }
}

```
