diff options
Diffstat (limited to 'vendor/symfony/form/Symfony/Component/Form/Tests/Fixtures/CustomArrayObject.php')
-rw-r--r-- | vendor/symfony/form/Symfony/Component/Form/Tests/Fixtures/CustomArrayObject.php | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/vendor/symfony/form/Symfony/Component/Form/Tests/Fixtures/CustomArrayObject.php b/vendor/symfony/form/Symfony/Component/Form/Tests/Fixtures/CustomArrayObject.php new file mode 100644 index 00000000..950f677f --- /dev/null +++ b/vendor/symfony/form/Symfony/Component/Form/Tests/Fixtures/CustomArrayObject.php | |||
@@ -0,0 +1,70 @@ | |||
1 | <?php | ||
2 | |||
3 | /* | ||
4 | * This file is part of the Symfony package. | ||
5 | * | ||
6 | * (c) Fabien Potencier <fabien@symfony.com> | ||
7 | * | ||
8 | * For the full copyright and license information, please view the LICENSE | ||
9 | * file that was distributed with this source code. | ||
10 | */ | ||
11 | |||
12 | namespace Symfony\Component\Form\Tests\Fixtures; | ||
13 | |||
14 | /** | ||
15 | * This class is a hand written simplified version of PHP native `ArrayObject` | ||
16 | * class, to show that it behaves differently than the PHP native implementation. | ||
17 | */ | ||
18 | class CustomArrayObject implements \ArrayAccess, \IteratorAggregate, \Countable, \Serializable | ||
19 | { | ||
20 | private $array; | ||
21 | |||
22 | public function __construct(array $array = null) | ||
23 | { | ||
24 | $this->array = $array ?: array(); | ||
25 | } | ||
26 | |||
27 | public function offsetExists($offset) | ||
28 | { | ||
29 | return array_key_exists($offset, $this->array); | ||
30 | } | ||
31 | |||
32 | public function offsetGet($offset) | ||
33 | { | ||
34 | return $this->array[$offset]; | ||
35 | } | ||
36 | |||
37 | public function offsetSet($offset, $value) | ||
38 | { | ||
39 | if (null === $offset) { | ||
40 | $this->array[] = $value; | ||
41 | } else { | ||
42 | $this->array[$offset] = $value; | ||
43 | } | ||
44 | } | ||
45 | |||
46 | public function offsetUnset($offset) | ||
47 | { | ||
48 | unset($this->array[$offset]); | ||
49 | } | ||
50 | |||
51 | public function getIterator() | ||
52 | { | ||
53 | return new \ArrayIterator($this->array); | ||
54 | } | ||
55 | |||
56 | public function count() | ||
57 | { | ||
58 | return count($this->array); | ||
59 | } | ||
60 | |||
61 | public function serialize() | ||
62 | { | ||
63 | return serialize($this->array); | ||
64 | } | ||
65 | |||
66 | public function unserialize($serialized) | ||
67 | { | ||
68 | $this->array = (array) unserialize((string) $serialized); | ||
69 | } | ||
70 | } | ||