public function convertMethodAnnotations(\ReflectionMethod $method, array $annotations) { $parameters = array(); foreach ($method->getParameters() as $index => $parameter) { $parameters[$parameter->getName()] = $index; } $methodMetadata = new MethodMetadata($method->getDeclaringClass()->getName(), $method->getName()); foreach ($annotations as $annotation) { if ($annotation instanceof Secure) { $methodMetadata->roles = $annotation->roles; } else { if ($annotation instanceof SecureParam) { if (!isset($parameters[$annotation->name])) { throw new \InvalidArgumentException(sprintf('The parameter "%s" does not exist for method "%s".', $annotation->name, $method->getName())); } $methodMetadata->addParamPermissions($parameters[$annotation->name], $annotation->permissions); } else { if ($annotation instanceof SecureReturn) { $methodMetadata->returnPermissions = $annotation->permissions; } else { if ($annotation instanceof SatisfiesParentSecurityPolicy) { $methodMetadata->satisfiesParentSecurityPolicy = true; } else { if ($annotation instanceof RunAs) { $methodMetadata->runAsRoles = $annotation->roles; } } } } } } return $methodMetadata; }
public function writeMethod(\ReflectionMethod $method) { $args = []; foreach ($method->getParameters() as $parameter) { $arg = ''; if ($parameter->isArray()) { $arg .= 'array '; } else { if ($parameter->getClass()) { $arg .= '\\' . $parameter->getClass()->getName() . ' '; } } if ($parameter->isPassedByReference()) { $arg .= '&'; } $arg .= '$' . $parameter->getName(); try { $defaultValue = $parameter->getDefaultValue(); $arg .= ' = ' . var_export($defaultValue, true); } catch (ReflectionException $e) { if ($parameter->isOptional()) { $arg .= ' = null'; } } $args[] = $arg; } $modifiers = array_diff(\Reflection::getModifierNames($method->getModifiers()), ['abstract']); $methodName = ($method->returnsReference() ? '&' : '') . $method->getName(); $this->code[] = ' ' . implode(' ', $modifiers) . ' function ' . $methodName . '(' . implode(', ', $args) . ') {'; $this->code[] = ' $result = $this->' . $this->propertyName . '->invoke($this, \'' . $method->getName() . '\', func_get_args());'; $this->code[] = ' return $result;'; $this->code[] = ' }'; }
public function validate_action(Request $request) { try { $rmethod = new ReflectionMethod($this->controller, $request->parameter('action')); } catch (ReflectionException $rfEx) { throw new ChainError($rfEx->getMessage()); } if (!$rmethod->isPublic() || $rmethod->isStatic()) { throw new ChainError('Method `' . $rmethod->getName() . '` should be declared as public on class instance `' . get_class($this->controller) . '`'); } $rparams = $rmethod->getParameters(); $action_args = array(); foreach ($rparams as $arg) { $arg_name = $arg->getName(); $arg_value = $request->parameter($arg_name); // XXX: detect behavior on Merb / Django if (null === $arg_value) { if ($arg->isOptional()) { continue; } else { throw new ChainError('Mandatory agrument `' . $arg_name . '` for action `' . $rmethod->getName() . '` not in request!'); } } $action_args[$arg_name] = $arg_value; } // ready to fire this action later $this->chain['action'] = array($rmethod, $action_args); // return true for now return true; }
/** * @param \ReflectionMethod $method * @return mixed|string */ public function build(\ReflectionMethod $method) { $functionDefinition = file_get_contents(__DIR__ . '/template/Function.php.template'); $functionDefinition = str_replace('%name%', $method->getName(), $functionDefinition); $arguments = ''; // TODO I guess this won't cut it if (substr($method->getName(), 0, 2) !== '__') { foreach ($method->getParameters() as $parameter) { $type = ''; if ($parameter->getClass() !== null) { $type = $parameter->getClass()->getName(); } elseif ($parameter->isArray()) { $type = 'array'; } $default = ''; if ($parameter->isDefaultValueAvailable()) { if (null === $parameter->getDefaultValue()) { $default = '= NULL'; } else { $default = sprintf("='%s'", $parameter->getDefaultValue()); } } elseif ($parameter->isOptional()) { // Workaround for optional parameters of internal methods $default = '= NULL'; } $arguments .= sprintf('%s $%s %s ,', $type, $parameter->getName(), $default); } $arguments = rtrim($arguments, ','); } $functionDefinition = str_replace('%arguments%', $arguments, $functionDefinition); return $functionDefinition; }
/** * @dataProvider getDriverInterfaceMethods */ public function testInterfaceMethods(\ReflectionMethod $method) { $refl = new \ReflectionClass('Behat\\Mink\\Driver\\CoreDriver'); $this->assertFalse($refl->getMethod($method->getName())->isAbstract(), sprintf('CoreDriver should implement a dummy %s method', $method->getName())); $driver = $this->getMockForAbstractClass('Behat\\Mink\\Driver\\CoreDriver'); $this->setExpectedException('Behat\\Mink\\Exception\\UnsupportedDriverActionException'); call_user_func_array(array($driver, $method->getName()), $this->getArguments($method)); }
protected function configureRoute(Route $route, \ReflectionClass $class, \ReflectionMethod $method, $annot) { if ($annot instanceof BrickRoute) { $route->setDefault('_controller', $annot->getService() . ':' . $method->getName()); } else { $route->setDefault('_controller', $class->getName() . '::' . $method->getName()); } }
/** * Gets a method's details * * @param string $visibility Method visibility * @param \ReflectionMethod $method Method's \ReflectionMethod instance * @return MethodData */ private function getMethodDetails($visibility, \ReflectionMethod $method) { $details = new MethodData(); $details->name = $method->getName(); $details->visibility = $visibility; $details->isSetter = preg_match('/^set/', $method->getName()) === 1 ? true : false; $details->arguments = $this->argumentWorker->generateArgumentObjects($method); return $details; }
public function getName() { $name = $this->getAnnotation('name'); if (!$name) { $name = $this->reflection->getName(); } $name = $this->convertName($name); return $name; }
public function execute($object) { $handler = $this->factory->getInstance($this->method->getDeclaringClass()->getName()); $properties = $this->getProperties($object); $args = []; foreach ($this->method->getParameters() as $parameter) { $args[] = $properties[$parameter->getName()]->get($object); } return call_user_func_array([$handler, $this->method->getName()], $args); }
/** * @param string | object $listener * @param \ReflectionMethod $methodReflection * @return array */ protected function createHandler($listener, \ReflectionMethod $methodReflection) { if (is_string($listener) && $methodReflection->isStatic()) { return [$listener, $methodReflection->getName()]; } elseif (is_object($listener) && $methodReflection->isStatic()) { return [get_class($listener), $methodReflection->getName()]; } elseif (is_object($listener) && $methodReflection->isStatic() == false) { return [$listener, $methodReflection->getName()]; } return false; }
/** * Exports the PHP code * * @return string */ public function exportCode() { $modifiers = \Reflection::getModifierNames($this->_method->getModifiers()); $params = array(); // Export method's parameters foreach ($this->_method->getParameters() as $param) { $reflection_parameter = new ReflectionParameter($param); $params[] = $reflection_parameter->exportCode(); } return sprintf('%s function %s(%s) {}', join(' ', $modifiers), $this->_method->getName(), join(', ', $params)); }
/** * Collect method info * * @param ReflectionMethod $method * @return array */ protected function _getMethodInfo(ReflectionMethod $method) { $parameterNames = array(); $parameters = array(); foreach ($method->getParameters() as $parameter) { $parameterNames[] = '$' . $parameter->getName(); $parameters[] = $this->_getMethodParameterInfo($parameter); } $methodInfo = array('name' => $method->getName(), 'parameters' => $parameters, 'body' => $this->_getMethodBody($method->getName(), $parameterNames), 'docblock' => array('shortDescription' => '{@inheritdoc}')); return $methodInfo; }
/** * Runs the test method. * @return void */ private function runMethod($method) { $method = new \ReflectionMethod($this, $method); if (!$method->isPublic()) { throw new TestCaseException("Method {$method->getName()} is not public. Make it public or rename it."); } $data = array(); $info = Helpers::parseDocComment($method->getDocComment()) + array('dataprovider' => NULL, 'throws' => NULL); if ($info['throws'] === '') { throw new TestCaseException("Missing class name in @throws annotation for {$method->getName()}()."); } elseif (is_array($info['throws'])) { throw new TestCaseException("Annotation @throws for {$method->getName()}() can be specified only once."); } else { $throws = preg_split('#\\s+#', $info['throws'], 2) + array(NULL, NULL); } $defaultParams = array(); foreach ($method->getParameters() as $param) { $defaultParams[$param->getName()] = $param->isDefaultValueAvailable() ? $param->getDefaultValue() : NULL; } foreach ((array) $info['dataprovider'] as $provider) { $res = $this->getData($provider); if (!is_array($res)) { throw new TestCaseException("Data provider {$provider}() doesn't return array."); } foreach ($res as $set) { $data[] = is_string(key($set)) ? array_merge($defaultParams, $set) : $set; } } if (!$info['dataprovider']) { if ($method->getNumberOfRequiredParameters()) { throw new TestCaseException("Method {$method->getName()}() has arguments, but @dataProvider is missing."); } $data[] = array(); } foreach ($data as $args) { try { if ($info['throws']) { $tmp = $this; $e = Assert::error(function () use($tmp, $method, $args) { $tmp->runTest($method->getName(), $args); }, $throws[0], $throws[1]); if ($e instanceof AssertException) { throw $e; } } else { $this->runTest($method->getName(), $args); } } catch (AssertException $e) { throw $e->setMessage("{$e->origMessage} in {$method->getName()}" . substr(Dumper::toLine($args), 5)); } } }
/** * Handle method annotations * * @param mixed $targetObj * @param \ReflectionMethod $reflection * @param array $annotations * * @return mixed */ public function handleMethodAnnotations(\ReflectionMethod $reflection, array $annotations, $targetObj = null) { if (isset($annotations['Route'])) { foreach ($annotations['Route'] as $route) { if ($route instanceof \stdClass && isset($route->path)) { $symfonyRoute = new Route($route->path, isset($route->defaults) ? $route->defaults : [], isset($route->requirements) ? $route->requirements : [], isset($route->options) ? $route->options : [], isset($route->host) ? $route->host : '', isset($route->schemes) ? $route->schemes : [], isset($route->methods) ? $route->methods : []); $symfonyRoute->setOption('karmaController', $reflection->getDeclaringClass()->getName()); $symfonyRoute->setOption('karmaAction', $reflection->getName()); $this->routeCollection->add(isset($route->name) ? $route->name : $reflection->getDeclaringClass()->getName() . ':' . $reflection->getName(), $symfonyRoute); } } } }
/** * @param \ReflectionMethod $reflectionMethod * @param \Donquixote\HastyReflectionCommon\Reflection\FunctionLike\MethodReflectionInterface $methodReflection */ private function assertEqualMethods(\ReflectionMethod $reflectionMethod, MethodReflectionInterface $methodReflection) { $this->assertEquals($reflectionMethod->isAbstract(), $methodReflection->isAbstract()); $this->assertEquals($reflectionMethod->getDeclaringClass()->getName(), $methodReflection->getDeclaringClassName()); $this->assertEquals($reflectionMethod->getDocComment(), $methodReflection->getDocComment()); $this->assertEquals($reflectionMethod->getShortName(), $methodReflection->getName()); $this->assertEquals($reflectionMethod->getName(), $methodReflection->getName()); $this->assertEquals($reflectionMethod->class . '::' . $reflectionMethod->getName(), $methodReflection->getQualifiedName()); $this->assertEquals($reflectionMethod->returnsReference(), $methodReflection->isByReference()); $this->assertEquals($reflectionMethod->isPrivate(), $methodReflection->isPrivate()); $this->assertEquals($reflectionMethod->isProtected(), $methodReflection->isProtected()); $this->assertEquals($reflectionMethod->isPublic(), $methodReflection->isPublic()); $this->assertEquals($reflectionMethod->isStatic(), $methodReflection->isStatic()); }
/** * Configures the _controller default parameter and eventually the _method * requirement of a given Route instance. * * @param Route $route A Route instance * @param ReflectionClass $class A ReflectionClass instance * @param ReflectionMethod $method A ReflectionClass method */ protected function configureRoute(Route $route, \ReflectionClass $class, \ReflectionMethod $method, $annot) { // controller if ($service = $annot->getService()) { $route->setDefault('_controller', $service . ':' . $method->getName()); } else { $route->setDefault('_controller', $class->getName() . '::' . $method->getName()); } // requirements (@extra:Method) foreach ($this->configReader->getMethodAnnotations($method) as $configuration) { if ($configuration instanceof Method) { $route->setRequirement('_method', implode('|', $configuration->getMethods())); } } }
function handleMethod(Module $module, ReflectionMethod $method, $params) { $name = $method->getName(); // имя метода $args = $method->getParameters(); // имя аргумента метода //проверка являеется ли метод "установщиком" (set) if (count($args) != 1 || substr($name, 0, 3) != "set") { return false; } $property = strtolower(substr($name, 3)); // получаем имя свойства if (!isset($params[$property])) { // проверяем есть ли такое свойство в асоциативном массиве с параметрами return false; } $arg_class = $args[0]->getClass(); // узнаём тип аргумента метода установщика if (empty($arg_class)) { // если у аргумента нету типа, значит это не объект $method->invoke($module, $params[$property]); // если не объект, то передаём нашему "модулю" обычный параметр } else { $method->invoke($module, $arg_class->newInstance($params[$property])); // если это объект, то передаём тип (класс) аргумента, и его значение, создаём объект и передаем его нашему "модулю" } }
/** * Actual routing + sanitizing data * * @param $class * @param array $params */ public static function connect($namespace, $class, $params = array()) { $defaults = array('indexPage' => 'index', 'loginPage' => false, 'loginRedirect' => false); static::$class = strtolower($class); $class = $namespace . '\\' . $class; $params += $defaults; extract($params); // Authenticated controllers if ($loginPage) { Auth::checkLogin($loginRedirect, $loginPage); } $method = $indexPage; $parameters = array(); if (isset($_SERVER[URI_INFO])) { $url = explode('/', substr($_SERVER[URI_INFO], 1)); array_shift($url); if ($url) { foreach ($url as $key => $element) { if (!$key && !is_numeric($element)) { $method = $element; } else { $parameters[] = $element; } } } } // Check availability try { $methodInfo = new \ReflectionMethod($class, $method); // Methods that start with _ are not accesible from browser $name = $methodInfo->getName(); if ($name[0] == '_') { $method = $indexPage; } $methodParams = $methodInfo->getParameters(); // Force cast parameters by arguments default value if ($methodParams) { foreach ($methodParams as $parameterKey => $parameterValue) { try { $defaultValue = $parameterValue->getDefaultValue(); $type = gettype($defaultValue); if ($defaultValue) { unset($methodParams[$parameterKey]); } // settype($parameters[$parameterKey], $type); } catch (\Exception $e) { continue; } } } // if(count($methodParams) != count($parameters)) { // $parameters = array(); // } } catch (\Exception $e) { $method = $indexPage; } static::$method = $method; call_user_func_array($class . '::' . $method, $parameters); return; }
public final function generateCode(ReflectionClass $class, $test_double_class_name, array $interfaces = array(), array $traits = array(), $method_checker = null) { FBMock_Utils::assertString($test_double_class_name); if ($class->isFinal() && !$this->canOverrideFinals()) { throw new FBMock_TestDoubleException("Cannot mock final class %s", $class->getName()); } $code = $this->getMockClassHeader($class, $test_double_class_name, $interfaces, $traits) . "\n"; $method_sources = array(); foreach ($class->getMethods() as $method) { $method_checker && $method_checker($class, $method); if ($method->isFinal() && !$this->canOverrideFinals()) { continue; } // #1137433 if (!$class->isInterface()) { $method = new ReflectionMethod($class->getName(), $method->getName()); } $test_double_method_generator = FBMock_Config::get()->getMethodGenerator(); $method_source = $test_double_method_generator->generateCode($method); if ($method_source) { $method_sources[] = $method_source; } } $code .= implode("\n\n", $method_sources); $code .= "\n}"; // close class return $code; }
/** * @param ReflectionClass $theClass * @param Stagehand_TestRunner_Config $config * @return boolean */ protected function shouldExclude(ReflectionClass $class, ReflectionMethod $method) { if (is_null($this->config->phpunitConfigFile)) { return false; } $groups = PHPUnit_Util_Test::getGroups($class->getName(), $method->getName()); $shouldExclude = false; $groupConfiguration = PHPUnit_Util_Configuration::getInstance($this->config->phpunitConfigFile)->getGroupConfiguration(); if (array_key_exists('include', $groupConfiguration) && count($groupConfiguration['include'])) { $shouldExclude = true; foreach ($groups as $group) { if (in_array($group, $groupConfiguration['include'])) { $shouldExclude = false; break; } } } if (array_key_exists('exclude', $groupConfiguration) && count($groupConfiguration['exclude'])) { foreach ($groups as $group) { if (in_array($group, $groupConfiguration['exclude'])) { $shouldExclude = true; break; } } } return $shouldExclude; }
private function generateMethod($methodName, $methodBody, $className) { $method = new \ReflectionMethod($className, $methodName); $parameters = $method->getParameters(); $parameterNames = []; foreach ($parameters as $parameter) { $parameterNames[] = '$' . $parameter->getName(); } $hasMethodBody = $methodBody ? 'true' : 'false'; $methodName = $method->getName(); $parameters = implode(',', $parameterNames); $methodString = 'public function ' . $methodName . '(' . $parameters . ') { $methodName = "' . $methodName . '"; if (isset($this->mockCalls[$methodName])) $this->mockCalls[$methodName]++; else $this->mockCalls[$methodName] = 1; if (' . $hasMethodBody . ') { ' . $methodBody . ' } else return parent::$methodName(' . $parameters . '); }'; return $methodString; }
/** * @param \ReflectionMethod $method * @return bool */ private function isAutoloadMethod(\ReflectionMethod $method) { if (strpos($method->getName(), KnotConsts::AUTOLOAD_METHOD_PREFIX) !== 0 || $method->getNumberOfParameters() != 1 || $method->getNumberOfRequiredParameters() != 1 || $method->isStatic() || $method->isAbstract() || !Extractor::instance()->has($method, KnotConsts::AUTOLOAD_ANNOTATIONS)) { return false; } return true; }
/** * @param \ReflectionMethod $method */ public function __construct(ClassSymbol $class, \ReflectionMethod $method) { $this->classSymbol = $class; $this->reflectionMethod = $method; $this->parameters = $method->getParameters(); $this->handle = $method->getName(); }
public function getSql(ReflectionMethod $method, $suffix = null) { if (is_null($suffix)) { $suffix = ''; } $methodName = $method->getName(); $key1 = $methodName . self::UNDERSCORE . $suffix . self::SQL_SUFFIX; if ($this->reflector->hasConstant($key1)) { return $this->reflector->getConstant($key1); } $key2 = $methodName . self::SQL_SUFFIX; if ($this->reflector->hasConstant($key2)) { return $this->reflector->getConstant($key2); } $fileName = $this->reflector->getFileName(); $className = $this->reflector->getName(); $dirPath = dirname($fileName) . DIRECTORY_SEPARATOR; $key3 = $dirPath . self::underscore($className, $methodName, $suffix) . self::SQL_FILE_EXTENSION; if (file_exists($key3)) { return file_get_contents($key3); } $key4 = $dirPath . self::underscore($className, $methodName) . self::SQL_FILE_EXTENSION; if (file_exists($key4)) { return file_get_contents($key4); } return null; }
/** * @param \ReflectionClass $class * @param \ReflectionMethod $method * @param Reader $reader * @return array */ public function getServiceDefinition(\ReflectionClass $class, \ReflectionMethod $method, Reader $reader) { $params = []; $definition = ['arguments' => [], 'class' => $class->getName(), 'method' => $method->getName(), 'singleton' => false]; $annotations = $reader->getMethodAnnotations($method); foreach ($annotations as $annotation) { if ($annotation instanceof Inject) { $params[$annotation->param] = $annotation->id; } elseif ($annotation instanceof Provides) { $definition['alias'] = $annotation->alias; $definition['id'] = $annotation->id; } elseif ($annotation instanceof Singleton) { $definition['singleton'] = true; } } foreach ($method->getParameters() as $parameter) { if (isset($params[$parameter->name])) { $definition['arguments'][] = ['name' => $params[$parameter->name]]; continue; } if ($parameter->name === $definition['id']) { throw new ContainerException("Cyclic injection detected for '{$parameter->name}' parameter in {$definition['class']}::{$definition['method']}"); } $argument = ['name' => $parameter->name]; if ($clazz = $parameter->getClass()) { $argument['class'] = $clazz->name; } $definition['arguments'][] = $argument; } return $definition; }
/** * Parse the phpDoc of the method under test * and save the parsed doc node object to a * member variable. * * @return void */ private function initParameterInformation() { $this->loadMethodAnnotations(); $this->params = $this->filterParams(); $paramArray = $this->reflectionMethod->getParameters(); // @TODO (ryang 8/12/14) : more validation of parameters to make sure the phpdoc matches the code. $count = count($this->params); if ($count !== count($paramArray)) { $msg = sprintf("Number of parameters in PHPDoc for Method name ( %s ) doesn't match the code.", $this->reflectionMethod->getName()); App::writeln($msg); } $isConstructor = $this->reflectionMethod->isConstructor(); if ($isConstructor) { $this->returnType = new PHPDocVoidType(); } else { $returnTypeAnnotation = $this->filterReturnType(); if ($returnTypeAnnotation) { $docString = $returnTypeAnnotation->value(); $this->returnType = $this->parsePHPDocString($docString, 'return value'); } else { $warningMsg = sprintf("Method ( %s ) of the class ( %s ) " . "doesn't have the return type specified in its PHPDoc." . "\nAssume mixed return type.", $this->getName(), $this->inClass->getPhpClassName()->getFullyQualifiedClassName()); App::writeln($warningMsg); $this->returnType = new PHPDocMixedType(); } } }
/** * @param RouteCollection $router * @param \ReflectionClass $class * @param \ReflectionMethod $method * @param mixed $docblock */ protected function registerRoute(RouteCollection $router, \ReflectionClass $class, \ReflectionMethod $method, $docblock) { if ($docblock instanceof Route) { $this->addVersionToRoute($docblock); $router->addRoute($docblock->method, $docblock->path, '\\' . $class->getName() . '::' . $method->getName()); } }
/** * */ public function setRoute() { $segments = $this->getSegments(); $this->moduleName = isset($segments[0]) ? $segments[0] : self::DEFAULT_MODULE; $this->controllerName = isset($segments[1]) ? $segments[1] : self::DEFAULT_CONTROLLER; $this->methodName = isset($segments[2]) ? $segments[2] : self::DEFAULT_METHOD; $className = sprintf('%s\\Controller\\%s\\%s\\%s', $GLOBALS['appNameSpace'], ucwords($this->moduleName), ucwords($this->controllerName), ucwords($this->methodName)); if (class_exists($className)) { if (method_exists($className, self::FUNCTIONNAME)) { $method = new \ReflectionMethod($className, self::FUNCTIONNAME); if ($method->isPublic() && $method->getName() === self::FUNCTIONNAME) { $this->controller = new $className(); return true; } } } //退到/module/index.php $this->methodName = self::DEFAULT_METHOD; $this->controllerName = self::DEFAULT_CONTROLLER; $className = sprintf('%s\\Controller\\%s\\%s', $GLOBALS['appNameSpace'], ucwords($this->moduleName), ucwords($this->controllerName)); if (class_exists($className) && method_exists($className, self::FUNCTIONNAME)) { $this->controller = new $className(); return true; } $this->moduleName = self::DEFAULT_MODULE; $className = sprintf('%s\\Controller\\%s', $GLOBALS['appNameSpace'], ucwords($this->moduleName)); if (class_exists($className) && method_exists($className, self::FUNCTIONNAME)) { $this->controller = new $className(); return true; } if (is_null($this->controller)) { throw new \BadMethodCallException('wrong route path', -1); } }
/** * @param mixed $nodes * @return bool */ private function callsFuncGetArgs($nodes) : bool { foreach ($nodes as $node) { if (is_array($node)) { if ($this->callsFuncGetArgs($node)) { return true; } } if (!$node instanceof \PhpParser\Node) { continue; } if ($node instanceof \PhpParser\Node\Stmt\ClassLike && isset($node->namespacedName) && $this->declaringClass->getName() !== (string) $node->namespacedName) { continue; } if ($node instanceof ClassMethod) { if ($node->getStmts() === null) { continue; // interface } $methodName = $node->name; if ($methodName === $this->reflection->getName()) { return $this->functionCallStatementFinder->findFunctionCallInStatements(ParametersAcceptor::VARIADIC_FUNCTIONS, $node->getStmts()) !== null; } continue; } if ($this->callsFuncGetArgs($node)) { return true; } } return false; }
protected function configureRoute(\Symfony\Component\Routing\Route $route, \ReflectionClass $class, \ReflectionMethod $method, $annot) { // defines the controller $route->setDefault('_controller', $class->getName() . '::' . $method->getName()); // verify the other callbacks $options = $annot->getOptions(); foreach ($options as $prop => &$values) { if (!in_array($prop, array('_after_middlewares', '_before_middlewares', '_converters'))) { continue; } if (empty($values)) { continue; } foreach ($values as &$value) { if (is_string($value) && $class->hasMethod($value)) { // call static method from class $value = array($class->getName(), $value); } } unset($value); // clear reference } unset($values); $route->setOptions($options); }