ClientAbstract.php
1.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
<?php
namespace Zendesk\API;
/**
* Abstract class for all endpoints
* @package Zendesk\API
*/
abstract class ClientAbstract
{
/**
* @var Client
*/
protected $client;
/**
* @var int
*/
protected $lastId;
/**
* @param Client $client
*/
public function __construct(Client $client)
{
$this->client = $client;
}
/**
* Saves an id for future methods in the chain
*
* @param int $id
*
* @return $this
*/
public function setLastId($id)
{
$this->lastId = $id;
return $this;
}
/**
* Saves an id for future methods in the chain
*
* @return int
*/
public function getLastId()
{
return $this->lastId;
}
/**
* Check that all parameters have been supplied
*
* @param array $params
* @param array $mandatory
*
* @return bool
*/
public function hasKeys(array $params, array $mandatory)
{
for ($i = 0; $i < count($mandatory); $i++) {
if (!array_key_exists($mandatory[$i], $params)) {
return false;
}
}
return true;
}
/**
* Check that any parameter has been supplied
*
* @param array $params
* @param array $mandatory
*
* @return bool
*/
public function hasAnyKey(array $params, array $mandatory)
{
for ($i = 0; $i < count($mandatory); $i++) {
if (array_key_exists($mandatory[$i], $params)) {
return true;
}
}
return false;
}
/**
* Enable side-loading (beta) - flags until the next chain
*
* @param array $fields
*
* @return $this
*/
public function sideload(array $fields = array())
{
$this->client->setSideload($fields);
return $this;
}
}