Passed
Push — master ( 55710c...55bc39 )
by Jean-Christophe
06:21
created

RestController::initialize()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 9
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 3.1406

Importance

Changes 0
Metric Value
eloc 7
dl 0
loc 9
ccs 6
cts 8
cp 0.75
rs 10
c 0
b 0
f 0
cc 3
nc 4
nop 0
crap 3.1406
1
<?php
2
3
namespace Ubiquity\controllers\rest;
4
5
use Ubiquity\cache\CacheManager;
6
use Ubiquity\orm\DAO;
7
8
/**
9
 * Abstract base class for Rest controllers.
10
 * Ubiquity\controllers\rest$RestController
11
 * This class is part of Ubiquity
12
 *
13
 * @author jcheron <[email protected]>
14
 * @version 1.0.4
15
 *
16
 */
17
abstract class RestController extends RestBaseController {
18
19 1
	public function initialize() {
20 1
		$thisClass = \get_class ( $this );
21 1
		if (! isset ( $this->model ))
22 1
			$this->model = CacheManager::getRestResource ( $thisClass );
23 1
		if (! isset ( $this->model )) {
24
			$modelsNS = $this->config ["mvcNS"] ["models"];
25
			$this->model = $modelsNS . "\\" . $this->_getResponseFormatter ()->getModel ( $thisClass );
26
		}
27 1
		parent::initialize ();
28 1
	}
29
30
	/**
31
	 * Returns all objects for the resource $model
32
	 */
33
	public function _index() {
34
		$datas = DAO::getAll ( $this->model );
35
		echo $this->_getResponseFormatter ()->get ( $datas );
36
	}
37
38
	/**
39
	 * Returns a list of objects from the server
40
	 *
41
	 * @param string $condition
42
	 *        	the sql Where part
43
	 * @param boolean|string $included
44
	 *        	if true, loads associate members with associations, if string, example : client.*,commands
45
	 * @param boolean $useCache
46
	 */
47 1
	public function get($condition = "1=1", $included = false, $useCache = false) {
48 1
		$this->_get ( $condition, $included, $useCache );
49 1
	}
50
51
	/**
52
	 * Get the first object corresponding to the $keyValues
53
	 *
54
	 * @param string $keyValues
55
	 *        	primary key(s) value(s) or condition
56
	 * @param boolean|string $included
57
	 *        	if true, loads associate members with associations, if string, example : client.*,commands
58
	 * @param boolean $useCache
59
	 *        	if true then response is cached
60
	 */
61 1
	public function getOne($keyValues, $included = false, $useCache = false) {
62 1
		$this->_getOne ( $keyValues, $included, $useCache );
63 1
	}
64
65
	/**
66
	 * Update an instance of $model selected by the primary key $keyValues
67
	 * Require members values in $_POST array
68
	 * Requires an authorization with access token
69
	 *
70
	 * @param array $keyValues
71
	 * @authorization
72
	 */
73
	public function update(...$keyValues) {
74
		$this->_update ( $keyValues );
75
	}
76
77
	/**
78
	 * Insert a new instance of $model
79
	 * Require members values in $_POST array
80
	 * Requires an authorization with access token
81
	 *
82
	 * @authorization
83
	 */
84
	public function add() {
85
		$this->_add ();
86
	}
87
88
	/**
89
	 * Delete the instance of $model selected by the primary key $keyValues
90
	 * Requires an authorization with access token
91
	 *
92
	 * @param array $keyValues
93
	 * @route("methods"=>["delete"],"priority"=>30)
94
	 * @authorization
95
	 */
96
	public function delete(...$keyValues) {
97
		$this->_delete ( $keyValues );
98
	}
99
}
100