aboutsummaryrefslogtreecommitdiff
path: root/lib/classes/JsonApi/Schemas/StockImage.php
blob: e28582c5c99a5554f283a0d0d0b4452f187380c8 (plain)
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
<?php

namespace JsonApi\Schemas;

use JsonApi\Schemas\SchemaProvider;
use Neomerx\JsonApi\Contracts\Schema\ContextInterface;
use Neomerx\JsonApi\Schema\Link;
use Neomerx\JsonApi\Contracts\Schema\LinkInterface;

class StockImage extends SchemaProvider
{
    public const TYPE = 'stock-images';

    /**
     * {@inheritdoc}
     */
    public function getId($resource): ?string
    {
        return $resource->getId();
    }

    /**
     * {@inheritdoc}
     */
    public function getAttributes($resource, ContextInterface $context): iterable
    {
        return [
            'title' => $resource['title'],
            'description' => $resource['description'],
            'author' => $resource['author'],
            'license' => $resource['license'],
            'mime-type' => $resource['mime_type'],

            'download-urls' => $resource->getDownloadURLs(),

            'size' => (int) $resource['size'],
            'width' => (int) $resource['width'],
            'height' => (int) $resource['height'],
            'palette' => empty($resource['palette']) ? null : json_decode($resource['palette']),
            'tags' => empty($resource['tags']) ? [] : json_decode($resource['tags']),

            'mkdate' => date('c', $resource['mkdate']),
            'chdate' => date('c', $resource['chdate']),
        ];
    }

    /**
     * @SuppressWarnings(PHPMD.UnusedFormalParameter)
     */
    public function getRelationships($resource, ContextInterface $context): iterable
    {
        return [];
    }
}