Completed
Push — master ( c28425...19ce3d )
by Konstantinos
04:16
created

AppGlobal::getUrlType()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 4
ccs 0
cts 2
cp 0
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 2
1
<?php
2
3
namespace BZIon\Twig;
4
5
use Symfony\Component\DependencyInjection\ContainerInterface;
6
7
/**
8
 * A twig global that provides information about the app
9
 */
10
class AppGlobal
11
{
12
    /**
13
     * The controller handling the request
14
     * @var \Controller
15
     */
16
    private $controller;
17
18
    /**
19
     * Symfony's container
20
     * @var ContainerInterface
21
     */
22
    private $container;
23
24
    /**
25
     * Create new AppGlobal
26
     *
27
     * @param \Controller        $controller The controller handling the request
28
     * @param ContainerInterface $container  Symfony's service container
29
     */
30 1
    public function __construct(\Controller $controller, ContainerInterface $container)
31
    {
32 1
        $this->controller = $controller;
33 1
        $this->container  = $container;
34 1
    }
35
36
    /**
37
     * Get the controller handling the request
38
     *
39
     * @return \Controller
40
     */
41 1
    public function getController()
42
    {
43 1
        return $this->controller;
44
    }
45
46
    /**
47
     * Get the environment of the kernel
48
     *
49
     * @return string
50
     */
51
    public function getEnvironment()
52
    {
53
        return $this->container->getParameter('kernel.environment');
54
    }
55
56
    /**
57
     * Find out whether the kernel has enabled debugging
58
     *
59
     * @return bool
60
     */
61 1
    public function isDebug()
62
    {
63 1
        return $this->container->getParameter('kernel.debug');
64
    }
65
66
    /**
67
     * Find out whether maintenance mode is enabled for users of the website
68
     *
69
     * @return bool
70
     */
71 1
    public function isMaintenance()
72
    {
73 1
        return $this->container->getParameter('bzion.miscellaneous.maintenance');
74
    }
75
76
    /**
77
     * Get the name of the website
78
     *
79
     * @return string
80
     */
81 1
    public function getSiteTitle()
82
    {
83 1
        return $this->container->getParameter('bzion.site.name');
84
    }
85
86
    /**
87
     * Get the name of the website
88
     *
89
     * @return string
90
     */
91 1
    public function getSiteWelcome()
92
    {
93 1
        return $this->container->getParameter('bzion.site.welcome');
94
    }
95
96
    /**
97
     * Get the name of the website
98
     *
99
     * @return string
100
     */
101 1
    public function getSiteSlug()
102
    {
103 1
        return $this->container->getParameter('bzion.site.slug');
104
    }
105
106
    /**
107
     * Whether or not the website wide alert is enabled
108
     *
109
     * @return bool
110
     */
111 1
    public function isAlertEnabled()
112
    {
113 1
        return $this->container->getParameter('bzion.site.alert.enabled');
114
    }
115
116
    /**
117
     * Should the alert be collapsible
118
     *
119
     * @return bool
120
     */
121
    public function isAlertCollapsible()
122
    {
123
        return $this->container->getParameter('bzion.site.alert.collapsible');
124
    }
125
126
    /**
127
     * The title of the alert
128
     *
129
     * @return string
130
     */
131
    public function getAlertHeader()
132
    {
133
        return $this->container->getParameter('bzion.site.alert.header');
134
    }
135
136
    /**
137
     * The message of the alert
138
     *
139
     * @return string
140
     */
141
    public function getAlertMessage()
142
    {
143
        return $this->container->getParameter('bzion.site.alert.message');
144
    }
145
146
    /**
147
     * The type of URLs for Models
148
     *
149
     * @return string `vanity` or `permalink`
150
     */
151
    public function getUrlType()
152
    {
153
        return $this->container->getParameter('bzion.site.url_type');
154
    }
155
156
    /**
157
     * A unique enough identifier of the alert
158
     *
159
     * @return string
160
     */
161 1
    public function getAlertID()
162
    {
163
        return substr(md5($this->getAlertHeader() . $this->getAlertMessage()), 0, 7);
164
    }
165 1
166 1
    /**
167
     * Get information about sockets
168
     *
169
     * @return array
170
     */
171
    public function getSocket()
172
    {
173
        return array(
174
            'websocket' => array(
175
                'enabled' => $this->container->getParameter('bzion.features.websocket.enabled'),
176 1
                'port'    => $this->container->getParameter('bzion.features.websocket.push_port')
177
            )
178 1
        );
179 1
    }
180 1
181
    /**
182
     * Get a list of visible pages
183
     *
184
     * @return \Page[]
185
     */
186
    public function getPages()
187
    {
188
        return \Page::getQueryBuilder()
189
            ->where('status')->equals('live')
190
            ->getModels($fast = true);
191
    }
192
}
193