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:
8: namespace Nette\ComponentModel;
9:
10: use Nette;
11:
12:
13: /**
14: * Implementation of \ArrayAccess for IContainer.
15: */
16: trait ArrayAccess
17: {
18: /**
19: * Adds the component to the container.
20: * @param string|int $name
21: * @param IComponent $component
22: * @return void
23: */
24: public function offsetSet($name, $component)
25: {
26: $this->addComponent($component, $name);
27: }
28:
29:
30: /**
31: * Returns component specified by name. Throws exception if component doesn't exist.
32: * @param string|int $name
33: * @return IComponent
34: * @throws Nette\InvalidArgumentException
35: */
36: public function offsetGet($name)
37: {
38: return $this->getComponent($name);
39: }
40:
41:
42: /**
43: * Does component specified by name exists?
44: * @param string|int $name
45: * @return bool
46: */
47: public function offsetExists($name)
48: {
49: return $this->getComponent($name, false) !== null;
50: }
51:
52:
53: /**
54: * Removes component from the container.
55: * @param string|int $name
56: * @return void
57: */
58: public function offsetUnset($name)
59: {
60: if ($component = $this->getComponent($name, false)) {
61: $this->removeComponent($component);
62: }
63: }
64: }
65: