OptionalParametersFilter.php in Zircon Profile 8
File
vendor/zendframework/zend-hydrator/src/Filter/OptionalParametersFilter.php
View source
<?php
namespace Zend\Hydrator\Filter;
use ReflectionException;
use ReflectionMethod;
use ReflectionParameter;
use Zend\Hydrator\Exception\InvalidArgumentException;
class OptionalParametersFilter implements FilterInterface {
protected static $propertiesCache = [];
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);
}
}