Skip to content
This repository has been archived by the owner on Jan 31, 2020. It is now read-only.

Commit

Permalink
Merge remote-tracking branch 'upstream/develop' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
blanchonvincent committed Dec 18, 2012
164 parents 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 + f2ce9f7 + 2eb75ba + f1c4b1b + b67f270 + ff615a6 + 5cf3c74 + 8c883f5 + 3f0ab11 + ba47a31 + ede9ab9 + daaff96 + bb8e9d5 commit 0fc5628
Show file tree
Hide file tree
Showing 9 changed files with 371 additions and 11 deletions.
10 changes: 5 additions & 5 deletions src/AbstractOptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ abstract class AbstractOptions implements ParameterObjectInterface

/**
* @param array|Traversable|null $options
* @return AbstractOptions
* @throws Exception\InvalidArgumentException
*/
public function __construct($options = null)
{
Expand All @@ -41,7 +39,7 @@ public function __construct($options = null)
/**
* @param array|Traversable $options
* @throws Exception\InvalidArgumentException
* @return void
* @return AbstractOptions Provides fluent interface
*/
public function setFromArray($options)
{
Expand All @@ -55,6 +53,7 @@ public function setFromArray($options)
foreach ($options as $key => $value) {
$this->__set($key, $value);
}
return $this;
}

/**
Expand Down Expand Up @@ -115,6 +114,7 @@ public function __get($key)
. 'which must be defined'
);
}

return $this->{$getter}();
}

Expand All @@ -131,14 +131,14 @@ public function __isset($key)
/**
* @see ParameterObject::__unset()
* @param string $key
* @return void
* @throws Exception\InvalidArgumentException
* @return void
*/
public function __unset($key)
{
try {
$this->__set($key, null);
} catch (\InvalidArgumentException $e) {
} catch (Exception\BadMethodCallException $e) {
throw new Exception\InvalidArgumentException(
'The class property $' . $key . ' cannot be unset as'
. ' NULL is an invalid value for it',
Expand Down
18 changes: 16 additions & 2 deletions src/Hydrator/AbstractHydrator.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
namespace Zend\Stdlib\Hydrator;

use ArrayObject;
use Zend\Stdlib\Exception;
use Zend\Stdlib\Hydrator\StrategyEnabledInterface;
use Zend\Stdlib\Hydrator\Strategy\StrategyInterface;

Expand Down Expand Up @@ -44,7 +45,19 @@ public function __construct()
*/
public function getStrategy($name)
{
return $this->strategies[$name];
if (isset($this->strategies[$name])) {
return $this->strategies[$name];
}

if (!isset($this->strategies['*'])) {
throw new Exception\InvalidArgumentException(sprintf(
'%s: no strategy by name of "%s", and no wildcard strategy present',
__METHOD__,
$name
));
}

return $this->strategies['*'];
}

/**
Expand All @@ -55,7 +68,8 @@ public function getStrategy($name)
*/
public function hasStrategy($name)
{
return array_key_exists($name, $this->strategies);
return array_key_exists($name, $this->strategies)
|| array_key_exists('*', $this->strategies);
}

/**
Expand Down
45 changes: 42 additions & 3 deletions src/Hydrator/ClassMethods.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,61 @@
* @package Zend_Stdlib
* @subpackage Hydrator
*/
class ClassMethods extends AbstractHydrator
class ClassMethods extends AbstractHydrator implements HydratorOptionsInterface
{
/**
* Flag defining whether array keys are underscore-separated (true) or camel case (false)
* @var boolean
*/
protected $underscoreSeparatedKeys;
protected $underscoreSeparatedKeys = true;

/**
* Define if extract values will use camel case or name with underscore
* @param boolean $underscoreSeparatedKeys
* @param boolean|array $underscoreSeparatedKeys
*/
public function __construct($underscoreSeparatedKeys = true)
{
parent::__construct();
$this->setUnderscoreSeparatedKeys($underscoreSeparatedKeys);
}

/**
* @param array|\Traversable $options
* @return ClassMethods
* @throws Exception\InvalidArgumentException
*/
public function setOptions($options)
{
if ($options instanceof Traversable) {
$options = ArrayUtils::iteratorToArray($options);
} elseif (!is_array($options)) {
throw new Exception\InvalidArgumentException(
'The options parameter must be an array or a Traversable'
);
}
if (isset($options['underscoreSeparatedKeys'])) {
$this->setUnderscoreSeparatedKeys($options['underscoreSeparatedKeys']);
}

return $this;
}

/**
* @param boolean $underscoreSeparatedKeys
* @return ClassMethods
*/
public function setUnderscoreSeparatedKeys($underscoreSeparatedKeys)
{
$this->underscoreSeparatedKeys = $underscoreSeparatedKeys;
return $this;
}

/**
* @return boolean
*/
public function getUnderscoreSeparatedKeys()
{
return $this->underscoreSeparatedKeys;
}

/**
Expand Down
25 changes: 25 additions & 0 deletions src/Hydrator/HydratorOptionsInterface.php
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-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;

/**
* @category Zend
* @package Zend_Stdlib
* @subpackage Hydrator
*/
interface HydratorOptionsInterface
{
/**
* @param array|\Traversable $options
* @return HydratorOptionsInterface
*/
public function setOptions($options);
}
128 changes: 128 additions & 0 deletions src/Hydrator/Strategy/SerializableStrategy.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
<?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;

use Zend\Stdlib\Exception\InvalidArgumentException;
use Zend\Serializer\Adapter\AdapterInterface as SerializerAdapter;
use Zend\Serializer\Serializer as SerializerFactory;

/**
* @category Zend
* @package Zend_Stdlib_Hydrator
* @subpackage Strategy
*/
class SerializableStrategy implements StrategyInterface
{
/**
* @var string|SerializerAdapter
*/
protected $serializer;

/**
* @var array
*/
protected $serializerOptions = array();

/**
*
* @param mixed $serializer string or SerializerAdapter
*/
public function __construct($serializer, $serializerOptions = null)
{
$this->setSerializer($serializer);
if($serializerOptions) {
$this->setSerializerOptions($serializerOptions);
}
}

/**
* Serialize 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)
{
$serializer = $this->getSerializer();
return $serializer->serialize($value);
}

/**
* Unserialize 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)
{
$serializer = $this->getSerializer();
return $serializer->unserialize($value);
}

/**
* Set serializer
*
* @param string|SerializerAdapter $serializer
* @return Serializer
*/
public function setSerializer($serializer)
{
if (!is_string($serializer) && !$serializer instanceof SerializerAdapter) {
throw new InvalidArgumentException(sprintf(
'%s expects either a string serializer name or Zend\Serializer\Adapter\AdapterInterface instance; '
. 'received "%s"',
__METHOD__,
(is_object($serializer) ? get_class($serializer) : gettype($serializer))
));
}
$this->serializer = $serializer;
return $this;
}

/**
* Get serializer
*
* @return SerializerAdapter
*/
public function getSerializer()
{
if (is_string($this->serializer)) {
$options = $this->getSerializerOptions();
$this->setSerializer(SerializerFactory::factory($this->serializer, $options));
} elseif (null === $this->serializer) {
$this->setSerializer(SerializerFactory::getDefaultAdapter());
}

return $this->serializer;
}

/**
* Set configuration options for instantiating a serializer adapter
*
* @param mixed $serializerOptions
* @return SerializableStrategy
*/
public function setSerializerOptions($serializerOptions)
{
$this->serializerOptions = $serializerOptions;
return $this;
}

/**
* Get configuration options for instantiating a serializer adapter
*
* @return mixed
*/
public function getSerializerOptions()
{
return $this->serializerOptions;
}
}
27 changes: 27 additions & 0 deletions src/InitializableInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?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;

/**
* Interface to allow objects to have initialization logic
*
* @category Zend
* @package Zend_Stdlib
*/
interface InitializableInterface
{
/**
* Init an object
*
* @return void
*/
public function init();
}
Loading

0 comments on commit 0fc5628

Please sign in to comment.