also looking at this
Media model
#6
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.
| @@ -4,12 +4,9 @@ namespace Meema\MeemaApi\Models; | ||
| 4 | 4 | |
| 5 | 5 | use Meema\MeemaApi\Client; |
| 6 | 6 | use Meema\MeemaApi\Response\Response; |
| 7 | use Meema\MeemaApi\Traits\SerializesResponse; | |
| 8 | 7 | |
| 9 | 8 | class Folder |
| 10 | 9 | { |
| 11 | use SerializesResponse; | |
| 12 | ||
| 13 | 10 | /** |
| 14 | 11 | * @var Meema\MeemaApi\Client |
| 15 | 12 | */ |
| @@ -182,18 +179,6 @@ class Folder | ||
| 182 | 179 | return $this->client->request('POST', "folders/{$id}/duplicate"); |
| 183 | 180 | } |
| 184 | 181 | |
| 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 | ||
| 197 | 182 | /** |
| 198 | 183 | * Add folder to media. |
| 199 | 184 | * |
| @@ -223,7 +208,7 @@ class Folder | ||
| 223 | 208 | * |
| 224 | 209 | * @param Meema\MeemaApi\Models\Media $media |
| 225 | 210 | * |
| 226 | * @return void | |
| 211 | * @return self | |
| 227 | 212 | */ |
| 228 | 213 | public function setMedia($media): self |
| 229 | 214 | { |
| @@ -231,4 +216,26 @@ class Folder | ||
| 231 | 216 | |
| 232 | 217 | return $this; |
| 233 | 218 | } |
| 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 | } | |
| 234 | 241 | } |
| @@ -18,9 +18,9 @@ class Media | ||
| 18 | 18 | protected $id; |
| 19 | 19 | |
| 20 | 20 | /** |
| 21 | * @var int | |
| 21 | * @var object | |
| 22 | 22 | */ |
| 23 | protected $folderId; | |
| 23 | protected $model; | |
| 24 | 24 | |
| 25 | 25 | /** |
| 26 | 26 | * @var array |
| @@ -32,11 +32,9 @@ class Media | ||
| 32 | 32 | * |
| 33 | 33 | * @param Meema\MeemaApi\Client $client |
| 34 | 34 | */ |
| 35 | public function __construct(Client $client, $folderId = null) | |
| 35 | public function __construct(Client $client) | |
| 36 | 36 | { |
| 37 | 37 | $this->client = $client; |
| 38 | ||
| 39 | $this->folderId = $folderId; | |
| 40 | 38 | } |
| 41 | 39 | |
| 42 | 40 | /** |
| @@ -56,8 +54,8 @@ class Media | ||
| 56 | 54 | */ |
| 57 | 55 | public function get($id = null) |
| 58 | 56 | { |
| 59 | if ($this->folderId) { | |
| 60 | return $this->fetchMediaForFolder($this->folderId); | |
| 57 | if ($this->model) { | |
| 58 | return $this->fetchMediaForFolder($this->model->getId()); | |
| 61 | 59 | } |
| 62 | 60 | |
| 63 | 61 | if (! $id) { |
| @@ -195,8 +193,7 @@ class Media | ||
| 195 | 193 | { |
| 196 | 194 | $client = new Client($this->client->getAccessKey()); |
| 197 | 195 | |
| 198 | return (new Folder($client)) | |
| 199 | ->setMedia($this); | |
| 196 | return (new Folder($client))->setMedia($this); | |
| 200 | 197 | } |
| 201 | 198 | |
| 202 | 199 | /** |
| @@ -211,6 +208,25 @@ class Media | ||
| 211 | 208 | return $this->client->request('GET', "folders/{$id}/media"); |
| 212 | 209 | } |
| 213 | 210 | |
| 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 | */ | |
| 214 | 230 | public function getId() |
| 215 | 231 | { |
| 216 | 232 | return $this->id; |