Exemple #1
0
 /**
  * @param array $annotationClassesByName
  */
 public function registerCustomAnnotations($annotationClassesByName)
 {
     $manager = Annotations::getManager();
     foreach (array_keys($annotationClassesByName) as $name) {
         $manager->registry[$name] = $annotationClassesByName[$name];
     }
 }
 public static function register()
 {
     $manager = Annotations::getManager();
     $manager->registry['get'] = Get::class;
     $manager->registry['post'] = Post::class;
     $manager->registry['delete'] = Delete::class;
     $manager->registry['controller'] = Controller::class;
 }
Exemple #3
0
 public function __construct()
 {
     Annotations::$config['cache'] = false;
     $annotationManager = Annotations::getManager();
     $annotationManager->registry['assert'] = 'Phprtest\\Annotations\\AssertAnnotation';
     $annotationManager->registry['provider'] = 'Phprtest\\Annotations\\ProviderAnnotation';
     $annotationManager->registry['repeat'] = 'Phprtest\\Annotations\\RepeatAnnotation';
     $this->setAnnotations($annotationManager);
     $this->setPrinter(new ConsolePrinter());
     $this->setProfiler(new Profiler(true));
 }
 /**
  * @param RequestContext $requestContext
  * @param InterceptorStack $stack
  * @return Result
  */
 public function intercept(RequestContext $requestContext, InterceptorStack $stack)
 {
     $annotations = Annotations::ofClass($requestContext->controllerMethod->getDeclaringClass(), PublicAccess::class);
     $isPublic = count($annotations) > 0;
     if ($isPublic) {
         return $stack->next();
     }
     if (key_exists('loggedInUser', $_SESSION)) {
         $requestContext->inject('loggedInUser', $_SESSION['loggedInUser']);
         return $stack->next();
     }
     return Results::http('Unauthorized', 401);
 }
 /**
  * @param \ReflectionMethod $method
  * @param string $controllerPath
  * @throws RouterConfigurationException
  */
 private function configureControllerMethod(\ReflectionMethod $method, $controllerPath)
 {
     /** @var HttpVerb $httpVerbAnnotation */
     $httpVerbAnnotation = null;
     $annotations = Annotations::ofMethod($method);
     foreach ($annotations as $annotation) {
         if (in_array(get_class($annotation), $this->httpVerbsAnnotations)) {
             $httpVerbAnnotation = $annotation;
             break;
         }
     }
     if ($httpVerbAnnotation === null) {
         return;
     }
     $methodPath = $httpVerbAnnotation->path;
     $fullPath = $this->basePath . $controllerPath . $methodPath;
     $methodFullName = $method->getDeclaringClass()->getName() . '::' . $method->getName();
     $httpVerb = $this->httpVerbsByAnnotations[get_class($httpVerbAnnotation)];
     $this->routeCollector->addRoute($httpVerb, $fullPath, $methodFullName);
 }
 public function testMalformedParamAnnotationThrowsException()
 {
     $this->setExpectedException(self::ANNOTATION_EXCEPTION, 'ParamAnnotation requires a type property');
     Annotations::ofMethod('BrokenParamAnnotationClass', 'brokenParamAnnotation');
 }
Exemple #7
0
 private function getMetadata($property, $type, $name, $default = null)
 {
     $a = Annotations::ofProperty(get_class($this->object), $property, $type);
     if (!count($a)) {
         return $default;
     }
     return $a[0]->{$name};
 }