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 'master' of git://github.com/zendframework/zf2 into cach…
…e_interfaces
- Loading branch information
88 parents
425826b
+
8409977
+
8074ba0
+
8f92486
+
94860d1
+
05d33c4
+
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
commit 738f2e6
Showing
13 changed files
with
586 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
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 |
---|---|---|
@@ -1,5 +1,6 @@ | ||
Zend/Amf | ||
Zend/Date | ||
Zend/Dojo | ||
Zend/Queue | ||
Zend/Service | ||
Zend/Test | ||
|
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,45 @@ | ||
<?php | ||
/** | ||
* Zend Framework | ||
* | ||
* LICENSE | ||
* | ||
* This source file is subject to the new BSD license that is bundled | ||
* with this package in the file LICENSE.txt. | ||
* It is also available through the world-wide-web at this URL: | ||
* http://framework.zend.com/license/new-bsd | ||
* If you did not receive a copy of the license and are unable to | ||
* obtain it through the world-wide-web, please send an email | ||
* to license@zend.com so we can send you a copy immediately. | ||
* | ||
* @category Zend | ||
* @package Zend_Stdlib | ||
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) | ||
* @license http://framework.zend.com/license/new-bsd New BSD License | ||
*/ | ||
|
||
namespace Zend\Stdlib; | ||
|
||
/** | ||
* @category Zend | ||
* @package Zend_Stdlib | ||
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) | ||
* @license http://framework.zend.com/license/new-bsd New BSD License | ||
*/ | ||
interface ArraySerializableInterface | ||
{ | ||
/** | ||
* Exchange internal values from provided array | ||
* | ||
* @param array $array | ||
* @return void | ||
*/ | ||
public function exchangeArray(array $array); | ||
|
||
/** | ||
* Return an array representation of the object | ||
* | ||
* @return array | ||
*/ | ||
public function getArrayCopy(); | ||
} |
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,80 @@ | ||
<?php | ||
/** | ||
* Zend Framework | ||
* | ||
* LICENSE | ||
* | ||
* This source file is subject to the new BSD license that is bundled | ||
* with this package in the file LICENSE.txt. | ||
* It is also available through the world-wide-web at this URL: | ||
* http://framework.zend.com/license/new-bsd | ||
* If you did not receive a copy of the license and are unable to | ||
* obtain it through the world-wide-web, please send an email | ||
* to license@zend.com so we can send you a copy immediately. | ||
* | ||
* @category Zend | ||
* @package Zend_Stdlib | ||
* @subpackage Hydrator | ||
* @copyright Copyright (c) 2005-2012 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\Stdlib\Exception; | ||
|
||
/** | ||
* @category Zend | ||
* @package Zend_Stdlib | ||
* @subpackage Hydrator | ||
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) | ||
* @license http://framework.zend.com/license/new-bsd New BSD License | ||
*/ | ||
class ArraySerializable implements HydratorInterface | ||
{ | ||
/** | ||
* Extract values from the provided object | ||
* | ||
* Extracts values via the object's getArrayCopy() method. | ||
* | ||
* @param object $object | ||
* @return array | ||
* @throws Exception\BadMethodCallException for an $object not implementing getArrayCopy() | ||
*/ | ||
public function extract($object) | ||
{ | ||
if (!is_callable(array($object, 'getArrayCopy'))) { | ||
throw new Exception\BadMethodCallException(sprintf( | ||
'%s expects the provided object to implement getArrayCopy()', | ||
__METHOD__ | ||
)); | ||
} | ||
return $object->getArrayCopy(); | ||
} | ||
|
||
/** | ||
* Hydrate an object | ||
* | ||
* Hydrates an object by passing $data to either its exchangeArray() or | ||
* populate() method. | ||
* | ||
* @param array $data | ||
* @param object $object | ||
* @return object | ||
* @throws Exception\BadMethodCallException for an $object not implementing exchangeArray() or populate() | ||
*/ | ||
public function hydrate(array $data, $object) | ||
{ | ||
if (is_callable(array($object, 'exchangeArray'))) { | ||
$object->exchangeArray($data); | ||
} else if (is_callable(array($object, 'populate'))) { | ||
$object->populate($data); | ||
} else { | ||
throw new Exception\BadMethodCallException(sprintf( | ||
'%s expects the provided object to implement exchangeArray() or populate()', | ||
__METHOD__ | ||
)); | ||
} | ||
return $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,127 @@ | ||
<?php | ||
/** | ||
* Zend Framework | ||
* | ||
* LICENSE | ||
* | ||
* This source file is subject to the new BSD license that is bundled | ||
* with this package in the file LICENSE.txt. | ||
* It is also available through the world-wide-web at this URL: | ||
* http://framework.zend.com/license/new-bsd | ||
* If you did not receive a copy of the license and are unable to | ||
* obtain it through the world-wide-web, please send an email | ||
* to license@zend.com so we can send you a copy immediately. | ||
* | ||
* @category Zend | ||
* @package Zend_Stdlib | ||
* @subpackage Hydrator | ||
* @copyright Copyright (c) 2005-2012 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\Stdlib\Exception; | ||
|
||
/** | ||
* @category Zend | ||
* @package Zend_Stdlib | ||
* @subpackage Hydrator | ||
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) | ||
* @license http://framework.zend.com/license/new-bsd New BSD License | ||
*/ | ||
class ClassMethods implements HydratorInterface | ||
{ | ||
/** | ||
* CamelCase usage to extract attribute with getter/setter method name | ||
* @var boolean | ||
*/ | ||
protected $useCamelCase; | ||
|
||
/** | ||
* Define if extract values will use camel case or name with underscore | ||
* @param boolean $useCamelCase | ||
*/ | ||
public function __construct($useCamelCase = true) | ||
{ | ||
$this->useCamelCase = $useCamelCase; | ||
} | ||
|
||
/** | ||
* Extract values from an object with class methods | ||
* | ||
* Extracts the getter/setter of the given $object. | ||
* | ||
* @param object $object | ||
* @return array | ||
* @throws Exception\BadMethodCallException for a non-object $object | ||
*/ | ||
public function extract($object) | ||
{ | ||
if (!is_object($object)) { | ||
throw new Exception\BadMethodCallException(sprintf( | ||
'%s expects the provided $object to be a PHP object)', | ||
__METHOD__ | ||
)); | ||
} | ||
|
||
$transform = function($letters) | ||
{ | ||
$letter = array_shift($letters); | ||
return '_' . strtolower($letter); | ||
}; | ||
$attributes = array(); | ||
$methods = get_class_methods($object); | ||
foreach($methods as $method) { | ||
if(preg_match('/^get[A-Z]\w*/', $method)) { | ||
// setter verification | ||
$setter = preg_replace('/^get/', 'set', $method); | ||
if(!in_array($setter, $methods)) { | ||
continue; | ||
} | ||
$attribute = substr($method, 3); | ||
$attribute = lcfirst($attribute); | ||
if (!$this->useCamelCase) { | ||
$attribute = preg_replace_callback('/([A-Z])/', $transform, $attribute); | ||
} | ||
$attributes[$attribute] = $object->$method(); | ||
} | ||
} | ||
|
||
return $attributes; | ||
} | ||
|
||
/** | ||
* Hydrate an object by populating getter/setter methods | ||
* | ||
* Hydrates an object by getter/setter methods of the object. | ||
* | ||
* @param array $data | ||
* @param object $object | ||
* @return object | ||
* @throws Exception\BadMethodCallException for a non-object $object | ||
*/ | ||
public function hydrate(array $data, $object) | ||
{ | ||
if (!is_object($object)) { | ||
throw new Exception\BadMethodCallException(sprintf( | ||
'%s expects the provided $object to be a PHP object)', | ||
__METHOD__ | ||
)); | ||
} | ||
|
||
$transform = function($letters) | ||
{ | ||
$letter = substr(array_shift($letters), 1, 1); | ||
return ucfirst($letter); | ||
}; | ||
foreach ($data as $property => $value) { | ||
if (!$this->useCamelCase) { | ||
$property = preg_replace_callback('/(_[a-z])/', $transform, $property); | ||
} | ||
$method = 'set' . ucfirst($property); | ||
$object->$method($value); | ||
} | ||
return $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,49 @@ | ||
<?php | ||
/** | ||
* Zend Framework | ||
* | ||
* LICENSE | ||
* | ||
* This source file is subject to the new BSD license that is bundled | ||
* with this package in the file LICENSE.txt. | ||
* It is also available through the world-wide-web at this URL: | ||
* http://framework.zend.com/license/new-bsd | ||
* If you did not receive a copy of the license and are unable to | ||
* obtain it through the world-wide-web, please send an email | ||
* to license@zend.com so we can send you a copy immediately. | ||
* | ||
* @category Zend | ||
* @package Zend_Stdlib | ||
* @subpackage Hydrator | ||
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) | ||
* @license http://framework.zend.com/license/new-bsd New BSD License | ||
*/ | ||
|
||
namespace Zend\Stdlib\Hydrator; | ||
|
||
/** | ||
* @category Zend | ||
* @package Zend_Stdlib | ||
* @subpackage Hydrator | ||
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) | ||
* @license http://framework.zend.com/license/new-bsd New BSD License | ||
*/ | ||
interface HydratorInterface | ||
{ | ||
/** | ||
* Extract values from an object | ||
* | ||
* @param object $object | ||
* @return array | ||
*/ | ||
public function extract($object); | ||
|
||
/** | ||
* Hydrate $object with the provided $data. | ||
* | ||
* @param array $data | ||
* @param object $object | ||
* @return object | ||
*/ | ||
public function hydrate(array $data, $object); | ||
} |
Oops, something went wrong.