forked from prolificinteractive/mabi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathModelController.php
65 lines (51 loc) · 1.6 KB
/
ModelController.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
<?php
namespace MABI;
include_once __DIR__ . '/Utilities.php';
include_once __DIR__ . '/Controller.php';
/**
* todo: docs
*/
class ModelController extends Controller {
protected $modelClass = NULL;
/**
* @endpoint ignore
* @return string
*/
public function getModelClass() {
return $this->modelClass;
}
/**
* @param $extension Extension
*/
public function __construct($extension) {
if (empty($this->modelClass)) {
$this->modelClass = ReflectionHelper::getPrefixFromControllerClass(get_called_class());
}
if (empty($this->base)) {
$this->base = Inflector::pluralize(strtolower(ReflectionHelper::stripClassName($this->modelClass)));
}
parent::__construct($extension);
}
public static function generate($modelClass, $extension) {
$calledClass = get_called_class();
$newController = new $calledClass($extension);
$newController->modelClass = $modelClass;
$newController->base = Inflector::pluralize(strtolower(ReflectionHelper::stripClassName($modelClass)));
return $newController;
}
public function getDocJSON(Parser $parser) {
$doc = parent::getDocJSON($parser);
$rClass = new \ReflectionClass(get_called_class());
if (in_array('show-model', ReflectionHelper::getDocDirective($rClass->getDocComment(), 'docs'))) {
/**
* @var $model \MABI\Model
*/
$model = call_user_func($this->modelClass . '::init', $this->getApp());
if (empty($doc['models'])) {
$doc['models'] = array();
}
array_unshift($doc['models'], $model->getDocOutput($parser));
}
return $doc;
}
}