protected function addVisitors(Container $container)
{
foreach ($this->checkerVisitors as $visitorServiceName => $visitorParameters) {
$container[$visitorServiceName] = function ($c) use($visitorParameters) {
$visitorDependencyServiceNames = isset($visitorParameters['dependencies']) ? $visitorParameters['dependencies'] : array();
$otherVisitorArguments = isset($visitorParameters['arguments']) ? $visitorParameters['arguments'] : array();
$visitorClassName = $visitorParameters['class'];
if (!$visitorDependencyServiceNames && !$otherVisitorArguments) {
/* This early return is required, because a ReflectionException is thrown
* from ReflectionClass::newInstanceArgs for classes without constructors
* on PHP 5.3.3
*/
return new $visitorClassName();
}
$visitorClassReflection = new \ReflectionClass($visitorClassName);
$visitorDependencies = array();
foreach ($visitorDependencyServiceNames as $serviceName) {
$visitorDependencies[] = $c[$serviceName];
}
return $visitorClassReflection->newInstanceArgs(array_merge($visitorDependencies, $otherVisitorArguments));
};
}
}