Passed
Push — master ( 8a5846...f63d0b )
by Jean-Christophe
11:58
created

RestController::get()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

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