forked from mickaelandrieu/backbee-standard
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApplication.php
More file actions
executable file
·155 lines (135 loc) · 4.76 KB
/
Application.php
File metadata and controls
executable file
·155 lines (135 loc) · 4.76 KB
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
<?php
/*
* Copyright (c) 2011-2015 Lp digital system
*
* This file is part of BackBee Standard Edition.
*
* BackBee is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* BackBee Standard Edition is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with BackBee Standard Edition. If not, see <http://www.gnu.org/licenses/>.
*/
namespace BackBee\Standard;
use BackBee\BBApplication;
use BackBee\Console\Console;
use BackBee\Security\Token\BBUserToken;
use Symfony\Component\Finder\Finder;
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
use Symfony\Component\HttpKernel\HttpKernelInterface;
/**
* @author e.chau <eric.chau@lp-digital.fr>
* @author Mickaël Andrieu <mickael.andrieu@lp-digital.fr>
*/
class Application extends BBApplication
{
/**
* {@inheritdoc}
*/
public function getBaseDir()
{
return __DIR__;
}
/**
* Set the paths to Commands in BackBee Standard application
*/
public function getCommandDirectories()
{
return array_merge(
[$this->getBaseRepository() . DIRECTORY_SEPARATOR . 'Command'],
$this->hasContext() ? [$this->getRepository() . DIRECTORY_SEPARATOR . 'Command'] : []
);
}
/**
* {@inheritdoc}
*/
public static function getConfigurationDir()
{
return __DIR__ . DIRECTORY_SEPARATOR . 'repository' . DIRECTORY_SEPARATOR . 'Config' . DIRECTORY_SEPARATOR;
}
/**
* Check if the CMS is installed
*/
public static function isInstalled()
{
$configDirectory = __DIR__.DIRECTORY_SEPARATOR.'repository'.DIRECTORY_SEPARATOR.'Config';
return is_file($configDirectory.DIRECTORY_SEPARATOR.'sites.yml')
&& is_file($configDirectory.DIRECTORY_SEPARATOR.'doctrine.yml')
&& is_file($configDirectory.DIRECTORY_SEPARATOR.'bootstrap.yml')
;
}
/**
* Finds and registers Commands in BackBee Standard application
*
* @{inheritdoc}
* @param BackBee\Console\Console $console An Application instance
*/
public function registerCommands(Console $console)
{
parent::registerCommands($console);
$commandNamespace = 'BackBee\Standard\Command';
$directories = $this->getCommandDirectories();
foreach($directories as $directory) {
if (is_dir($directory)) {
/* register the namespace */
$this->getAutoloader()
->register()
->registerNamespace($commandNamespace, $directory)
;
$files = (new Finder())->files()->name('*Command.php')->in($directory);
foreach ($files as $file) {
if ($relativePath = $file->getRelativePath()) {
$commandNamespace .= '\\'.strtr($relativePath, '/', '\\');
}
$reflectionClass = new \ReflectionClass($commandNamespace.'\\'.$file->getBasename('.php'));
if (
$reflectionClass->isSubclassOf('BackBee\\Console\\AbstractCommand')
&& !$reflectionClass->isAbstract()
&& !$reflectionClass->getConstructor()->getNumberOfRequiredParameters()
) {
$console->add($reflectionClass->newInstance());
}
}
}
}
}
/**
* Stop the current BBApplication instance.
*
* @{inheritdoc}
* @return void
*/
public function stop()
{
parent::stop();
exit();
}
/**
* {@inheritdoc}
*/
public function getBBUserToken()
{
$token = $this->getSecurityContext()->getToken();
if (!($token instanceof BBUserToken) || $token->isExpired()) {
$restToken = unserialize($this->getSession()->get('_security_rest_api_area'));
$token = $restToken ?: $token;
}
if ($token instanceof BBUserToken && $token->isExpired()) {
$event = new GetResponseEvent(
$this->getController(),
$this->getRequest(),
HttpKernelInterface::MASTER_REQUEST
);
$this->getEventDispatcher()->dispatch('frontcontroller.request.logout', $event);
$token = null;
}
return $token instanceof BBUserToken ? $token : null;
}
}