Passed
Push — master ( ba7917...6c027d )
by Jean-Christophe
06:26
created

RestController::add()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 2
ccs 0
cts 2
cp 0
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 2
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 implements HasResourceInterface {
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 the sql Where part
42
	 * @param boolean|string $included if true, loads associate members with associations, if string, example : client.*,commands
43
	 * @param boolean $useCache
44
	 *
45
	 */
46 1
	public function get($condition = "1=1", $included = false, $useCache = false) {
47 1
		$this->_get ( $condition, $included, $useCache );
48 1
	}
49
50
	/**
51
	 * Get the first object corresponding to the $keyValues
52
	 *
53
	 * @param string $keyValues primary key(s) value(s) or condition
54
	 * @param boolean|string $included if true, loads associate members with associations, if string, example : client.*,commands
55
	 * @param boolean $useCache if true then response is cached
56
	 */
57 1
	public function getOne($keyValues, $included = false, $useCache = false) {
58 1
		$this->_getOne ( $keyValues, $included, $useCache );
59 1
	}
60
61
	/**
62
	 * Update an instance of $model selected by the primary key $keyValues
63
	 * Require members values in $_POST array
64
	 * Requires an authorization with access token
65
	 *
66
	 * @param array $keyValues
67
	 * @authorization
68
	 */
69
	public function update(...$keyValues) {
70
		$this->_update ( $keyValues );
71
	}
72
73
	/**
74
	 * Insert a new instance of $model
75
	 * Require members values in $_POST array
76
	 * Requires an authorization with access token
77
	 *
78
	 * @authorization
79
	 */
80
	public function add() {
81
		$this->_add ();
82
	}
83
84
	/**
85
	 * Delete the instance of $model selected by the primary key $keyValues
86
	 * Requires an authorization with access token
87
	 *
88
	 * @param array $keyValues
89
	 * @route("methods"=>["delete"],"priority"=>30)
90
	 * @authorization
91
	 */
92
	public function delete(...$keyValues) {
93
		$this->_delete ( $keyValues );
94
	}
95
}
96