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

View File

@@ -41,7 +41,8 @@ class DebuggerSubscriber implements EventSubscriberInterface
return; 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'])) { && isset($this->app['phraseanet.configuration']['debugger']['allowed-ips'])) {
$allowedIps = $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) 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)); $this->app->abort(503, 'Service Temporarily Unavailable', array('Retry-After' => 3600));
} }
} }

View File

@@ -36,7 +36,7 @@ class PersistentCookieSubscriber implements EventSubscriberInterface
{ {
$request = $event->getRequest(); $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'))) { if (false !== $session = $this->app['authentication.persistent-manager']->getSession($request->cookies->get('persistent'))) {
$this->app['authentication']->refreshAccount($session); $this->app['authentication']->refreshAccount($session);
} }

View File

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

View File

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

View File

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

View File

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