From 0c9b2d47b0ebeb83ce099fe77567fe720e8672ea Mon Sep 17 00:00:00 2001 From: Pierre Minnieur Date: Fri, 9 Mar 2012 10:08:43 +0100 Subject: [PATCH 01/18] use SecurityContextInterface instead of SecurityContext --- .../Component/Security/Http/Firewall/ContextListener.php | 4 ++-- .../Component/Security/Http/Firewall/RememberMeListener.php | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Symfony/Component/Security/Http/Firewall/ContextListener.php b/src/Symfony/Component/Security/Http/Firewall/ContextListener.php index d282452629ed9..52dea564ec6da 100644 --- a/src/Symfony/Component/Security/Http/Firewall/ContextListener.php +++ b/src/Symfony/Component/Security/Http/Firewall/ContextListener.php @@ -20,7 +20,7 @@ use Symfony\Component\Security\Core\Authentication\Token\TokenInterface; use Symfony\Component\Security\Core\Exception\UsernameNotFoundException; use Symfony\Component\Security\Core\Exception\UnsupportedUserException; -use Symfony\Component\Security\Core\SecurityContext; +use Symfony\Component\Security\Core\SecurityContextInterface; use Symfony\Component\Security\Core\User\UserInterface; use Symfony\Component\EventDispatcher\EventDispatcherInterface; @@ -37,7 +37,7 @@ class ContextListener implements ListenerInterface private $logger; private $userProviders; - public function __construct(SecurityContext $context, array $userProviders, $contextKey, LoggerInterface $logger = null, EventDispatcherInterface $dispatcher = null) + public function __construct(SecurityContextInterface $context, array $userProviders, $contextKey, LoggerInterface $logger = null, EventDispatcherInterface $dispatcher = null) { if (empty($contextKey)) { throw new \InvalidArgumentException('$contextKey must not be empty.'); diff --git a/src/Symfony/Component/Security/Http/Firewall/RememberMeListener.php b/src/Symfony/Component/Security/Http/Firewall/RememberMeListener.php index 55310122d48ca..ccda11309471d 100644 --- a/src/Symfony/Component/Security/Http/Firewall/RememberMeListener.php +++ b/src/Symfony/Component/Security/Http/Firewall/RememberMeListener.php @@ -6,7 +6,7 @@ use Symfony\Component\HttpKernel\Event\GetResponseEvent; use Symfony\Component\Security\Core\Authentication\AuthenticationManagerInterface; use Symfony\Component\Security\Core\Exception\AuthenticationException; -use Symfony\Component\Security\Core\SecurityContext; +use Symfony\Component\Security\Core\SecurityContextInterface; use Symfony\Component\Security\Http\RememberMe\RememberMeServicesInterface; use Symfony\Component\Security\Http\Event\InteractiveLoginEvent; use Symfony\Component\Security\Http\SecurityEvents; @@ -37,13 +37,13 @@ class RememberMeListener implements ListenerInterface /** * Constructor * - * @param SecurityContext $securityContext + * @param SecurityContextInterface $securityContext * @param RememberMeServicesInterface $rememberMeServices * @param AuthenticationManagerInterface $authenticationManager * @param LoggerInterface $logger * @param EventDispatcherInterface $dispatcher */ - public function __construct(SecurityContext $securityContext, RememberMeServicesInterface $rememberMeServices, AuthenticationManagerInterface $authenticationManager, LoggerInterface $logger = null, EventDispatcherInterface $dispatcher = null) + public function __construct(SecurityContextInterface $securityContext, RememberMeServicesInterface $rememberMeServices, AuthenticationManagerInterface $authenticationManager, LoggerInterface $logger = null, EventDispatcherInterface $dispatcher = null) { $this->securityContext = $securityContext; $this->rememberMeServices = $rememberMeServices; From 86a3512bd4de9463a0b21bd04738cea3eac7c6f7 Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Sun, 25 Mar 2012 20:43:23 +0200 Subject: [PATCH 02/18] [FrameworkBundle] Add support for full URLs to redirect controller --- .../Controller/RedirectController.php | 9 ++++++++- .../Tests/Controller/RedirectControllerTest.php | 15 +++++++++++---- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/src/Symfony/Bundle/FrameworkBundle/Controller/RedirectController.php b/src/Symfony/Bundle/FrameworkBundle/Controller/RedirectController.php index 2e2a24a0915a8..2cb84746fa967 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Controller/RedirectController.php +++ b/src/Symfony/Bundle/FrameworkBundle/Controller/RedirectController.php @@ -70,6 +70,13 @@ public function urlRedirectAction($path, $permanent = false, $scheme = null, $ht return new Response(null, 410); } + $statusCode = $permanent ? 301 : 302; + + // redirect if the path is a full URL + if (parse_url($path, PHP_URL_SCHEME)) { + return new RedirectResponse($path, $statusCode); + } + $request = $this->container->get('request'); if (null === $scheme) { $scheme = $request->getScheme(); @@ -89,6 +96,6 @@ public function urlRedirectAction($path, $permanent = false, $scheme = null, $ht $url = $scheme.'://'.$request->getHost().$port.$request->getBaseUrl().$path.$qs; - return new RedirectResponse($url, $permanent ? 301 : 302); + return new RedirectResponse($url, $statusCode); } } diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Controller/RedirectControllerTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/Controller/RedirectControllerTest.php index e90f9dc25ae04..fdb88c0ec0feb 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/Controller/RedirectControllerTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Controller/RedirectControllerTest.php @@ -92,15 +92,22 @@ public function provider() public function testEmptyPath() { - $container = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface'); - $controller = new RedirectController(); - $controller->setContainer($container); - $returnResponse = $controller->urlRedirectAction(''); $this->assertInstanceOf('\Symfony\Component\HttpFoundation\Response', $returnResponse); $this->assertEquals(410, $returnResponse->getStatusCode()); } + + public function testFullURL() + { + $controller = new RedirectController(); + $returnResponse = $controller->urlRedirectAction('http://foo.bar/'); + + $this->assertInstanceOf('\Symfony\Component\HttpFoundation\Response', $returnResponse); + + $this->assertEquals('http://foo.bar/', $returnResponse->headers->get('Location')); + $this->assertEquals(302, $returnResponse->getStatusCode()); + } } From 15dd17e9bd3f80427054fc4701fc20a073c357bf Mon Sep 17 00:00:00 2001 From: Jordan Alliot Date: Mon, 26 Mar 2012 23:58:48 +0200 Subject: [PATCH 03/18] Simplified CONTENT_ headers retrieval --- src/Symfony/Component/HttpFoundation/ServerBag.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Symfony/Component/HttpFoundation/ServerBag.php b/src/Symfony/Component/HttpFoundation/ServerBag.php index 9cb7786129cb2..b40637e9e4e8a 100644 --- a/src/Symfony/Component/HttpFoundation/ServerBag.php +++ b/src/Symfony/Component/HttpFoundation/ServerBag.php @@ -28,7 +28,7 @@ public function getHeaders() } // CONTENT_* are not prefixed with HTTP_ elseif (in_array($key, array('CONTENT_LENGTH', 'CONTENT_MD5', 'CONTENT_TYPE'))) { - $headers[$key] = $this->parameters[$key]; + $headers[$key] = $value; } } From e4f3fd9a728923004d4e675927c40f45a9914248 Mon Sep 17 00:00:00 2001 From: Clemens Tolboom Date: Thu, 29 Mar 2012 14:32:59 +0200 Subject: [PATCH 04/18] Fixed example code. --- src/Symfony/Component/Translation/README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Symfony/Component/Translation/README.md b/src/Symfony/Component/Translation/README.md index 9afd9f82066cc..713e6d978e1be 100644 --- a/src/Symfony/Component/Translation/README.md +++ b/src/Symfony/Component/Translation/README.md @@ -10,12 +10,12 @@ translated strings from these including support for pluralization. $translator = new Translator('fr_FR', new MessageSelector()); $translator->setFallbackLocale('fr'); - $translator->addLoader('array', return new ArrayLoader()); + $translator->addLoader('array', new ArrayLoader()); $translator->addResource('array', array( 'Hello World!' => 'Bonjour', ), 'fr'); - $translator->trans('Hello World!'); + echo $translator->trans('Hello World!') . "\n"; Resources --------- From 24a0d0a2dcf334efc7d85f1c816c01d7fa4111f8 Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Sat, 31 Mar 2012 21:11:13 +0200 Subject: [PATCH 05/18] [DependencyInjection] Support Yaml calls without arguments --- .../Component/DependencyInjection/Loader/YamlFileLoader.php | 3 ++- .../Component/DependencyInjection/Fixtures/yaml/services6.yml | 1 + .../DependencyInjection/Loader/YamlFileLoaderTest.php | 2 +- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Symfony/Component/DependencyInjection/Loader/YamlFileLoader.php b/src/Symfony/Component/DependencyInjection/Loader/YamlFileLoader.php index 0faa76736fb01..bad370e871e08 100644 --- a/src/Symfony/Component/DependencyInjection/Loader/YamlFileLoader.php +++ b/src/Symfony/Component/DependencyInjection/Loader/YamlFileLoader.php @@ -196,7 +196,8 @@ private function parseDefinition($id, $service, $file) if (isset($service['calls'])) { foreach ($service['calls'] as $call) { - $definition->addMethodCall($call[0], $this->resolveServices($call[1])); + $args = isset($call[1]) ? $this->resolveServices($call[1]) : array(); + $definition->addMethodCall($call[0], $args); } } diff --git a/tests/Symfony/Tests/Component/DependencyInjection/Fixtures/yaml/services6.yml b/tests/Symfony/Tests/Component/DependencyInjection/Fixtures/yaml/services6.yml index 93d618d5f50e6..bbc048cb7f41d 100644 --- a/tests/Symfony/Tests/Component/DependencyInjection/Fixtures/yaml/services6.yml +++ b/tests/Symfony/Tests/Component/DependencyInjection/Fixtures/yaml/services6.yml @@ -14,6 +14,7 @@ services: class: FooClass calls: - [ setBar, [] ] + - [ setBar ] method_call2: class: FooClass calls: diff --git a/tests/Symfony/Tests/Component/DependencyInjection/Loader/YamlFileLoaderTest.php b/tests/Symfony/Tests/Component/DependencyInjection/Loader/YamlFileLoaderTest.php index 537cc80326489..a2593ac2392d4 100644 --- a/tests/Symfony/Tests/Component/DependencyInjection/Loader/YamlFileLoaderTest.php +++ b/tests/Symfony/Tests/Component/DependencyInjection/Loader/YamlFileLoaderTest.php @@ -113,7 +113,7 @@ public function testLoadServices() $this->assertEquals('sc_configure', $services['configurator1']->getConfigurator(), '->load() parses the configurator tag'); $this->assertEquals(array(new Reference('baz'), 'configure'), $services['configurator2']->getConfigurator(), '->load() parses the configurator tag'); $this->assertEquals(array('BazClass', 'configureStatic'), $services['configurator3']->getConfigurator(), '->load() parses the configurator tag'); - $this->assertEquals(array(array('setBar', array())), $services['method_call1']->getMethodCalls(), '->load() parses the method_call tag'); + $this->assertEquals(array(array('setBar', array()), array('setBar', array())), $services['method_call1']->getMethodCalls(), '->load() parses the method_call tag'); $this->assertEquals(array(array('setBar', array('foo', new Reference('foo'), array(true, false)))), $services['method_call2']->getMethodCalls(), '->load() parses the method_call tag'); $this->assertEquals('baz_factory', $services['factory_service']->getFactoryService()); From 032ab942d3729427e8ec55fd828b1d067e511711 Mon Sep 17 00:00:00 2001 From: Juti Noppornpitak Date: Tue, 3 Apr 2012 10:18:34 -0400 Subject: [PATCH 06/18] Prepare for modifying toolbar. --- .../views/Profiler/toolbar.html.twig | 42 +++++++++++++------ 1 file changed, 30 insertions(+), 12 deletions(-) diff --git a/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Profiler/toolbar.html.twig b/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Profiler/toolbar.html.twig index eccdca834edd6..62dda911b364f 100644 --- a/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Profiler/toolbar.html.twig +++ b/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Profiler/toolbar.html.twig @@ -1,16 +1,15 @@ {% if 'normal' != position %} -
-{% endif %} - -
+ .sf-toolbarreset { + -moz-transition: all ease 200ms; + -webkit-transition: all ease 200ms; + position: {{ position }}; + background-color: #f7f7f7; background-image: -moz-linear-gradient(-90deg, #e4e4e4, #ffffff); background-image: -webkit-gradient(linear, 0% 0%, 0% 100%, from(#e4e4e4), to(#ffffff)); - bottom: 0; - left:0; + bottom: 0px; + left:95%; margin:0; padding: 0; z-index: 6000000; @@ -18,9 +17,28 @@ border-top: 1px solid #bbb; font: 11px Verdana, Arial, sans-serif; text-align: left; - color: #2f2f2f;" - {% endif %} -> + color: #2f2f2f; + border-left: 1px solid #bbb; + } + + .sf-toolbarreset:hover { + left: 0; + } + + /* + .sf-toolbarreset a[href$="request"] ~ span { + display: inline-block; + overflow: hidden; + max-width: 70px; + text-overflow: ellipsis; + border-left: 0px; + } + */ + +
+{% endif %} + +
  From fd1ea69b78994a787f0b5bf3e6cfc4f48e583864 Mon Sep 17 00:00:00 2001 From: Rui Marinho Date: Wed, 4 Apr 2012 11:36:25 +0100 Subject: [PATCH 07/18] [Security] [HttpDigest] Fixes a configuration error caused by an invalid key child node configuration --- .../DependencyInjection/Security/Factory/HttpDigestFactory.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Symfony/Bundle/SecurityBundle/DependencyInjection/Security/Factory/HttpDigestFactory.php b/src/Symfony/Bundle/SecurityBundle/DependencyInjection/Security/Factory/HttpDigestFactory.php index 2f09be07afc75..3a49b5dcdc583 100644 --- a/src/Symfony/Bundle/SecurityBundle/DependencyInjection/Security/Factory/HttpDigestFactory.php +++ b/src/Symfony/Bundle/SecurityBundle/DependencyInjection/Security/Factory/HttpDigestFactory.php @@ -62,7 +62,7 @@ public function addConfiguration(NodeDefinition $node) ->children() ->scalarNode('provider')->end() ->scalarNode('realm')->defaultValue('Secured Area')->end() - ->scalarNode('key')->cannotBeEmpty()->end() + ->scalarNode('key')->isRequired()->cannotBeEmpty()->end() ->end() ; } From e4ebffb01b5be4db17c4ce8bac85082b17b5e0e7 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Wed, 4 Apr 2012 13:13:39 +0200 Subject: [PATCH 08/18] Revert "merged branch ruimarinho/http_digest (PR #3778)" This reverts commit eb6a26f57269d844cf9ef90150e3e0925d5e5bf3, reversing changes made to a10fee16c193d93080c22528e58b1fd018341229. --- .../DependencyInjection/Security/Factory/HttpDigestFactory.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Symfony/Bundle/SecurityBundle/DependencyInjection/Security/Factory/HttpDigestFactory.php b/src/Symfony/Bundle/SecurityBundle/DependencyInjection/Security/Factory/HttpDigestFactory.php index 3a49b5dcdc583..2f09be07afc75 100644 --- a/src/Symfony/Bundle/SecurityBundle/DependencyInjection/Security/Factory/HttpDigestFactory.php +++ b/src/Symfony/Bundle/SecurityBundle/DependencyInjection/Security/Factory/HttpDigestFactory.php @@ -62,7 +62,7 @@ public function addConfiguration(NodeDefinition $node) ->children() ->scalarNode('provider')->end() ->scalarNode('realm')->defaultValue('Secured Area')->end() - ->scalarNode('key')->isRequired()->cannotBeEmpty()->end() + ->scalarNode('key')->cannotBeEmpty()->end() ->end() ; } From fc41d4f2236a26b64c841e9c38ce738de6ff8013 Mon Sep 17 00:00:00 2001 From: Rui Marinho Date: Wed, 4 Apr 2012 11:36:25 +0100 Subject: [PATCH 09/18] [Security] [HttpDigest] Fixes a configuration error caused by an invalid 'key' child node configuration --- .../DependencyInjection/Security/Factory/HttpDigestFactory.php | 2 +- .../Tests/DependencyInjection/Fixtures/php/container1.php | 2 +- .../Tests/DependencyInjection/Fixtures/xml/container1.xml | 2 +- .../Tests/DependencyInjection/Fixtures/yml/container1.yml | 3 ++- 4 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/Symfony/Bundle/SecurityBundle/DependencyInjection/Security/Factory/HttpDigestFactory.php b/src/Symfony/Bundle/SecurityBundle/DependencyInjection/Security/Factory/HttpDigestFactory.php index 2f09be07afc75..3a49b5dcdc583 100644 --- a/src/Symfony/Bundle/SecurityBundle/DependencyInjection/Security/Factory/HttpDigestFactory.php +++ b/src/Symfony/Bundle/SecurityBundle/DependencyInjection/Security/Factory/HttpDigestFactory.php @@ -62,7 +62,7 @@ public function addConfiguration(NodeDefinition $node) ->children() ->scalarNode('provider')->end() ->scalarNode('realm')->defaultValue('Secured Area')->end() - ->scalarNode('key')->cannotBeEmpty()->end() + ->scalarNode('key')->isRequired()->cannotBeEmpty()->end() ->end() ; } diff --git a/src/Symfony/Bundle/SecurityBundle/Tests/DependencyInjection/Fixtures/php/container1.php b/src/Symfony/Bundle/SecurityBundle/Tests/DependencyInjection/Fixtures/php/container1.php index 20792c7754b4f..f5ef9728383e7 100644 --- a/src/Symfony/Bundle/SecurityBundle/Tests/DependencyInjection/Fixtures/php/container1.php +++ b/src/Symfony/Bundle/SecurityBundle/Tests/DependencyInjection/Fixtures/php/container1.php @@ -48,7 +48,7 @@ 'simple' => array('pattern' => '/login', 'security' => false), 'secure' => array('stateless' => true, 'http_basic' => true, - 'http_digest' => true, + 'http_digest' => array('key' => 'TheKey'), 'form_login' => true, 'anonymous' => true, 'switch_user' => true, diff --git a/src/Symfony/Bundle/SecurityBundle/Tests/DependencyInjection/Fixtures/xml/container1.xml b/src/Symfony/Bundle/SecurityBundle/Tests/DependencyInjection/Fixtures/xml/container1.xml index c9fb6618a118d..7dbdb5480ec99 100644 --- a/src/Symfony/Bundle/SecurityBundle/Tests/DependencyInjection/Fixtures/xml/container1.xml +++ b/src/Symfony/Bundle/SecurityBundle/Tests/DependencyInjection/Fixtures/xml/container1.xml @@ -41,7 +41,7 @@ - + diff --git a/src/Symfony/Bundle/SecurityBundle/Tests/DependencyInjection/Fixtures/yml/container1.yml b/src/Symfony/Bundle/SecurityBundle/Tests/DependencyInjection/Fixtures/yml/container1.yml index 8cb2e8c158732..dbfabbf5a12e1 100644 --- a/src/Symfony/Bundle/SecurityBundle/Tests/DependencyInjection/Fixtures/yml/container1.yml +++ b/src/Symfony/Bundle/SecurityBundle/Tests/DependencyInjection/Fixtures/yml/container1.yml @@ -35,7 +35,8 @@ security: secure: stateless: true http_basic: true - http_digest: true + http_digest: + key: TheKey form_login: true anonymous: true switch_user: true From f7647f93252ee8c33d87806fe1ba595ec386817a Mon Sep 17 00:00:00 2001 From: Hugo Hamon Date: Fri, 6 Apr 2012 10:49:41 +0200 Subject: [PATCH 10/18] [Routing] improved exception message when giving an invalid route name. --- src/Symfony/Component/Routing/RouteCollection.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Symfony/Component/Routing/RouteCollection.php b/src/Symfony/Component/Routing/RouteCollection.php index 8224a7ae5fbf6..1effea5684ac4 100644 --- a/src/Symfony/Component/Routing/RouteCollection.php +++ b/src/Symfony/Component/Routing/RouteCollection.php @@ -95,7 +95,7 @@ public function getIterator() public function add($name, Route $route) { if (!preg_match('/^[a-z0-9A-Z_.]+$/', $name)) { - throw new \InvalidArgumentException(sprintf('Name "%s" contains non valid characters for a route name.', $name)); + throw new \InvalidArgumentException(sprintf('The provided route name "%s" contains non valid characters. A route name must only contain digits (0-9), letters (A-Z), underscores (_) and dots (.).', $name)); } $parent = $this; From 04ae7cc605952f32c44aedf61a292c87c63ef1c6 Mon Sep 17 00:00:00 2001 From: Hugo Hamon Date: Fri, 6 Apr 2012 11:45:36 +0200 Subject: [PATCH 11/18] [Routing] fixed exception message. --- src/Symfony/Component/Routing/RouteCollection.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Symfony/Component/Routing/RouteCollection.php b/src/Symfony/Component/Routing/RouteCollection.php index 1effea5684ac4..0b2955d1631bf 100644 --- a/src/Symfony/Component/Routing/RouteCollection.php +++ b/src/Symfony/Component/Routing/RouteCollection.php @@ -95,7 +95,7 @@ public function getIterator() public function add($name, Route $route) { if (!preg_match('/^[a-z0-9A-Z_.]+$/', $name)) { - throw new \InvalidArgumentException(sprintf('The provided route name "%s" contains non valid characters. A route name must only contain digits (0-9), letters (A-Z), underscores (_) and dots (.).', $name)); + throw new \InvalidArgumentException(sprintf('The provided route name "%s" contains non valid characters. A route name must only contain digits (0-9), letters (a-z and A-Z), underscores (_) and dots (.).', $name)); } $parent = $this; From 97f7b29783e963f2badea3b4ca48ef21d2633d2d Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Fri, 6 Apr 2012 13:44:36 +0200 Subject: [PATCH 12/18] [Console] Avoid outputing \r's in exception messages --- src/Symfony/Component/Console/Application.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Symfony/Component/Console/Application.php b/src/Symfony/Component/Console/Application.php index 752d42198d396..0931549c58fae 100644 --- a/src/Symfony/Component/Console/Application.php +++ b/src/Symfony/Component/Console/Application.php @@ -734,7 +734,7 @@ public function renderException($e, $output) $title = sprintf(' [%s] ', get_class($e)); $len = $strlen($title); $lines = array(); - foreach (explode("\n", $e->getMessage()) as $line) { + foreach (preg_split("{\r?\n}", $e->getMessage()) as $line) { $lines[] = sprintf(' %s ', $line); $len = max($strlen($line) + 4, $len); } From 595cc11251c32c4b86133dd53179d9cd8c6d4228 Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Fri, 6 Apr 2012 13:49:13 +0200 Subject: [PATCH 13/18] [Console] Wrap exception messages to the terminal width to avoid ugly output --- src/Symfony/Component/Console/Application.php | 31 +++++++++++++++++-- .../Component/Console/ApplicationTest.php | 9 ++++++ .../Fixtures/application_renderexception4.txt | 9 ++++++ 3 files changed, 46 insertions(+), 3 deletions(-) create mode 100644 tests/Symfony/Tests/Component/Console/Fixtures/application_renderexception4.txt diff --git a/src/Symfony/Component/Console/Application.php b/src/Symfony/Component/Console/Application.php index 0931549c58fae..cac6f80e55590 100644 --- a/src/Symfony/Component/Console/Application.php +++ b/src/Symfony/Component/Console/Application.php @@ -733,13 +733,16 @@ public function renderException($e, $output) do { $title = sprintf(' [%s] ', get_class($e)); $len = $strlen($title); + $width = $this->getTerminalWidth() ? $this->getTerminalWidth() - 1 : PHP_INT_MAX; $lines = array(); foreach (preg_split("{\r?\n}", $e->getMessage()) as $line) { - $lines[] = sprintf(' %s ', $line); - $len = max($strlen($line) + 4, $len); + foreach (str_split($line, $width - 4) as $line) { + $lines[] = sprintf(' %s ', $line); + $len = max($strlen($line) + 4, $len); + } } - $messages = array(str_repeat(' ', $len), $title.str_repeat(' ', $len - $strlen($title))); + $messages = array(str_repeat(' ', $len), $title.str_repeat(' ', max(0, $len - $strlen($title)))); foreach ($lines as $line) { $messages[] = $line.str_repeat(' ', $len - $strlen($line)); @@ -786,6 +789,28 @@ public function renderException($e, $output) } } + protected function getTerminalWidth() + { + if (defined('PHP_WINDOWS_VERSION_BUILD') && $ansicon = getenv('ANSICON')) { + return preg_replace('{^(\d+)x.*$}', '$1', $ansicon); + } + + if (preg_match("{rows.(\d+);.columns.(\d+);}i", exec('stty -a | grep columns'), $match)) { + return $match[1]; + } + } + + protected function getTerminalHeight() + { + if (defined('PHP_WINDOWS_VERSION_BUILD') && $ansicon = getenv('ANSICON')) { + return preg_replace('{^\d+x\d+ \(\d+x(\d+)\)$}', '$1', trim($ansicon)); + } + + if (preg_match("{rows.(\d+);.columns.(\d+);}i", exec('stty -a | grep columns'), $match)) { + return $match[2]; + } + } + /** * Gets the name of the command based on input. * diff --git a/tests/Symfony/Tests/Component/Console/ApplicationTest.php b/tests/Symfony/Tests/Component/Console/ApplicationTest.php index 28aa3d2d4eaba..f5f0fcb938ab9 100644 --- a/tests/Symfony/Tests/Component/Console/ApplicationTest.php +++ b/tests/Symfony/Tests/Component/Console/ApplicationTest.php @@ -255,6 +255,15 @@ public function testRenderException() $tester->run(array('command' => 'foo3:bar'), array('decorated' => false)); $this->assertStringEqualsFile(self::$fixturesPath.'/application_renderexception3.txt', $this->normalize($tester->getDisplay()), '->renderException() renders a pretty exceptions with previous exceptions'); + $application = $this->getMock('Symfony\Component\Console\Application', array('getTerminalWidth')); + $application->setAutoExit(false); + $application->expects($this->any()) + ->method('getTerminalWidth') + ->will($this->returnValue(32)); + $tester = new ApplicationTester($application); + + $tester->run(array('command' => 'foo'), array('decorated' => false)); + $this->assertStringEqualsFile(self::$fixturesPath.'/application_renderexception4.txt', $this->normalize($tester->getDisplay()), '->renderException() wraps messages when they are bigger than the terminal'); } public function testRun() diff --git a/tests/Symfony/Tests/Component/Console/Fixtures/application_renderexception4.txt b/tests/Symfony/Tests/Component/Console/Fixtures/application_renderexception4.txt new file mode 100644 index 0000000000000..19f893b0c8528 --- /dev/null +++ b/tests/Symfony/Tests/Component/Console/Fixtures/application_renderexception4.txt @@ -0,0 +1,9 @@ + + + + [InvalidArgumentException] + Command "foo" is not define + d. + + + From 8a2b115824e8b7c142e864b37a578944d402d068 Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Fri, 6 Apr 2012 18:24:40 +0200 Subject: [PATCH 14/18] [Console] Mock terminal size to prevent formatting errors on small terminals --- .../Tests/Component/Console/ApplicationTest.php | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/tests/Symfony/Tests/Component/Console/ApplicationTest.php b/tests/Symfony/Tests/Component/Console/ApplicationTest.php index f5f0fcb938ab9..4282c2368f766 100644 --- a/tests/Symfony/Tests/Component/Console/ApplicationTest.php +++ b/tests/Symfony/Tests/Component/Console/ApplicationTest.php @@ -201,8 +201,11 @@ public function testFind() public function testSetCatchExceptions() { - $application = new Application(); + $application = $this->getMock('Symfony\Component\Console\Application', array('getTerminalWidth')); $application->setAutoExit(false); + $application->expects($this->any()) + ->method('getTerminalWidth') + ->will($this->returnValue(120)); $tester = new ApplicationTester($application); $application->setCatchExceptions(true); @@ -237,8 +240,11 @@ public function testAsXml() public function testRenderException() { - $application = new Application(); + $application = $this->getMock('Symfony\Component\Console\Application', array('getTerminalWidth')); $application->setAutoExit(false); + $application->expects($this->any()) + ->method('getTerminalWidth') + ->will($this->returnValue(120)); $tester = new ApplicationTester($application); $tester->run(array('command' => 'foo'), array('decorated' => false)); From 7ce22f0cefa38e0ff171ae1678f99082c3e47107 Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Fri, 6 Apr 2012 18:25:51 +0200 Subject: [PATCH 15/18] [Console] Add docblocks --- src/Symfony/Component/Console/Application.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/Symfony/Component/Console/Application.php b/src/Symfony/Component/Console/Application.php index cac6f80e55590..db574589dbc11 100644 --- a/src/Symfony/Component/Console/Application.php +++ b/src/Symfony/Component/Console/Application.php @@ -789,6 +789,11 @@ public function renderException($e, $output) } } + /** + * Tries to figure out the terminal width in which this application runs + * + * @return int|null + */ protected function getTerminalWidth() { if (defined('PHP_WINDOWS_VERSION_BUILD') && $ansicon = getenv('ANSICON')) { @@ -800,6 +805,11 @@ protected function getTerminalWidth() } } + /** + * Tries to figure out the terminal height in which this application runs + * + * @return int|null + */ protected function getTerminalHeight() { if (defined('PHP_WINDOWS_VERSION_BUILD') && $ansicon = getenv('ANSICON')) { From 6bd64b55382de7045457a73be76202de51232779 Mon Sep 17 00:00:00 2001 From: Juti Noppornpitak Date: Fri, 6 Apr 2012 21:34:16 -0400 Subject: [PATCH 16/18] Reverted the position. --- .../Resources/views/Profiler/toolbar.html.twig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Profiler/toolbar.html.twig b/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Profiler/toolbar.html.twig index 62dda911b364f..c7225548b1de9 100644 --- a/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Profiler/toolbar.html.twig +++ b/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Profiler/toolbar.html.twig @@ -9,7 +9,7 @@ background-image: -moz-linear-gradient(-90deg, #e4e4e4, #ffffff); background-image: -webkit-gradient(linear, 0% 0%, 0% 100%, from(#e4e4e4), to(#ffffff)); bottom: 0px; - left:95%; + left: 0; margin:0; padding: 0; z-index: 6000000; From 420e00b8d048f1c6df3fb6c57f728d6388c62e1d Mon Sep 17 00:00:00 2001 From: Juti Noppornpitak Date: Sat, 7 Apr 2012 12:03:40 -0400 Subject: [PATCH 17/18] Revamped the profiler toolbar in both embedded mode and normal. --- .../Resources/public/css/toolbar.css | 65 ++++++++++++++++ .../views/Collector/config.html.twig | 57 +++++++++----- .../views/Collector/memory.html.twig | 4 +- .../views/Collector/request.html.twig | 12 +-- .../Resources/views/Collector/timer.html.twig | 4 +- .../views/Profiler/toolbar.html.twig | 74 ++++++++++++++++--- .../views/Profiler/toolbar_item.html.twig | 4 +- 7 files changed, 181 insertions(+), 39 deletions(-) diff --git a/src/Symfony/Bundle/WebProfilerBundle/Resources/public/css/toolbar.css b/src/Symfony/Bundle/WebProfilerBundle/Resources/public/css/toolbar.css index 504e3fe5081a8..dde17cc785ce6 100644 --- a/src/Symfony/Bundle/WebProfilerBundle/Resources/public/css/toolbar.css +++ b/src/Symfony/Bundle/WebProfilerBundle/Resources/public/css/toolbar.css @@ -7,6 +7,10 @@ build: 56 */ .sf-toolbarreset div,.sf-toolbarreset dl,.sf-toolbarreset dt,.sf-toolbarreset dd,.sf-toolbarreset ul,.sf-toolbarreset ol,.sf-toolbarreset li,.sf-toolbarreset h1,.sf-toolbarreset h2,.sf-toolbarreset h3,.sf-toolbarreset h4,.sf-toolbarreset h5,.sf-toolbarreset h6,.sf-toolbarreset pre,.sf-toolbarreset code,.sf-toolbarreset form,.sf-toolbarreset fieldset,.sf-toolbarreset legend,.sf-toolbarreset input,.sf-toolbarreset textarea,.sf-toolbarreset p,.sf-toolbarreset blockquote,.sf-toolbarreset th,.sf-toolbarreset td{margin:0;padding:0;}.sf-toolbarreset table{border-collapse:collapse;border-spacing:0;}.sf-toolbarreset fieldset,.sf-toolbarreset img{border:0;}.sf-toolbarreset address,.sf-toolbarreset caption,.sf-toolbarreset cite,.sf-toolbarreset code,.sf-toolbarreset dfn,.sf-toolbarreset em,.sf-toolbarreset strong,.sf-toolbarreset th,.sf-toolbarreset var{font-style:normal;font-weight:normal;}.sf-toolbarreset li{list-style:none;}.sf-toolbarreset caption,.sf-toolbarreset th{text-align:left;}.sf-toolbarreset h1,.sf-toolbarreset h2,.sf-toolbarreset h3,.sf-toolbarreset h4,.sf-toolbarreset h5,.sf-toolbarreset h6{font-size:100%;font-weight:normal;}.sf-toolbarreset q:before,.sf-toolbarreset q:after{content:'';}.sf-toolbarreset abbr,.sf-toolbarreset acronym{border:0;font-variant:normal;}.sf-toolbarreset sup{vertical-align:text-top;}.sf-toolbarreset sub{vertical-align:text-bottom;}.sf-toolbarreset input,.sf-toolbarreset textarea,.sf-toolbarreset select{font-family:inherit;font-size:inherit;font-weight:inherit;}.sf-toolbarreset input,.sf-toolbarreset textarea,.sf-toolbarreset select{*font-size:100%;}.sf-toolbarreset legend{color:#000;} +/* +Style for the toolbar in the profiler page. +*/ + .sf-toolbarreset { background: #cbcbcb; background-image: -moz-linear-gradient(-90deg, #e8e8e8, #cbcbcb); @@ -20,9 +24,70 @@ build: 56 margin: 0; font: 11px Verdana, Arial, sans-serif; color: #000; + min-height: 38px; } .sf-toolbarreset abbr { border-bottom: 1px dotted #000000; cursor: help; } + +.sf-toolbar-block { + float: left; + white-space: nowrap; + color: #2f2f2f; + display: inline-block; + min-height: 24px; + min-width: 28px; + text-align: center; + border-right: 1px solid #cdcdcd; + padding: 5px 4px; +} + +.sf-toolbar-block img { + border-width: 0; + vertical-align: middle; + margin: 0; + padding: 0; +} + +.sf-toolbar-block-info { + -moz-transition: all ease 200ms; + -webkit-transition: all ease 200ms; + margin-left: -5px; + top: 38px; + display: none; + padding: 10px; + position: absolute; + background-color: rgba(255, 255, 255, 0.95); + border-left: 1px solid #000; + border-bottom: 1px solid #cdcdcd; + border-right: 1px solid #cdcdcd; +} + +.sf-toolbar-block-info a, .sf-toolbar-block-info a:link { + color: #215498; +} + +.sf-toolbar-block-info-delimiter { + margin: 0 2px; + padding: 0; + color: #ccc; +} + +.sf-toolbar-block-icon { + text-decoration: none; + margin: 0; + padding: 0; + display: inline-block; +} + +.sf-toolbar-block:hover { + background-color: #fff; + border-left: 1px solid #000; + margin-left: -1px; +} + +.sf-toolbar-block:hover .sf-toolbar-block-info { + display: block; +} diff --git a/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Collector/config.html.twig b/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Collector/config.html.twig index b1be93d5d8aa1..e072a12c9fea0 100644 --- a/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Collector/config.html.twig +++ b/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Collector/config.html.twig @@ -9,35 +9,54 @@ {% if verbose %} {% set text %} {% spaceless %} - PHP {{ collector.phpversion }} - | - xdebug - | - accel +
P
+ + PHP {{ collector.phpversion }} + | + xdebug + | + accel + {% endspaceless %} {% endset %} {% include 'WebProfilerBundle:Profiler:toolbar_item.html.twig' with { 'link': false, 'icon': '' } %} {% endif %} {% set icon %} - Environment + Environment {% endset %} {% set text %} {% spaceless %} - {% if verbose %} - {{ collector.appname }} - | - {{ collector.env }} - | - {{ collector.debug ? 'debug' : 'no-debug' }} - | - {% endif %} - - {% if profiler_url %} - {{ collector.token }} - {% else %} - {{ collector.token }} + + {% if verbose %} + {{ collector.appname }} + | + {{ collector.env }} + | + {{ collector.debug ? 'debug' : 'no-debug' }} + | {% endif %} + + {% if profiler_url %} + {{ collector.token }} + {% else %} + {{ collector.token }} + {% endif %} + {% endspaceless %} {% endset %} diff --git a/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Collector/memory.html.twig b/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Collector/memory.html.twig index 4dd4ba6e71218..73d3acdf83f58 100644 --- a/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Collector/memory.html.twig +++ b/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Collector/memory.html.twig @@ -2,10 +2,10 @@ {% block toolbar %} {% set icon %} - Memory Usage + Memory Usage {% endset %} {% set text %} - {{ '%.0f'|format(collector.memory / 1024) }} KB + {{ '%.0f'|format(collector.memory / 1024) }} KB {% endset %} {% include 'WebProfilerBundle:Profiler:toolbar_item.html.twig' with { 'link': false } %} {% endblock %} diff --git a/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Collector/request.html.twig b/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Collector/request.html.twig index c8b71f417c46e..10af551c9b816 100644 --- a/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Collector/request.html.twig +++ b/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Collector/request.html.twig @@ -2,23 +2,25 @@ {% block toolbar %} {% set icon %} - Request + Request {% endset %} {% set text %} + {% spaceless %} {% if collector.controller.class is defined %} {{ collector.controller.class|abbr_class }} :: {% set link = collector.controller.file|file_link(collector.controller.line) %} - {% if link %}{{ collector.controller.method }}{% else %}{{ collector.controller.method }}{% endif %} + {% if link %}{{ collector.controller.method }}{% else %}{{ collector.controller.method }}{% endif %} {% else %} {{ collector.controller }} {% endif %} - | + | {{ collector.route ? collector.route : 'NONE' }} - | - {{ collector.statuscode }} + | + {{ collector.statuscode }} {% endspaceless %} + {% endset %} {% include 'WebProfilerBundle:Profiler:toolbar_item.html.twig' with { 'link': profiler_url } %} {% endblock %} diff --git a/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Collector/timer.html.twig b/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Collector/timer.html.twig index bc734ad3d39d2..743c2942cb03b 100644 --- a/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Collector/timer.html.twig +++ b/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Collector/timer.html.twig @@ -2,10 +2,10 @@ {% block toolbar %} {% set icon %} - Timers + Timers {% endset %} {% set text %} - {{ '%.0f'|format(collector.time * 1000) }} ms + {{ '%.0f'|format(collector.time * 1000) }} ms {% endset %} {% include 'WebProfilerBundle:Profiler:toolbar_item.html.twig' with { 'link': false } %} {% endblock %} diff --git a/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Profiler/toolbar.html.twig b/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Profiler/toolbar.html.twig index c7225548b1de9..4b3e974b803fa 100644 --- a/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Profiler/toolbar.html.twig +++ b/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Profiler/toolbar.html.twig @@ -1,6 +1,10 @@ {% if 'normal' != position %}
{% endif %} diff --git a/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Profiler/toolbar_item.html.twig b/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Profiler/toolbar_item.html.twig index a6d62a47fb68f..21f6cf46ecc72 100644 --- a/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Profiler/toolbar_item.html.twig +++ b/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Profiler/toolbar_item.html.twig @@ -1,9 +1,9 @@ {% if link %} {% set icon %} - {{ icon }} + {{ icon }} {% endset %} {% endif %} - + {{ icon|default('') }} {{ text|default('') }} From d6a293892f1b80940a865c4090d176726681f0e9 Mon Sep 17 00:00:00 2001 From: Juti Noppornpitak Date: Sat, 7 Apr 2012 23:18:41 -0400 Subject: [PATCH 18/18] minor update to the toolbar. --- .../WebProfilerBundle/Resources/views/Collector/config.html.twig | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Collector/config.html.twig b/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Collector/config.html.twig index e072a12c9fea0..8f4cd40ab25c1 100644 --- a/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Collector/config.html.twig +++ b/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Collector/config.html.twig @@ -23,6 +23,7 @@ font-family: 'Georgia', serif; font-style: italic; cursor: default; + overflow:hidden; ">P
PHP {{ collector.phpversion }}