Completed
Push — master ( acd295...352ddb )
by Ryan
05:52
created

LoadCurrentTheme::handle()   C

Complexity

Conditions 7
Paths 24

Size

Total Lines 34
Code Lines 23

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 7
eloc 23
nc 24
nop 7
dl 0
loc 34
rs 6.7272
c 0
b 0
f 0
1
<?php namespace Anomaly\Streams\Platform\Addon\Theme\Command;
2
3
use Anomaly\Streams\Platform\Addon\Theme\ThemeCollection;
4
use Anomaly\Streams\Platform\Asset\Asset;
5
use Anomaly\Streams\Platform\Image\Image;
6
use Illuminate\Config\Repository;
7
use Illuminate\Contracts\View\Factory;
8
use Illuminate\Http\Request;
9
use Illuminate\Translation\Translator;
10
11
/**
12
 * Class LoadCurrentTheme
13
 *
14
 * @link   http://pyrocms.com/
15
 * @author PyroCMS, Inc. <[email protected]>
16
 * @author Ryan Thompson <[email protected]>
17
 */
18
class LoadCurrentTheme
19
{
20
21
    /**
22
     * Create a new LoadCurrentTheme instance.
23
     *
24
     * @param Asset           $asset
25
     * @param Image           $image
26
     * @param Factory         $view
27
     * @param Request         $request
28
     * @param Repository      $config
29
     * @param ThemeCollection $themes
30
     * @param Translator      $translator
31
     */
32
    public function handle(
33
        Asset $asset,
34
        Image $image,
35
        Factory $view,
36
        Request $request,
37
        Repository $config,
38
        ThemeCollection $themes,
39
        Translator $translator
40
    ) {
41
        $admin    = $themes->get($config->get('streams::themes.admin'));
42
        $standard = $themes->get($config->get('streams::themes.standard'));
43
44
        if ($admin) {
45
            $admin->setActive(true);
46
        }
47
48
        if ($standard) {
49
            $standard->setActive(true);
50
        }
51
52
        if ($admin && in_array($request->segment(1), ['installer', 'admin'])) {
53
            $admin->setCurrent(true);
54
        } elseif ($standard) {
55
            $standard->setCurrent(true);
56
        }
57
58
        if ($theme = $themes->current()) {
59
            $view->addNamespace('theme', $theme->getPath('resources/views'));
60
            $translator->addNamespace('theme', $theme->getPath('resources/lang'));
61
62
            $asset->addPath('theme', $theme->getPath('resources'));
63
            $image->addPath('theme', $theme->getPath('resources'));
64
        }
65
    }
66
}
67