ThumbnailsManager::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 5
rs 9.4286
cc 1
eloc 3
nc 1
nop 1
1
<?php namespace Modules\Media\Image;
2
3
use Illuminate\Contracts\Config\Repository;
4
5
class ThumbnailsManager
6
{
7
    /**
8
     * @var Module
9
     */
10
    private $module;
11
    /**
12
     * @var Repository
13
     */
14
    private $config;
15
16
    /**
17
     * @param Repository $config
18
     */
19
    public function __construct(Repository $config)
20
    {
21
        $this->module = app('modules');
22
        $this->config = $config;
23
    }
24
25
    /**
26
     * Return all thumbnails for all modules
27
     * @return array
28
     */
29
    public function all()
30
    {
31
        $thumbnails = [];
32
        foreach ($this->module->enabled() as $enabledModule) {
33
            $configuration = $this->config->get(strtolower('asgard.' . $enabledModule->getName()) . '.thumbnails');
34
            if (!is_null($configuration)) {
35
                $thumbnails = array_merge($thumbnails, Thumbnail::makeMultiple($configuration));
36
            }
37
        }
38
39
        return $thumbnails;
40
    }
41
42
    /**
43
     * Find the filters for the given thumbnail
44
     * @param $thumbnail
45
     * @return array
46
     */
47
    public function find($thumbnail)
48
    {
49
        foreach ($this->all() as $thumb) {
50
            if ($thumb->name() == $thumbnail) {
51
                return $thumb->filters();
52
            }
53
        }
54
55
        return [];
56
    }
57
}
58