1 | <?php |
||
9 | class Client |
||
10 | { |
||
11 | /** |
||
12 | * @var array; |
||
13 | */ |
||
14 | protected $definitions = []; |
||
15 | /** |
||
16 | * @var string |
||
17 | */ |
||
18 | protected $key; |
||
19 | /** |
||
20 | * @var array |
||
21 | */ |
||
22 | protected $manipulations; |
||
23 | /** |
||
24 | * @var string |
||
25 | */ |
||
26 | protected $url; |
||
27 | /** |
||
28 | * @var array |
||
29 | */ |
||
30 | private $config; |
||
31 | |||
32 | /** |
||
33 | * Client constructor. |
||
34 | * |
||
35 | * @param $config |
||
36 | */ |
||
37 | 13 | public function __construct($config) |
|
41 | |||
42 | /** |
||
43 | * Check if a predefined manipulation set need to be called. |
||
44 | * |
||
45 | * @param string $method |
||
46 | * @param array $arguments |
||
47 | * @return $this |
||
48 | */ |
||
49 | 3 | public function __call($method, $arguments) |
|
62 | |||
63 | /** |
||
64 | * Make a circle of the image with the given radius. |
||
65 | * |
||
66 | * @param string $radius |
||
67 | * @return $this |
||
68 | */ |
||
69 | 2 | public function circle($radius = 'max') |
|
75 | |||
76 | /** |
||
77 | * Define a predefined set of manipulations. |
||
78 | * |
||
79 | * @param string $key |
||
80 | * @param Closure $callback |
||
81 | * @return $this |
||
82 | */ |
||
83 | 2 | public function define($key, Closure $callback) |
|
89 | |||
90 | /** |
||
91 | * Let the client fetch the given url as image. |
||
92 | * |
||
93 | * @param string $url |
||
94 | * @return $this |
||
95 | */ |
||
96 | 13 | public function fetch($url) |
|
102 | |||
103 | /** |
||
104 | * Fit the image when resizing it. |
||
105 | * |
||
106 | * @param null|string $gravity |
||
107 | * @return $this |
||
108 | */ |
||
109 | 5 | public function fit($gravity = null) |
|
119 | |||
120 | /** |
||
121 | * Set the desired height of the image. |
||
122 | * |
||
123 | * @param int $height |
||
124 | * @return $this |
||
125 | */ |
||
126 | 2 | public function height($height) |
|
132 | |||
133 | /** |
||
134 | * Retrieve the imaginary url. |
||
135 | * |
||
136 | * @return string |
||
137 | * @throws InvalidConfigException |
||
138 | */ |
||
139 | 12 | public function url() |
|
158 | |||
159 | /** |
||
160 | * Get the resource key. |
||
161 | * We currently only support image. |
||
162 | * |
||
163 | * @return string |
||
164 | */ |
||
165 | 10 | protected function getResourceKey() |
|
169 | |||
170 | /** |
||
171 | * Get the type key. |
||
172 | * We only support fetch at the moment. |
||
173 | * |
||
174 | * @return string |
||
175 | */ |
||
176 | 10 | protected function getTypeKey() |
|
180 | |||
181 | /** |
||
182 | * Get the string representation of all manipulations that |
||
183 | * need to be executed on the given resource. |
||
184 | * |
||
185 | * @return string|null |
||
186 | */ |
||
187 | public function getManipulations() |
||
195 | |||
196 | /** |
||
197 | * Set the desired width of the image. |
||
198 | * |
||
199 | * @param int $width |
||
200 | * @return $this |
||
201 | */ |
||
202 | 5 | public function width($width) |
|
208 | |||
209 | /** |
||
210 | * Return the url for this image. |
||
211 | * |
||
212 | * @return string |
||
213 | */ |
||
214 | 1 | public function __toString() |
|
218 | } |