Ubiquity 2.5.2
php rapid development framework
Loading...
Searching...
No Matches
RestControllerParser.php
Go to the documentation of this file.
1<?php
2
4
8
19 private $resource;
20 private $route;
21 private $rest;
23
24 public function __construct() {
25 $this->rest = false;
26 $this->authorizationMethods = [ ];
27 }
28
29 public function parse($controllerClass, $config) {
30 $this->controllerClass = $controllerClass;
31 $reflect = new \ReflectionClass ( $controllerClass );
32 if (! $reflect->isAbstract () && $reflect->isSubclassOf ( RestBaseController::class )) {
33 $restAnnotsClass = Reflexion::getAnnotationClass ( $controllerClass, "rest" );
34 if (\count ( $restAnnotsClass ) > 0) {
35 $routeAnnotsClass = Reflexion::getAnnotationClass ( $controllerClass, "route" );
36 if (\count ( $routeAnnotsClass ) > 0) {
37 $this->route = $routeAnnotsClass [0]->path;
38 }
39 $this->resource = $this->_getResourceName ( $config, $restAnnotsClass [0]->resource );
40 $this->rest = true;
41 $methods = Reflexion::getMethods ( $controllerClass, \ReflectionMethod::IS_PUBLIC );
42 foreach ( $methods as $method ) {
43 $annots = Reflexion::getAnnotationsMethod ( $controllerClass, $method->name, "authorization" );
44 if ($annots !== false) {
45 $this->authorizationMethods [] = $method->name;
46 }
47 }
48 }
49 }
50 }
51
52 private function _getResourceName($config, $name) {
53 if ($name != null) {
54 $modelsNS = $config ["mvcNS"] ["models"];
55 return ClassUtils::getClassNameWithNS ( $modelsNS, $name );
56 }
57 return '';
58 }
59
60 public function asArray() {
61 return [ $this->controllerClass => [ "resource" => $this->resource,"authorizations" => $this->authorizationMethods,"route" => $this->route ] ];
62 }
63
64 public function isRest() {
65 return $this->rest;
66 }
67}
Manipulates class and namespace names Ubiquity\cache$ClassUtils This class is part of Ubiquity.
static getClassNameWithNS($defaultNS, $name)
Returns the complete name of a class.
Ubiquity\cache\parser$RestControllerParser This class is part of Ubiquity.
Abstract base class for Rest controllers.
Reflection utilities in dev environment only.
Definition Reflexion.php:17