Completed
Pull Request — master (#4522)
by Craig
13:45
created

BrandingRuntime::getSiteSlogan()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 1
b 0
f 1
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the Zikula package.
7
 *
8
 * Copyright Zikula - https://ziku.la/
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
14
namespace Zikula\ThemeModule\Twig\Runtime;
15
16
use Exception;
17
use Twig\Environment;
18
use Twig\Extension\RuntimeExtensionInterface;
19
use Zikula\Bundle\CoreBundle\Site\SiteDefinitionInterface;
20
use Zikula\ThemeModule\Engine\Asset;
21
22
class BrandingRuntime implements RuntimeExtensionInterface
23
{
24
    /**
25
     * @var Environment
26
     */
27
    private $twig;
28
29
    /**
30
     * @var SiteDefinitionInterface
31
     */
32
    private $site;
33
34
    /**
35
     * @var Asset
36
     */
37
    private $assetHelper;
38
39
    public function __construct(
40
        Environment $twig,
41
        SiteDefinitionInterface $site,
42
        Asset $assetHelper
43
    ) {
44
        $this->twig = $twig;
45
        $this->site = $site;
46
        $this->assetHelper = $assetHelper;
47
    }
48
49
    /**
50
     * Returns site name.
51
     */
52
    public function getSiteName(): string
53
    {
54
        return $this->site->getName();
55
    }
56
57
    /**
58
     * Returns site slogan.
59
     */
60
    public function getSiteSlogan(): string
61
    {
62
        return $this->site->getSlogan();
63
    }
64
65
    /**
66
     * Returns site branding markup.
67
     */
68
    public function getSiteBrandingMarkup(): string
69
    {
70
        return $this->twig->render('@ZikulaThemeModule/Engine/manifest.html.twig');
71
    }
72
73
    /**
74
     * Returns site image path.
75
     */
76
    public function getSiteImagePath(string $imageType = ''): string
77
    {
78
        if (!in_array($imageType, ['logo', 'mobileLogo', 'icon'], true)) {
79
            $imageType = 'logo';
80
        }
81
82
        $accessor = 'get' . ucfirst($imageType) . 'Path';
83
84
        $assetPath = $this->site->{$accessor}();
85
86
        try {
87
            $imagePath = $this->assetHelper->resolve($assetPath);
88
        } catch (Exception $exception) {
89
            // fall back to default
90
            $assetPath = '@CoreBundle:images/';
91
            if ('logo' === $imageType) {
92
                $assetPath .= 'logo_with_title.png';
93
            } elseif ('mobileLogo' === $imageType) {
94
                $assetPath .= 'zk-power.png';
95
            } elseif ('icon' === $imageType) {
96
                $assetPath .= 'logo.gif';
97
            }
98
99
            $imagePath = $this->assetHelper->resolve($assetPath);
100
        }
101
102
        return $imagePath;
103
    }
104
}
105