From 11c5ae47f6fb71e9fea997988c583d94c2e49eb2 Mon Sep 17 00:00:00 2001 From: Romain Neutron Date: Mon, 11 Feb 2013 15:07:15 +0100 Subject: [PATCH] Add Silex WebProfiler --- composer.json | 1 + composer.lock | 56 +++++++++++++++++-- config/nginx.rewrite.rules | 1 + lib/Alchemy/Phrasea/Application.php | 36 +++++++----- .../Alchemy/Tests/Phrasea/ApplicationTest.php | 15 +++++ www/.htaccess | 1 + 6 files changed, 92 insertions(+), 18 deletions(-) diff --git a/composer.json b/composer.json index 148fba15a9..8019c4423d 100644 --- a/composer.json +++ b/composer.json @@ -26,6 +26,7 @@ "phpexiftool/phpexiftool" : "~0.1.0", "phpexiftool/exiftool" : "dev-master", "silex/silex" : "1.0.x-dev@dev", + "silex/web-profiler" : "1.0.x-dev@dev", "swiftmailer/swiftmailer" : "~4.3.0", "symfony/symfony" : "2.2.x-dev@dev", "tecnick.com/tcpdf" : "dev-master", diff --git a/composer.lock b/composer.lock index f231f55436..2ee037631e 100644 --- a/composer.lock +++ b/composer.lock @@ -1,5 +1,5 @@ { - "hash": "fc5fa4c5fd4b320e0ff3c53ec0ad8705", + "hash": "3214068afe9eec2f5219bcb246f8e0cf", "packages": [ { "name": "BadFaith/BadFaith", @@ -1464,6 +1464,51 @@ "microframework" ] }, + { + "name": "silex/web-profiler", + "version": "dev-master", + "target-dir": "Silex/Provider", + "source": { + "type": "git", + "url": "https://github.com/sensiolabs/Silex-WebProfiler", + "reference": "61207f087efbdc568d1d380f5d8ff54b4bbc1bab" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sensiolabs/Silex-WebProfiler/zipball/61207f087efbdc568d1d380f5d8ff54b4bbc1bab", + "reference": "61207f087efbdc568d1d380f5d8ff54b4bbc1bab", + "shasum": "" + }, + "require": { + "silex/silex": ">=1.0,<2.0", + "symfony/web-profiler-bundle": ">=2.2,<3.0", + "symfony/stopwatch": ">=2.2,<3.0" + }, + "time": "2013-02-07 16:48:25", + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "psr-0": { + "Silex\\Provider\\": "" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + } + ], + "description": "A WebProfiler for Silex", + "homepage": "http://silex.sensiolabs.org/" + }, { "name": "swftools/swftools", "version": "0.1.1", @@ -1572,12 +1617,12 @@ "source": { "type": "git", "url": "git://github.com/symfony/symfony.git", - "reference": "95ba9449e2d5e77bd945c1a0c611c30c4f0237c7" + "reference": "f410931dd808cc7054599ba8fcb3d02e55b43584" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/symfony/zipball/95ba9449e2d5e77bd945c1a0c611c30c4f0237c7", - "reference": "95ba9449e2d5e77bd945c1a0c611c30c4f0237c7", + "url": "https://api.github.com/repos/symfony/symfony/zipball/f410931dd808cc7054599ba8fcb3d02e55b43584", + "reference": "f410931dd808cc7054599ba8fcb3d02e55b43584", "shasum": "" }, "require": { @@ -1629,7 +1674,7 @@ "doctrine/orm": ">=2.2,<3.0,>=2.2.3", "propel/propel1": "1.6.*" }, - "time": "2013-02-11 11:43:49", + "time": "2013-02-11 12:46:49", "type": "library", "extra": { "branch-alias": { @@ -1931,6 +1976,7 @@ "neutron/silex-filesystem-provider": 20, "phpexiftool/exiftool": 20, "silex/silex": 20, + "silex/web-profiler": 20, "symfony/symfony": 20, "tecnick.com/tcpdf": 20, "twig/extensions": 20, diff --git a/config/nginx.rewrite.rules b/config/nginx.rewrite.rules index 80ac579b18..69120b8c0c 100644 --- a/config/nginx.rewrite.rules +++ b/config/nginx.rewrite.rules @@ -1,6 +1,7 @@ rewrite ^/include/minify/([a-z]=.*) /include/minify/index.php?$1 last; rewrite ^/admin/.*$ /index.php last; +rewrite ^/_profiler/.*$ /index.php last; rewrite ^/lightbox.?$ /index.php last; rewrite ^/robots.txt$ /index.php last; rewrite ^/feeds/.*$ /index.php last; diff --git a/lib/Alchemy/Phrasea/Application.php b/lib/Alchemy/Phrasea/Application.php index 9c5dbff282..6665670380 100644 --- a/lib/Alchemy/Phrasea/Application.php +++ b/lib/Alchemy/Phrasea/Application.php @@ -96,6 +96,8 @@ use Silex\Provider\TwigServiceProvider; use Silex\Provider\SwiftmailerServiceProvider; use Silex\Provider\UrlGeneratorServiceProvider; use Silex\Provider\ValidatorServiceProvider; +use Silex\Provider\ServiceControllerServiceProvider; +use Silex\Provider\WebProfilerServiceProvider; use Unoconv\UnoconvServiceProvider; use XPDF\PdfToText; use XPDF\XPDFServiceProvider; @@ -182,6 +184,10 @@ class Application extends SilexApplication $this->register(new MediaAlchemystServiceProvider()); $this->register(new MediaVorusServiceProvider()); $this->register(new MonologServiceProvider()); + $this['monolog.name'] = 'Phraseanet logger'; + $this['monolog.handler'] = $this->share(function () { + return new NullHandler(); + }); $this->register(new MP4BoxServiceProvider()); $this->register(new NotificationDelivererServiceProvider()); $this->register(new ORMServiceProvider()); @@ -191,13 +197,29 @@ class Application extends SilexApplication $this->register(new SessionServiceProvider(), array( 'session.test' => $this->getEnvironment() == 'test' )); + $this->register(new ServiceControllerServiceProvider()); + $this->register(new SwiftmailerServiceProvider()); $this->register(new TaskManagerServiceProvider()); + $this->register(new TwigServiceProvider(), array( + 'twig.options' => array( + 'cache' => realpath(__DIR__ . '/../../../../../../tmp/cache_twig/'), + ) + )); + + $this->setupTwig(); $this->register(new UnoconvServiceProvider()); $this->register(new UrlGeneratorServiceProvider()); $this->register(new UnicodeServiceProvider()); $this->register(new ValidatorServiceProvider()); + + if ('dev' === $this->environment) { + $this->register($p = new WebProfilerServiceProvider(), array( + 'profiler.cache_dir' => __DIR__ . '/../../../cache/profiler', + )); + $this->mount('/_profiler', $p); + } + $this->register(new XPDFServiceProvider()); - $this->register(new SwiftmailerServiceProvider()); $this['swiftmailer.transport'] = $this->share(function ($app) { @@ -266,10 +288,6 @@ class Application extends SilexApplication throw new \RuntimeException('No Imagine driver available'); }); - $this['monolog.name'] = 'Phraseanet logger'; - $this['monolog.handler'] = $this->share(function () { - return new NullHandler(); - }); $app = $this; $this['phraseanet.logger'] = $this->protect(function($databox) use ($app) { @@ -296,14 +314,6 @@ class Application extends SilexApplication }) ); - $this->register(new TwigServiceProvider(), array( - 'twig.options' => array( - 'cache' => realpath(__DIR__ . '/../../../../../../tmp/cache_twig/'), - ) - )); - - $this->setupTwig(); - $this['dispatcher']->addListener(KernelEvents::REQUEST, array($this, 'addLocale'), 255); $this['dispatcher']->addListener(KernelEvents::REQUEST, array($this, 'initSession'), 254); $this['dispatcher']->addListener(KernelEvents::RESPONSE, array($this, 'addUTF8Charset'), -128); diff --git a/tests/Alchemy/Tests/Phrasea/ApplicationTest.php b/tests/Alchemy/Tests/Phrasea/ApplicationTest.php index 03a25c0106..87ff4ac2d8 100644 --- a/tests/Alchemy/Tests/Phrasea/ApplicationTest.php +++ b/tests/Alchemy/Tests/Phrasea/ApplicationTest.php @@ -172,6 +172,21 @@ class ApplicationTest extends \PhraseanetPHPUnitAbstract $this->assertEquals('123456', $sessionId); } + public function testWebProfilerDisableByDefault() + { + $app = new Application('prod'); + $this->assertFalse(isset($app['profiler'])); + + $app = new Application('test'); + $this->assertFalse(isset($app['profiler'])); + } + + public function testWebProfilerEnableInDevMode() + { + $app = new Application('dev'); + $this->assertTrue(isset($app['profiler'])); + } + private function getAppThatReturnLocale() { $app = new Application('test'); diff --git a/www/.htaccess b/www/.htaccess index 545b4835b4..0228de1fce 100644 --- a/www/.htaccess +++ b/www/.htaccess @@ -2,6 +2,7 @@ RewriteEngine on RewriteRule ^include/minify/([a-z]=.*) /include/minify/index.php$1 [L,NE] + RewriteRule ^_profiler/.*$ /index.php [L] RewriteRule ^lightbox/.*$ /index.php [L] RewriteRule ^admin/.*$ /index.php [L] RewriteRule ^permalink/.*$ /index.php [L]