PluginProbe
Packeta / 1.2.6
Packeta v1.2.6
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 / packetery_vendor / nette / component-model / src / ComponentModel / ArrayAccess.php

ArrayAccess.php in Packeta 1.2.6, at packetery_vendor/nette/component-model/src/ComponentModel/ArrayAccess.php

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