protected function getName() { $serviceName = $this->reflClass->getName(); $component = $this->reflClass->getAnnotation(Component::class); if ($component && $component->name) { $serviceName = $component->name; } return $serviceName; }
/** * @param object|class $controller * @return string Name of matchig method */ public static function getMatchingMethod($controller) { $reflClass = new ReflectionClass($controller); $classAnnotation = $reflClass->getAnnotation(RequestMapping::class); $requestHelper = Helper::getService(HttpServletRequest::class); $pathInfo = $requestHelper->getServer(HttpServletRequest::PATH_INFO); if (!$pathInfo) { $pathInfo = $requestHelper->getServer(HttpServletRequest::REQUEST_URI); } /* @var $reflMethod ReflectionMethod */ foreach ($reflClass->getMethods(PHP_ReflectionMethod::IS_PUBLIC) as $reflMethod) { /* @var $methodAnnotation RequestMapping */ $methodAnnotation = $reflMethod->getAnnotation(RequestMapping::class); /* @var $requestHelper HttpServletRequest */ $url = ''; if ($classAnnotation) { $url .= $classAnnotation->value; } if ($methodAnnotation) { $url .= $methodAnnotation->value; } $regexp = '/^' . str_replace('/', '\\/', $url) . '/'; $test = preg_match($regexp, $pathInfo, $prop); $test &= $methodAnnotation !== null && self::isMatching($methodAnnotation); if ($url && $methodAnnotation && $test) { foreach ($prop as $key => $value) { if (!is_numeric($key)) { $requestHelper->setParam($key, $value); } } return $reflMethod->getName(); } } return null; }
private function getScope(ReflectionClass $reflClass) { $scope = Scope::SINGLETON; if ($reflClass->hasAnnotation(Component::class)) { $annotation = $reflClass->getAnnotation(Component::class); $scope = $annotation->scope; if ($reflClass->hasAnnotation(Scope::class)) { $annotation = $reflClass->getAnnotation(Scope::class); $scope = $annotation->value; } } /** * @todo Need more work */ switch ($scope) { case Scope::SINGLETON: case Scope::REQUEST: case Scope::SESSION: $scope = Scope::SINGLETON; break; default: $scope = Scope::PROTOTYPE; break; } return $scope; }
/** * @covers PhSpring\Reflection\ReflectionClass::getAnnotation */ public function testGetAnnotation() { $annotation = $this->object->getAnnotation(Controller::class); $this->assertInstanceOf(Controller::class, $annotation); }