ReviewOS

also looking at this

meemalabs/meema-client-php

Media model

#6
Merged glennmichael123 wants to merge media-model into main
7 files +1700 -76

Review threads live on the whole diff, not on one commit, so none are shown here - a thread's line means something in the branch's final form, and painting it into an intermediate step would put it on code it is not about.

src/Models/Folder.phpmodified+23-16
Changes to src/Models/Folder.php
@@ -4,12 +4,9 @@ namespace Meema\MeemaApi\Models;
44
55use Meema\MeemaApi\Client;
66use Meema\MeemaApi\Response\Response;
7use Meema\MeemaApi\Traits\SerializesResponse;
87
98class Folder
109{
11 use SerializesResponse;
12
1310 /**
1411 * @var Meema\MeemaApi\Client
1512 */
@@ -182,18 +179,6 @@ class Folder
182179 return $this->client->request('POST', "folders/{$id}/duplicate");
183180 }
184181
185 /**
186 * Initialize the media model.
187 *
188 * @return Meema\MeemaApi\Models\Media
189 */
190 public function media(): Media
191 {
192 $client = new Client($this->client->getAccessKey());
193
194 return new Media($client, $this->id);
195 }
196
197182 /**
198183 * Add folder to media.
199184 *
@@ -223,7 +208,7 @@ class Folder
223208 *
224209 * @param Meema\MeemaApi\Models\Media $media
225210 *
226 * @return void
211 * @return self
227212 */
228213 public function setMedia($media): self
229214 {
@@ -231,4 +216,26 @@ class Folder
231216
232217 return $this;
233218 }
219
220 /**
221 * Get the protected id
222 *
223 * @return int
224 */
225 public function getId()
226 {
227 return $this->id;
228 }
229
230 /**
231 * Initialize the media model.
232 *
233 * @return Meema\MeemaApi\Models\Media
234 */
235 public function media(): Media
236 {
237 $client = new Client($this->client->getAccessKey());
238
239 return (new Media($client))->setFolder($this);
240 }
234241}
src/Models/Media.phpmodified+25-9
Changes to src/Models/Media.php
@@ -18,9 +18,9 @@ class Media
1818 protected $id;
1919
2020 /**
21 * @var int
21 * @var object
2222 */
23 protected $folderId;
23 protected $model;
2424
2525 /**
2626 * @var array
@@ -32,11 +32,9 @@ class Media
3232 *
3333 * @param Meema\MeemaApi\Client $client
3434 */
35 public function __construct(Client $client, $folderId = null)
35 public function __construct(Client $client)
3636 {
3737 $this->client = $client;
38
39 $this->folderId = $folderId;
4038 }
4139
4240 /**
@@ -56,8 +54,8 @@ class Media
5654 */
5755 public function get($id = null)
5856 {
59 if ($this->folderId) {
60 return $this->fetchMediaForFolder($this->folderId);
57 if ($this->model) {
58 return $this->fetchMediaForFolder($this->model->getId());
6159 }
6260
6361 if (! $id) {
@@ -195,8 +193,7 @@ class Media
195193 {
196194 $client = new Client($this->client->getAccessKey());
197195
198 return (new Folder($client))
199 ->setMedia($this);
196 return (new Folder($client))->setMedia($this);
200197 }
201198
202199 /**
@@ -211,6 +208,25 @@ class Media
211208 return $this->client->request('GET', "folders/{$id}/media");
212209 }
213210
211 /**
212 * Initialize media model.
213 *
214 * @param Meema\MeemaApi\Models\Folder $folder
215 *
216 * @return self
217 */
218 public function setFolder($folder): self
219 {
220 $this->model = $folder;
221
222 return $this;
223 }
224
225 /**
226 * Get the protected id
227 *
228 * @return int
229 */
214230 public function getId()
215231 {
216232 return $this->id;