1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Waredesk; |
4
|
|
|
|
5
|
|
|
use Waredesk\Mappers\VariableMapper; |
6
|
|
|
use Waredesk\Mappers\VariablesMapper; |
7
|
|
|
use Waredesk\Models\Variable; |
8
|
|
|
|
9
|
|
|
class Variables extends Controller |
10
|
|
|
{ |
11
|
|
|
private const ENDPOINT = '/v1-alpha/variables'; |
12
|
|
|
|
13
|
1 |
|
public function create(Variable $variable): Variable |
14
|
|
|
{ |
15
|
1 |
|
return $this->doCreate( |
16
|
1 |
|
self::ENDPOINT, |
17
|
|
|
$variable, |
18
|
|
|
function ($response) use ($variable) { |
19
|
1 |
|
return (new VariableMapper())->map($variable, $response); |
20
|
1 |
|
} |
21
|
|
|
); |
22
|
|
|
} |
23
|
|
|
|
24
|
1 |
|
public function update(Variable $variable): Variable |
25
|
|
|
{ |
26
|
1 |
|
$this->validateIsNotNewEntity($variable->getId()); |
27
|
1 |
|
return $this->doUpdate( |
28
|
1 |
|
self::ENDPOINT."/{$variable->getId()}", |
29
|
|
|
$variable, |
30
|
|
|
function ($response) use ($variable) { |
31
|
1 |
|
return (new VariableMapper())->map($variable, $response); |
32
|
1 |
|
} |
33
|
|
|
); |
34
|
|
|
} |
35
|
|
|
|
36
|
1 |
|
public function delete(Variable $variable): bool |
37
|
|
|
{ |
38
|
1 |
|
$this->validateIsNotNewEntity($variable->getId()); |
39
|
1 |
|
return $this->doDelete(self::ENDPOINT."/{$variable->getId()}"); |
40
|
|
|
} |
41
|
|
|
|
42
|
1 |
|
public function fetch(string $orderBy = null, string $order = self::ORDER_BY_ASC, int $limit = null): Collections\Variables |
43
|
|
|
{ |
44
|
1 |
|
return $this->doFetch( |
45
|
1 |
|
self::ENDPOINT, |
46
|
|
|
$orderBy, |
47
|
|
|
$order, |
48
|
|
|
$limit, |
49
|
|
|
function ($response) { |
50
|
1 |
|
return (new VariablesMapper())->map(new Collections\Variables(), $response); |
51
|
1 |
|
} |
52
|
|
|
); |
53
|
|
|
} |
54
|
|
|
|
55
|
2 |
|
public function fetchOne(string $orderBy = null, string $order = self::ORDER_BY_ASC): ? Variable |
56
|
|
|
{ |
57
|
2 |
|
return $this->doFetchOne( |
58
|
2 |
|
self::ENDPOINT, |
59
|
|
|
$orderBy, |
60
|
|
|
$order, |
61
|
|
|
function ($response) { |
62
|
2 |
|
return (new VariablesMapper())->map(new Collections\Variables(), $response); |
63
|
2 |
|
} |
64
|
|
|
); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
public function findOneBy(array $criteria, string $orderBy = null, string $order = self::ORDER_BY_ASC): ? Variable |
68
|
|
|
{ |
69
|
|
|
return $this->doFindOneBy( |
70
|
|
|
self::ENDPOINT, |
71
|
|
|
$criteria, |
72
|
|
|
$orderBy, |
73
|
|
|
$order, |
74
|
|
|
function ($response) { |
75
|
|
|
return (new VariablesMapper())->map(new Collections\Variables(), $response); |
76
|
|
|
} |
77
|
|
|
); |
78
|
|
|
} |
79
|
|
|
} |
80
|
|
|
|