Skip to content

Commit

Permalink
Add new interface FilterEnabledInterface
Browse files Browse the repository at this point in the history
  • Loading branch information
mouhamed committed Jun 29, 2013
1 parent 0493616 commit c874d77
Show file tree
Hide file tree
Showing 2 changed files with 98 additions and 32 deletions.
63 changes: 31 additions & 32 deletions library/Zend/Stdlib/Hydrator/AbstractHydrator.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,8 @@
use Zend\Stdlib\Hydrator\StrategyEnabledInterface;
use Zend\Stdlib\Hydrator\Strategy\StrategyInterface;
use Zend\Stdlib\Hydrator\Strategy\DefaultStrategy;
use Zend\Stdlib\Hydrator\Filter\FilterProviderInterface;

abstract class AbstractHydrator implements HydratorInterface, StrategyEnabledInterface, FilterProviderInterface
abstract class AbstractHydrator implements HydratorInterface, StrategyEnabledInterface, FilterEnabledInterface
{
/**
* The list with strategies that this hydrator has.
Expand Down Expand Up @@ -101,36 +100,6 @@ public function removeStrategy($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.
* @param array $object The object is optionally provided as context.
* @return mixed
*/
public function extractValue($name, $value, $object = null)
{
$strategy = $this->hasStrategy($name) ? $this->getStrategy($name) : new DefaultStrategy();

return $strategy->extract($value, $object);
}

/**
* 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.
* @param array $data The whole data is optionally provided as context.
* @return mixed
*/
public function hydrateValue($name, $value, $data = null)
{
$strategy = $this->hasStrategy($name) ? $this->getStrategy($name) : new DefaultStrategy();

return $strategy->hydrate($value, $data);
}

/**
* Get the filter instance
*
Expand Down Expand Up @@ -193,4 +162,34 @@ public function removeFilter($name)
{
return $this->filterComposite->removeFilter($name);
}

/**
* 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.
* @param array $object The object is optionally provided as context.
* @return mixed
*/
public function extractValue($name, $value, $object = null)
{
$strategy = $this->hasStrategy($name) ? $this->getStrategy($name) : new DefaultStrategy();

return $strategy->extract($value, $object);
}

/**
* 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.
* @param array $data The whole data is optionally provided as context.
* @return mixed
*/
public function hydrateValue($name, $value, $data = null)
{
$strategy = $this->hasStrategy($name) ? $this->getStrategy($name) : new DefaultStrategy();

return $strategy->hydrate($value, $data);
}
}
67 changes: 67 additions & 0 deletions library/Zend/Stdlib/Hydrator/FilterEnabledInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2013 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\Hydrator\Filter\FilterInterface;
use Zend\Stdlib\Hydrator\Filter\FilterComposite;

interface FilterEnabledInterface
{
/**
* Add a new filter to take care of what needs to be hydrated.
* To exclude e.g. the method getServiceLocator:
*
* <code>
* $composite->addFilter("servicelocator",
* function($property) {
* list($class, $method) = explode('::', $property);
* if ($method === 'getServiceLocator') {
* return false;
* }
* return true;
* }, FilterComposite::CONDITION_AND
* );
* </code>
*
* @param string $name Index in the composite
* @param callable|FilterInterface $filter
* @param int $condition
* @return FilterComposite
*/
public function addFilter($name, $filter, $condition = FilterComposite::CONDITION_OR);

/**
* Get the filter instance
*
* @return FilterComposite
*/
public function getFilter();

/**
* Check whether a specific filter exists at key $name or not
*
* @param string $name Index in the composite
* @return bool
*/
public function hasFilter($name);

/**
* Remove a filter from the composition.
* To not extract "has" methods, you simply need to unregister it
*
* <code>
* $filterComposite->removeFilter('has');
* </code>
*
* @param $name
* @return FilterComposite
*/
public function removeFilter($name);
}

0 comments on commit c874d77

Please sign in to comment.