PluginProbe
Packeta / 2.0.9
Packeta v2.0.9
2.3.2 2.3.1 trunk 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.3.0 1.3.1 1.3.2 1.4 1.4.1 1.4.2 1.4.3 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.6.0 1.6.1 1.6.2 1.6.3 1.6.4 All 56 releases
packeta / deps / nette / component-model / src / ComponentModel / ArrayAccess.php

ArrayAccess.php in Packeta 2.0.9, at deps/nette/component-model/src/ComponentModel/ArrayAccess.php

57 lines 1.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * This file is part of the Nette Framework (https://nette.org)
5 * Copyright (c) 2004 David Grudl (https://davidgrudl.com)
6 */
7 declare (strict_types=1);
8 namespace Packetery\Nette\ComponentModel;
9
10 use Packetery\Nette;
11 /**
12 * Implementation of \ArrayAccess for IContainer.
13 */
14 trait ArrayAccess
15 {
16 /**
17 * Adds the component to the container.
18 * @param string|int $name
19 * @param IComponent $component
20 */
21 public function offsetSet($name, $component) : void
22 {
23 $name = \is_int($name) ? (string) $name : $name;
24 $this->addComponent($component, $name);
25 }
26 /**
27 * Returns component specified by name. Throws exception if component doesn't exist.
28 * @param string|int $name
29 * @throws \Packetery\Nette\InvalidArgumentException
30 */
31 public function offsetGet($name) : IComponent
32 {
33 $name = \is_int($name) ? (string) $name : $name;
34 return $this->getComponent($name);
35 }
36 /**
37 * Does component specified by name exists?
38 * @param string|int $name
39 */
40 public function offsetExists($name) : bool
41 {
42 $name = \is_int($name) ? (string) $name : $name;
43 return $this->getComponent($name, \false) !== null;
44 }
45 /**
46 * Removes component from the container.
47 * @param string|int $name
48 */
49 public function offsetUnset($name) : void
50 {
51 $name = \is_int($name) ? (string) $name : $name;
52 if ($component = $this->getComponent($name, \false)) {
53 $this->removeComponent($component);
54 }
55 }
56 }
57