1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Copyright (c) 2019 - present |
4
|
|
|
* updown - CrudObject.php |
5
|
|
|
* author: Roberto Belotti - [email protected] |
6
|
|
|
* web : robertobelotti.com, github.com/biscolab |
7
|
|
|
* Initial version created on: 15/2/2019 |
8
|
|
|
* MIT license: https://github.com/biscolab/updown-php/blob/master/LICENSE |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
namespace Biscolab\UpDown\Objects; |
12
|
|
|
|
13
|
|
|
use Biscolab\UpDown\Abstracts\AbstractObject; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* Class CrudObject |
17
|
|
|
* @package Biscolab\UpDown\Objects |
18
|
|
|
*/ |
19
|
|
|
class CrudObject extends BaseObject |
20
|
|
|
{ |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* @param array|null $params |
24
|
|
|
* |
25
|
|
|
* @return AbstractObject |
26
|
|
|
*/ |
27
|
|
|
public function create(?array $params = []): AbstractObject |
28
|
|
|
{ |
29
|
|
|
|
30
|
|
|
if (empty($params)) { |
31
|
|
|
$params = $this->attributes; |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
$path = $this->prepareApiPath(false); |
35
|
|
|
|
36
|
|
|
$response = $this->updown->post($path, $params); |
|
|
|
|
37
|
|
|
|
38
|
|
|
$this->setArgs($response->getResult()->getData()); |
39
|
|
|
|
40
|
|
|
return $this; |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @return AbstractObject |
45
|
|
|
*/ |
46
|
|
|
public function read(): AbstractObject |
47
|
|
|
{ |
48
|
|
|
|
49
|
|
|
$path = $this->prepareApiPath(); |
50
|
|
|
|
51
|
|
|
$response = $this->updown->get($path); |
52
|
|
|
|
53
|
|
|
$this->setArgs($response->getResult()->getData()); |
54
|
|
|
|
55
|
|
|
return $this; |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* @param $params |
60
|
|
|
* |
61
|
|
|
* @return AbstractObject |
62
|
|
|
*/ |
63
|
|
|
public function update(?array $params = []): AbstractObject |
64
|
|
|
{ |
65
|
|
|
|
66
|
|
|
if (empty($params)) { |
67
|
|
|
$params = $this->attributes; |
68
|
|
|
$this->setArgs($params); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
$path = $this->prepareApiPath(); |
72
|
|
|
|
73
|
|
|
$response = $this->updown->put($path, $params); |
74
|
|
|
|
75
|
|
|
$this->setArgs($response->getResult()->getData()); |
76
|
|
|
|
77
|
|
|
return $this; |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* @return bool |
82
|
|
|
*/ |
83
|
|
|
public function delete(): bool |
84
|
|
|
{ |
85
|
|
|
|
86
|
|
|
$path = $this->prepareApiPath(); |
87
|
|
|
|
88
|
|
|
$response = $this->updown->delete($path); |
89
|
|
|
|
90
|
|
|
$result = $response->getResult()->getData(); |
91
|
|
|
|
92
|
|
|
if ($result['deleted']) { |
93
|
|
|
return $result['deleted']; |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
return false; |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
} |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.