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 branch 'feature/hydration-strategy' of https://github.com/Walte…
…rTamboer/zf2 into feature/hydrator-strategy Conflicts: tests/Zend/Form/FormTest.php
- Loading branch information
125 parents
448f428
+
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
+
debdd75
commit 5c1adbd
Showing
12 changed files
with
581 additions
and
26 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,117 @@ | ||
<?php | ||
/** | ||
* Zend Framework (http://framework.zend.com/) | ||
* | ||
* @link http://github.com/zendframework/zf2 for the canonical source repository | ||
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) | ||
* @license http://framework.zend.com/license/new-bsd New BSD License | ||
* @package Zend_Stdlib | ||
*/ | ||
|
||
namespace Zend\Stdlib\Hydrator; | ||
|
||
use ArrayObject; | ||
use Zend\Stdlib\Hydrator\StrategyEnabledInterface; | ||
use Zend\Stdlib\Hydrator\Strategy\StrategyInterface; | ||
|
||
/** | ||
* @category Zend | ||
* @package Zend_Stdlib | ||
* @subpackage Hydrator | ||
*/ | ||
abstract class AbstractHydrator implements HydratorInterface, StrategyEnabledInterface | ||
{ | ||
/** | ||
* The list with strategies that this hydrator has. | ||
* | ||
* @var ArrayObject | ||
*/ | ||
protected $strategies; | ||
|
||
/** | ||
* Initializes a new instance of this class. | ||
*/ | ||
public function __construct() | ||
{ | ||
$this->strategies = new ArrayObject(); | ||
} | ||
|
||
/** | ||
* Gets the strategy with the given name. | ||
* | ||
* @param string $name The name of the strategy to get. | ||
* @return StrategyInterface | ||
*/ | ||
public function getStrategy($name) | ||
{ | ||
return $this->strategies[$name]; | ||
} | ||
|
||
/** | ||
* Checks if the strategy with the given name exists. | ||
* | ||
* @param string $name The name of the strategy to check for. | ||
* @return bool | ||
*/ | ||
public function hasStrategy($name) | ||
{ | ||
return array_key_exists($name, $this->strategies); | ||
} | ||
|
||
/** | ||
* Adds the given strategy under the given name. | ||
* | ||
* @param string $name The name of the strategy to register. | ||
* @param StrategyInterface $strategy The strategy to register. | ||
* @return HydratorInterface | ||
*/ | ||
public function addStrategy($name, StrategyInterface $strategy) | ||
{ | ||
$this->strategies[$name] = $strategy; | ||
return $this; | ||
} | ||
|
||
/** | ||
* Removes the strategy with the given name. | ||
* | ||
* @param string $name The name of the strategy to remove. | ||
* @return HydratorInterface | ||
*/ | ||
public function removeStrategy($name) | ||
{ | ||
unset($this->strategies[$name]); | ||
return $this; | ||
} | ||
|
||
/** | ||
* Converts a value for extraction. If no strategy exists the plain value is returned. | ||
* | ||
* @param string $name The name of the strategy to use. | ||
* @param mixed $value The value that should be converted. | ||
* @return mixed | ||
*/ | ||
public function extractValue($name, $value) | ||
{ | ||
if ($this->hasStrategy($name)) { | ||
$strategy = $this->getStrategy($name); | ||
$value = $strategy->extract($value); | ||
} | ||
return $value; | ||
} | ||
|
||
/** | ||
* Converts a value for hydration. If no strategy exists the plain value is returned. | ||
* | ||
* @param string $name The name of the strategy to use. | ||
* @param mixed $value The value that should be converted. | ||
* @return mixed | ||
*/ | ||
public function hydrateValue($name, $value) | ||
{ | ||
if ($this->hasStrategy($name)) { | ||
$strategy = $this->getStrategy($name); | ||
$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
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,41 @@ | ||
<?php | ||
/** | ||
* Zend Framework (http://framework.zend.com/) | ||
* | ||
* @link http://github.com/zendframework/zf2 for the canonical source repository | ||
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) | ||
* @license http://framework.zend.com/license/new-bsd New BSD License | ||
* @package Zend_Stdlib | ||
*/ | ||
|
||
namespace Zend\Stdlib\Hydrator\Strategy; | ||
|
||
/** | ||
* @category Zend | ||
* @package Zend_Stdlib | ||
* @subpackage Hydrator | ||
*/ | ||
class DefaultStrategy implements StrategyInterface | ||
{ | ||
/** | ||
* Converts the given value so that it can be extracted by the hydrator. | ||
* | ||
* @param mixed $value The original value. | ||
* @return mixed Returns the value that should be extracted. | ||
*/ | ||
public function extract($value) | ||
{ | ||
return $value; | ||
} | ||
|
||
/** | ||
* Converts the given value so that it can be hydrated by the hydrator. | ||
* | ||
* @param mixed $value The original value. | ||
* @return mixed Returns the value that should be hydrated. | ||
*/ | ||
public function 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php | ||
/** | ||
* Zend Framework (http://framework.zend.com/) | ||
* | ||
* @link http://github.com/zendframework/zf2 for the canonical source repository | ||
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) | ||
* @license http://framework.zend.com/license/new-bsd New BSD License | ||
* @package Zend_Stdlib | ||
*/ | ||
|
||
namespace Zend\Stdlib\Hydrator\Strategy; | ||
|
||
/** | ||
* @category Zend | ||
* @package Zend_Stdlib | ||
* @subpackage Hydrator | ||
*/ | ||
interface StrategyInterface | ||
{ | ||
/** | ||
* Converts the given value so that it can be extracted by the hydrator. | ||
* | ||
* @param mixed $value The original value. | ||
* @return mixed Returns the value that should be extracted. | ||
*/ | ||
public function extract($value); | ||
|
||
/** | ||
* Converts the given value so that it can be hydrated by the hydrator. | ||
* | ||
* @param mixed $value The original value. | ||
* @return mixed Returns the value that should be hydrated. | ||
*/ | ||
public function hydrate($value); | ||
} |
Oops, something went wrong.