Skip to content

Commit

Permalink
Allowing ClassMethods to also call methods with optional parameters
Browse files Browse the repository at this point in the history
Fixes test @b47c85e045b185cec8fd6b95b6db2d3d4ddf2a5c
  • Loading branch information
Ocramius committed May 17, 2013
1 parent b47c85e commit b9e5266
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions library/Zend/Stdlib/Hydrator/ClassMethods.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
use Zend\Stdlib\Hydrator\Filter\HasFilter;
use Zend\Stdlib\Hydrator\Filter\IsFilter;
use Zend\Stdlib\Hydrator\Filter\MethodMatchFilter;
use Zend\Stdlib\Hydrator\Filter\NumberOfParameterFilter;
use Zend\Stdlib\Hydrator\Filter\OptionalParametersFilter;

class ClassMethods extends AbstractHydrator implements HydratorOptionsInterface
{
Expand All @@ -29,6 +29,11 @@ class ClassMethods extends AbstractHydrator implements HydratorOptionsInterface
*/
protected $underscoreSeparatedKeys = true;

/**
* @var \Zend\Stdlib\Hydrator\Filter\FilterInterface
*/
private $callableMethodFilter;

/**
* Define if extract values will use camel case or name with underscore
* @param bool|array $underscoreSeparatedKeys
Expand All @@ -38,10 +43,12 @@ public function __construct($underscoreSeparatedKeys = true)
parent::__construct();
$this->setUnderscoreSeparatedKeys($underscoreSeparatedKeys);

$this->callableMethodFilter = new OptionalParametersFilter();

$this->filterComposite->addFilter("is", new IsFilter());
$this->filterComposite->addFilter("has", new HasFilter());
$this->filterComposite->addFilter("get", new GetFilter());
$this->filterComposite->addFilter("parameter", new NumberOfParameterFilter(), FilterComposite::CONDITION_AND);
$this->filterComposite->addFilter("parameter", new OptionalParametersFilter(), FilterComposite::CONDITION_AND);
}

/**
Expand Down Expand Up @@ -128,8 +135,7 @@ public function extract($object)
continue;
}

$reflectionMethod = new ReflectionMethod(get_class($object) . '::' . $method);
if ($reflectionMethod->getNumberOfParameters() > 0) {
if (!$this->callableMethodFilter->filter(get_class($object) . '::' . $method)) {
continue;
}

Expand Down

0 comments on commit b9e5266

Please sign in to comment.