Source of file OptionalParametersFilter.php
Size: 1,628 Bytes - Last Modified: 2014-03-12T23:21:18+01:00
/home/theseer/Downloads/ZendFramework-2.3.0/library/Zend/Stdlib/Hydrator/Filter/OptionalParametersFilter.php
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455 | <?php /** * Zend Framework (http://framework.zend.com/) * * @link http://github.com/zendframework/zf2 for the canonical source repository * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ namespace Zend\Stdlib\Hydrator\Filter; use InvalidArgumentException; use ReflectionException; use ReflectionMethod; use ReflectionParameter; /** * Filter that includes methods which have no parameters or only optional parameters */ 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(static::$propertiesCache[$property])) { return static::$propertiesCache[$property]; } try { $reflectionMethod = new ReflectionMethod($property); } catch (ReflectionException $exception) { throw new InvalidArgumentException(sprintf('Method %s doesn\'t exist', $property)); } $mandatoryParameters = array_filter( $reflectionMethod->getParameters(), function (ReflectionParameter $parameter) { return ! $parameter->isOptional(); } ); return static::$propertiesCache[$property] = empty($mandatoryParameters); } } |