-
Notifications
You must be signed in to change notification settings - Fork 11
/
GeneratedRESTModelControllerLoader.php
68 lines (57 loc) · 1.86 KB
/
GeneratedRESTModelControllerLoader.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
58
59
60
61
62
63
64
65
66
67
68
<?php
namespace MABI;
include_once __DIR__ . '/ControllerLoader.php';
include_once __DIR__ . '/RESTModelController.php';
/**
* automatically generates RESTful controllers
* GET /<model> get all models by id
* POST /<model> creates a new model
* PUT /<model> bulk creates full model collection
* DELETE /<model> deletes all models
* GET /<model>/<id> gets one model's full details
* PUT /<model>/<id> updates the model
* DELETE /<model>/<id> deletes the model
*
* These functions will be restricted by AccessControl
*/
class GeneratedRESTModelControllerLoader extends ControllerLoader {
/**
* @var \MABI\Extension
*/
protected $extension;
/**
* @var string[]
*/
protected $modelClasses;
/**
* @var \MABI\Controller[]
*/
protected $controllers = array();
public function __construct($modelClasses, $extension) {
$this->extension = $extension;
$this->modelClasses = $modelClasses;
foreach ($this->modelClasses as $modelClass) {
$rClass = new \ReflectionClass($modelClass);
$properties = ReflectionHelper::getDocDirective($rClass->getDocComment(), 'model');
if (!in_array('NoController', $properties)) {
/**
* @var $controller Controller
*/
$controller = RESTModelController::generate($modelClass, $this->extension);
// Load the middleware that's specified in the Model
$middlewares = ReflectionHelper::getDocDirective($rClass->getDocComment(), 'middleware');
foreach ($middlewares as $middlewareClass) {
$controller->addMiddlewareByClass($middlewareClass);
}
$this->controllers[] = $controller;
}
}
}
/**
* @return Controller[]
*/
function getControllers() {
// TODO: Implement getControllers() method.
return $this->controllers;
}
}