Fix #1368 : Disable call to configuration when application is not installed

This commit is contained in:
Romain Neutron
2013-07-23 18:33:48 +02:00
parent 87f37e767a
commit bc617d101a
8 changed files with 29 additions and 9 deletions

View File

@@ -521,6 +521,7 @@ class Application extends SilexApplication
private function setupUrlGenerator()
{
$this['url_generator'] = $this->share($this->extend('url_generator', function($urlGenerator, $app) {
if ($app['phraseanet.configuration']->isSetup()) {
$data = parse_url($app['phraseanet.configuration']['main']['servername']);
if (isset($data['scheme'])) {
@@ -529,6 +530,7 @@ class Application extends SilexApplication
if (isset($data['host'])) {
$urlGenerator->getContext()->setHost($data['host']);
}
}
return $urlGenerator;
}));

View File

@@ -41,7 +41,8 @@ class DebuggerSubscriber implements EventSubscriberInterface
return;
}
if (isset($this->app['phraseanet.configuration']['debugger'])
if ($this->app['phraseanet.configuration']->isSetup()
&& isset($this->app['phraseanet.configuration']['debugger'])
&& isset($this->app['phraseanet.configuration']['debugger']['allowed-ips'])) {
$allowedIps = $this->app['phraseanet.configuration']['debugger']['allowed-ips'];

View File

@@ -34,7 +34,7 @@ class MaintenanceSubscriber implements EventSubscriberInterface
public function checkForMaintenance(GetResponseEvent $event)
{
if ($this->app['phraseanet.configuration']['main']['maintenance']) {
if ($this->app['phraseanet.configuration']->isSetup() && $this->app['phraseanet.configuration']['main']['maintenance']) {
$this->app->abort(503, 'Service Temporarily Unavailable', array('Retry-After' => 3600));
}
}

View File

@@ -36,7 +36,7 @@ class PersistentCookieSubscriber implements EventSubscriberInterface
{
$request = $event->getRequest();
if ($request->cookies->has('persistent') && !$this->app['authentication']->isAuthenticated()) {
if ($this->app['phraseanet.configuration']->isSetup() && $request->cookies->has('persistent') && !$this->app['authentication']->isAuthenticated()) {
if (false !== $session = $this->app['authentication.persistent-manager']->getSession($request->cookies->get('persistent'))) {
$this->app['authentication']->refreshAccount($session);
}

View File

@@ -35,6 +35,10 @@ class TrustedProxySubscriber implements EventSubscriberInterface
public function setProxyConf(GetResponseEvent $event)
{
if (!$this->configuration->isSetup()) {
return;
}
$proxies = isset($this->configuration['trusted-proxies']) ? $this->configuration['trusted-proxies'] : array();
Request::setTrustedProxies($proxies);
}

View File

@@ -35,6 +35,10 @@ class XSendFileSubscriber implements EventSubscriberInterface
public function applyHeaders(GetResponseEvent $event)
{
if (!$this->app['phraseanet.configuration']->isSetup()) {
return;
}
if ($this->app['phraseanet.xsendfile-factory']->isXSendFileModeEnabled()) {
BinaryFileResponse::trustXSendfileTypeHeader();
$this->app['phraseanet.xsendfile-factory']->getMode()->setHeaders($event->getRequest());

View File

@@ -294,6 +294,9 @@ class ApplicationTest extends \PhraseanetPHPUnitAbstract
{
$app = new Application('test');
$app['phraseanet.configuration'] = $this->getMock('Alchemy\Phrasea\Core\Configuration\ConfigurationInterface');
$app['phraseanet.configuration']->expects($this->once())
->method('isSetup')
->will($this->returnValue(true));
$app['phraseanet.configuration']->expects($this->once())
->method('offsetGet')
->with('main')

View File

@@ -19,6 +19,9 @@ class TrustedProxySubscriberTest extends \PHPUnit_Framework_TestCase
public function testAllowedIpsAreSetAsArray()
{
$configuration = $this->getConfigurationMock();
$configuration->expects($this->once())
->method('isSetup')
->will($this->returnValue(true));
$configuration->expects($this->once())
->method('offsetGet')
->with('trusted-proxies')
@@ -45,6 +48,9 @@ class TrustedProxySubscriberTest extends \PHPUnit_Framework_TestCase
public function testAllowedIpsAreSetWhenEmpty()
{
$configuration = $this->getConfigurationMock();
$configuration->expects($this->once())
->method('isSetup')
->will($this->returnValue(true));
$configuration->expects($this->once())
->method('offsetExists')
->with('trusted-proxies')