Completed
Push — master ( 1f65a3...0feaa6 )
by Jean-Christophe
01:28
created

RestControllerParser::parse()   B

Complexity

Conditions 6
Paths 5

Size

Total Lines 19
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 19
rs 8.8571
cc 6
eloc 14
nc 5
nop 2
1
<?php
2
3
namespace micro\cache\parser;
4
5
use micro\orm\parser\Reflexion;
6
use micro\cache\ClassUtils;
7
8
class RestControllerParser {
9
	private $controllerClass;
10
	private $resource;
11
	private $rest;
12
	private $authorizationMethods;
13
14
	public function __construct(){
15
		$this->rest=false;
16
		$this->authorizationMethods=[];
17
	}
18
	public function parse($controllerClass,$config) {
19
		$this->controllerClass=$controllerClass;
20
		$reflect=new \ReflectionClass($controllerClass);
21
		if (!$reflect->isAbstract() && $reflect->isSubclassOf("micro\\controllers\\rest\\RestController")) {
22
			$restAnnotsClass=Reflexion::getAnnotationClass($controllerClass, "@rest");
23
			if (\sizeof($restAnnotsClass) > 0){
24
				$modelsNS=$config["mvcNS"]["models"];
25
				$this->resource=$modelsNS."\\".$restAnnotsClass[0]->resource;
26
				$this->rest=true;
27
				$methods=Reflexion::getMethods($controllerClass, \ReflectionMethod::IS_PUBLIC);
28
				foreach ( $methods as $method ) {
29
					$annots=Reflexion::getAnnotationsMethod($controllerClass, $method->name, "@authorization");
30
					if($annots!==false){
31
						$this->authorizationMethods[]=$method->name;
32
					}
33
				}
34
			}
35
		}
36
	}
37
38
	public function asArray() {
39
		return [ClassUtils::cleanClassname($this->controllerClass)=>["resource"=>ClassUtils::cleanClassname($this->resource),"authorizations"=>$this->authorizationMethods]];
40
	}
41
42
	public function isRest() {
43
		return $this->rest;
44
	}
45
46
}
47