This repository has been archived by the owner on Jan 31, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 75
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request zendframework/zendframework#1 from zendframework/d…
…evelop Develop
- Loading branch information
209 parents
73d20a1
+
b39d73c
+
7c9dbb1
+
9df2571
+
d8f58fd
+
c8aca84
+
4ac816f
+
7f2fed2
+
b528fc5
+
fb851e2
+
802bf45
+
29ea285
+
c9418a6
+
fdeb27b
+
c382628
+
ee15e76
+
5f29760
+
714d1a8
+
84b0297
+
cbc5f03
+
76361f8
+
e7209df
+
87630e0
+
df43daf
+
f7d6cbb
+
7e2b798
+
3ed1ead
+
87505b6
+
c229265
+
eb61c8f
+
efcb00e
+
0a0842f
+
b6d0c88
+
7edee62
+
60ea64c
+
a08bcca
+
b40ec3e
+
63172ed
+
448f428
+
92a516a
+
5ecbc99
+
a2df21b
+
4de87f2
+
7c259ec
+
a22bdcb
+
084ad9f
+
9414e5a
+
489be93
+
cb39e7e
+
54a28dc
+
c9c769e
+
dda791d
+
70d382a
+
8bbad0e
+
9321185
+
7ab35a6
+
b93694e
+
3ea7087
+
0fe3d3a
+
bd5e189
+
d1cba17
+
8d75392
+
3fb5b55
+
6cb0ccb
+
30aa565
+
8409977
+
8074ba0
+
8f92486
+
94860d1
+
05d33c4
+
425826b
+
f0e91f0
+
e31468f
+
7d2af87
+
2e4dc80
+
19d128f
+
1b9e4b2
+
1c46483
+
fdda3f2
+
595fcd1
+
213395c
+
8e514a8
+
2f30186
+
bb4ed65
+
132d5b6
+
030ff33
+
f2f20f3
+
a50e133
+
4c554ee
+
dbfb1b8
+
ccab83f
+
00b350f
+
78945d0
+
f0e5f4b
+
ceb7d8c
+
9e124d1
+
3de5912
+
b6a974a
+
10a6438
+
cb6c1e7
+
18afd6c
+
3baf1bd
+
c800904
+
f52dcb8
+
126ccb2
+
e7d6206
+
e2d24ab
+
ec1abfc
+
290ea90
+
9f4ca1b
+
edaa760
+
c4c0c95
+
d21f055
+
5b18029
+
e6b97af
+
010fb36
+
64c7b8d
+
636523e
+
4cc2cd6
+
e34098a
+
16367cd
+
943c77f
+
8226e5b
+
0b47726
+
3cd8a03
+
cc4782c
+
9c653a6
+
656dbe5
+
9bce1ba
+
7dc18ca
+
861130d
+
2d2ffbd
+
4f413a5
+
2e1067a
+
1d082e4
+
e8aeb79
+
b562091
+
ff2fdc3
+
4aa72c0
+
1bb67ac
+
cd015c8
+
5e89910
+
0c21258
+
dd54faf
+
57f9063
+
b88ce2e
+
af68643
+
06cd3b4
+
2c71b71
+
ee02c35
+
9456314
+
5a77a7b
+
e98a077
+
738f2e6
+
cb1e63c
+
736df07
+
d0a0154
+
990523c
+
78687de
+
a5b6e79
+
6e9dfe9
+
e201a1c
+
d9b45ef
+
76222ad
+
16d67da
+
1ab2258
+
b81d711
+
ed2e9bc
+
61efe82
+
f353ea5
+
1f02519
+
58c1fe8
+
ed502d9
+
2defba6
+
4885013
+
06a8384
+
17d9eed
+
3b21b5d
+
c62101c
+
909ef34
+
13d376a
+
8a75367
+
98a3cf5
+
270f2c4
+
3038cfa
+
1112202
+
c8fb359
+
8d37cd0
+
4d868a7
+
555cb91
+
7ac5858
+
8103f1f
+
9fe9c96
+
a3ecac6
+
10e77c1
+
e0d3e13
+
19ad608
+
e0d665c
+
1a5b402
+
56ae12a
+
9073fc1
+
2d5b32f
+
a8e6198
+
83e8f34
+
30eb247
+
6204c2f
+
c3855a9
+
543aa17
+
c6edc6e
commit 2fafe62
Showing
13 changed files
with
444 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
<?php | ||
/** | ||
* Zend Framework (http://framework.zend.com/) | ||
* | ||
* @link http://github.com/zendframework/zf2 for the canonical source repository | ||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) | ||
* @license http://framework.zend.com/license/new-bsd New BSD License | ||
*/ | ||
|
||
namespace Zend\Stdlib\Hydrator; | ||
|
||
use Zend\ServiceManager\ServiceLocatorInterface; | ||
|
||
class DelegatingHydrator implements HydratorInterface | ||
{ | ||
/** | ||
* @var ServiceLocatorInterface | ||
*/ | ||
protected $hydrators; | ||
|
||
/** | ||
* Constructor | ||
* | ||
* @param ServiceLocatorInterface $hydrators | ||
*/ | ||
public function __construct(ServiceLocatorInterface $hydrators) | ||
{ | ||
$this->hydrators = $hydrators; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function hydrate(array $data, $object) | ||
{ | ||
return $this->getHydrator($object)->hydrate($data, $object); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function extract($object) | ||
{ | ||
return $this->getHydrator($object)->extract($object); | ||
} | ||
|
||
/** | ||
* Gets hydrator of an object | ||
* | ||
* @param object $object | ||
* @return HydratorInterface | ||
*/ | ||
protected function getHydrator($object) | ||
{ | ||
return $this->hydrators->get(get_class($object)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?php | ||
/** | ||
* Zend Framework (http://framework.zend.com/) | ||
* | ||
* @link http://github.com/zendframework/zf2 for the canonical source repository | ||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) | ||
* @license http://framework.zend.com/license/new-bsd New BSD License | ||
*/ | ||
|
||
namespace Zend\Stdlib\Hydrator; | ||
|
||
use Zend\ServiceManager\FactoryInterface; | ||
use Zend\ServiceManager\ServiceLocatorInterface; | ||
|
||
class DelegatingHydratorFactory implements FactoryInterface | ||
{ | ||
/** | ||
* Creates DelegatingHydrator | ||
* | ||
* @param ServiceLocatorInterface $serviceLocator | ||
* @return DelegatingHydrator | ||
*/ | ||
public function createService(ServiceLocatorInterface $serviceLocator) | ||
{ | ||
// Assume that this factory is registered with the HydratorManager, | ||
// and just pass it directly on. | ||
return new DelegatingHydrator($serviceLocator); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
<?php | ||
/** | ||
* Zend Framework (http://framework.zend.com/) | ||
* | ||
* @link http://github.com/zendframework/zf2 for the canonical source repository | ||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) | ||
* @license http://framework.zend.com/license/new-bsd New BSD License | ||
*/ | ||
|
||
namespace Zend\Stdlib\Hydrator\Strategy; | ||
|
||
use Traversable; | ||
use Zend\Stdlib\ArrayUtils; | ||
|
||
final class StrategyChain implements StrategyInterface | ||
{ | ||
/** | ||
* Strategy chain for extraction | ||
* | ||
* @var StrategyInterface[] | ||
*/ | ||
private $extractionStrategies; | ||
|
||
/** | ||
* Strategy chain for hydration | ||
* | ||
* @var StrategyInterface[] | ||
*/ | ||
private $hydrationStrategies; | ||
|
||
/** | ||
* Constructor | ||
* | ||
* @param array|Traversable $extractionStrategies | ||
*/ | ||
public function __construct($extractionStrategies) | ||
{ | ||
$extractionStrategies = ArrayUtils::iteratorToArray($extractionStrategies); | ||
$this->extractionStrategies = array_map( | ||
function (StrategyInterface $strategy) { | ||
// this callback is here only to ensure type-safety | ||
return $strategy; | ||
}, | ||
$extractionStrategies | ||
); | ||
|
||
$this->hydrationStrategies = array_reverse($extractionStrategies); | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function extract($value) | ||
{ | ||
foreach ($this->extractionStrategies as $strategy) { | ||
$value = $strategy->extract($value); | ||
} | ||
|
||
return $value; | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function hydrate($value) | ||
{ | ||
foreach ($this->hydrationStrategies as $strategy) { | ||
$value = $strategy->hydrate($value); | ||
} | ||
|
||
return $value; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?php | ||
/** | ||
* Zend Framework (http://framework.zend.com/) | ||
* | ||
* @link http://github.com/zendframework/zf2 for the canonical source repository | ||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) | ||
* @license http://framework.zend.com/license/new-bsd New BSD License | ||
*/ | ||
|
||
namespace ZendTest\Stdlib\Hydrator; | ||
|
||
use Zend\Stdlib\Hydrator\DelegatingHydratorFactory; | ||
|
||
class DelegatingHydratorFactoryTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
public function testFactory() | ||
{ | ||
$hydratorManager = $this->getMock('Zend\ServiceManager\ServiceLocatorInterface'); | ||
$factory = new DelegatingHydratorFactory(); | ||
$this->assertInstanceOf( | ||
'Zend\Stdlib\Hydrator\DelegatingHydrator', | ||
$factory->createService($hydratorManager) | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
<?php | ||
/** | ||
* Zend Framework (http://framework.zend.com/) | ||
* | ||
* @link http://github.com/zendframework/zf2 for the canonical source repository | ||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) | ||
* @license http://framework.zend.com/license/new-bsd New BSD License | ||
*/ | ||
|
||
namespace ZendTest\Stdlib\Hydrator; | ||
|
||
use Zend\Stdlib\Hydrator\DelegatingHydrator; | ||
use ArrayObject; | ||
|
||
/** | ||
* Unit tests for {@see \Zend\Stdlib\Hydrator\DelegatingHydrator} | ||
* | ||
* @covers \Zend\Stdlib\Hydrator\DelegatingHydrator | ||
*/ | ||
class DelegatingHydratorTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
/** | ||
* @var DelegatingHydrator | ||
*/ | ||
protected $hydrator; | ||
|
||
/** | ||
* @var \PHPUnit_Framework_MockObject_MockObject | ||
*/ | ||
protected $hydrators; | ||
|
||
/** | ||
* @var ArrayObject | ||
*/ | ||
protected $object; | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function setUp() | ||
{ | ||
$this->hydrators = $this->getMock('Zend\ServiceManager\ServiceLocatorInterface'); | ||
$this->hydrator = new DelegatingHydrator($this->hydrators); | ||
$this->object = new ArrayObject; | ||
} | ||
|
||
public function testExtract() | ||
{ | ||
$this->hydrators->expects($this->any()) | ||
->method('has') | ||
->with('ArrayObject') | ||
->will($this->returnValue(true)); | ||
|
||
$hydrator = $this->getMock('Zend\Stdlib\Hydrator\HydratorInterface'); | ||
|
||
$this->hydrators->expects($this->any()) | ||
->method('get') | ||
->with('ArrayObject') | ||
->will($this->returnValue($hydrator)); | ||
|
||
$hydrator->expects($this->any()) | ||
->method('extract') | ||
->with($this->object) | ||
->will($this->returnValue(array('foo' => 'bar'))); | ||
|
||
$this->assertEquals(array('foo' => 'bar'), $hydrator->extract($this->object)); | ||
} | ||
|
||
public function testHydrate() | ||
{ | ||
$this->hydrators->expects($this->any()) | ||
->method('has') | ||
->with('ArrayObject') | ||
->will($this->returnValue(true)); | ||
|
||
$hydrator = $this->getMock('Zend\Stdlib\Hydrator\HydratorInterface'); | ||
|
||
$this->hydrators->expects($this->any()) | ||
->method('get') | ||
->with('ArrayObject') | ||
->will($this->returnValue($hydrator)); | ||
|
||
$hydrator->expects($this->any()) | ||
->method('hydrate') | ||
->with(array('foo' => 'bar'), $this->object) | ||
->will($this->returnValue($this->object)); | ||
$this->assertEquals($this->object, $hydrator->hydrate(array('foo' => 'bar'), $this->object)); | ||
} | ||
} |
Oops, something went wrong.