Skip to content

Commit

Permalink
Caching analyzed methods map for performance
Browse files Browse the repository at this point in the history
  • Loading branch information
Ocramius committed May 24, 2013
1 parent b9e5266 commit e56eefe
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion library/Zend/Stdlib/Hydrator/Filter/OptionalParametersFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,24 @@
*/
class OptionalParametersFilter implements FilterInterface
{
/**
* Map of methods already analyzed
* by {@see \Zend\Stdlib\Hydrator\Filter\OptionalParametersFilter::filter()},
* cached for performance reasons
*
* @var bool[]
*/
private static $propertiesCache = array();

/**
* {@inheritDoc}
*/
public function filter($property)
{
if (isset(self::$propertiesCache[$property])) {
return self::$propertiesCache[$property];
}

try {
$reflectionMethod = new ReflectionMethod($property);
} catch (ReflectionException $exception) {
Expand All @@ -36,6 +49,6 @@ function (ReflectionParameter $parameter) {
}
);

return empty($mandatoryParameters);
return self::$propertiesCache[$property] = empty($mandatoryParameters);
}
}

0 comments on commit e56eefe

Please sign in to comment.