Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 26a7222

Browse files
committed
merged branch cystbear/PropertyAccessor-CustomArrayObject-Fix (PR #7320)
This PR was submitted for the master branch but it was merged into the 2.2 branch instead (closes #7320). Commits ------- 7ff2d52 Property accessor custom array object fix Discussion ---------- Property accessor custom array object fix Copied `Symfony\Component\Form\Tests\Fixtures\CustomArrayObject` to Fixtures dir, and used it in tests to be able run tests separately from Form component,
2 parents 6c1e86c + 663c796 commit 26a7222

File tree

2 files changed

+71
-1
lines changed

2 files changed

+71
-1
lines changed
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <[email protected]>
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\PropertyAccess\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+
}

src/Symfony/Component/PropertyAccess/Tests/PropertyAccessorCustomArrayObjectTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
namespace Symfony\Component\PropertyAccess\Tests;
1313

14-
use Symfony\Component\Form\Tests\Fixtures\CustomArrayObject;
14+
use Symfony\Component\PropertyAccess\Tests\Fixtures\CustomArrayObject;
1515

1616
class PropertyAccessorCustomArrayObjectTest extends PropertyAccessorCollectionTest
1717
{

0 commit comments

Comments
 (0)