/
RouteAnnotation.class.php
57 lines (45 loc) · 1.66 KB
/
RouteAnnotation.class.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
<?php
Library::import('recess.lang.Annotation');
Library::import('recess.framework.routing.Route');
class RouteAnnotation extends Annotation {
const EMPTY_PATH = ' ';
protected $httpMethods = array();
protected $path = self::EMPTY_PATH;
public function usage() {
return '!Route ( GET | POST | PUT | DELETE)[, route/path/here]';
}
public function isFor() {
return Annotation::FOR_METHOD;
}
protected function validate($class) {
$this->minimumParameterCount(1);
$this->maximumParameterCount(2);
$this->validOnSubclassesOf($class, Controller::CLASSNAME);
$this->acceptedIndexedValues(0, array(Methods::GET, Methods::POST, Methods::PUT, Methods::DELETE));
}
protected function expand($class, $reflection, $descriptor) {
if(is_array($this->values[0])) {
$this->httpMethods = $this->values[0];
} else {
$this->httpMethods = array($this->values[0]);
}
if(isset($this->values[1])) {
$this->path = $this->values[1];
}
$controller = Library::getFullyQualifiedClassName($class);
$controllerMethod = $reflection->getName();
if(strpos($this->path, Library::pathSeparator)===0) {
// Absolute Route
$route = new Route($controller, $controllerMethod, $this->httpMethods, $this->path);
$descriptor->methodUrls[$controllerMethod] = $this->path;
} else {
// Relative Route
$route = new Route($controller, $controllerMethod, $this->httpMethods, $descriptor->routesPrefix . $this->path);
$descriptor->methodUrls[$controllerMethod] = $descriptor->routesPrefix . $this->path;
}
$route->fileDefined = $reflection->getFileName();
$route->lineDefined = $reflection->getStartLine();
$descriptor->routes[] = $route;
}
}
?>