From 0c9b2d47b0ebeb83ce099fe77567fe720e8672ea Mon Sep 17 00:00:00 2001 From: Pierre Minnieur Date: Fri, 9 Mar 2012 10:08:43 +0100 Subject: [PATCH 01/14] 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 d282452629..52dea564ec 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\AnonymousToken; 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 55310122d4..ccda113094 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\Log\LoggerInterface; 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/14] [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 2e2a24a091..2cb84746fa 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Controller/RedirectController.php +++ b/src/Symfony/Bundle/FrameworkBundle/Controller/RedirectController.php @@ -70,6 +70,13 @@ class RedirectController extends ContainerAware 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 @@ class RedirectController extends ContainerAware $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 e90f9dc25a..fdb88c0ec0 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/Controller/RedirectControllerTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Controller/RedirectControllerTest.php @@ -92,15 +92,22 @@ class RedirectControllerTest extends TestCase 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/14] 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 9cb7786129..b40637e9e4 100644 --- a/src/Symfony/Component/HttpFoundation/ServerBag.php +++ b/src/Symfony/Component/HttpFoundation/ServerBag.php @@ -28,7 +28,7 @@ class ServerBag extends ParameterBag } // 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/14] 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 9afd9f8206..713e6d978e 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/14] [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 0faa76736f..bad370e871 100644 --- a/src/Symfony/Component/DependencyInjection/Loader/YamlFileLoader.php +++ b/src/Symfony/Component/DependencyInjection/Loader/YamlFileLoader.php @@ -196,7 +196,8 @@ class YamlFileLoader extends FileLoader 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 93d618d5f5..bbc048cb7f 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 537cc80326..a2593ac239 100644 --- a/tests/Symfony/Tests/Component/DependencyInjection/Loader/YamlFileLoaderTest.php +++ b/tests/Symfony/Tests/Component/DependencyInjection/Loader/YamlFileLoaderTest.php @@ -113,7 +113,7 @@ class YamlFileLoaderTest extends \PHPUnit_Framework_TestCase $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 fd1ea69b78994a787f0b5bf3e6cfc4f48e583864 Mon Sep 17 00:00:00 2001 From: Rui Marinho Date: Wed, 4 Apr 2012 11:36:25 +0100 Subject: [PATCH 06/14] [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 2f09be07af..3a49b5dcdc 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 @@ class HttpDigestFactory implements SecurityFactoryInterface ->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 07/14] 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 3a49b5dcdc..2f09be07af 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 @@ class HttpDigestFactory implements SecurityFactoryInterface ->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 08/14] [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 2f09be07af..3a49b5dcdc 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 @@ class HttpDigestFactory implements SecurityFactoryInterface ->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 20792c7754..f5ef972838 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 @@ $container->loadFromExtension('security', array( '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 c9fb6618a1..7dbdb5480e 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 8cb2e8c158..dbfabbf5a1 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 09/14] [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 8224a7ae5f..1effea5684 100644 --- a/src/Symfony/Component/Routing/RouteCollection.php +++ b/src/Symfony/Component/Routing/RouteCollection.php @@ -95,7 +95,7 @@ class RouteCollection implements \IteratorAggregate 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 10/14] [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 1effea5684..0b2955d163 100644 --- a/src/Symfony/Component/Routing/RouteCollection.php +++ b/src/Symfony/Component/Routing/RouteCollection.php @@ -95,7 +95,7 @@ class RouteCollection implements \IteratorAggregate 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 11/14] [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 752d42198d..0931549c58 100644 --- a/src/Symfony/Component/Console/Application.php +++ b/src/Symfony/Component/Console/Application.php @@ -734,7 +734,7 @@ class Application $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 12/14] [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 0931549c58..cac6f80e55 100644 --- a/src/Symfony/Component/Console/Application.php +++ b/src/Symfony/Component/Console/Application.php @@ -733,13 +733,16 @@ class Application 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 @@ class Application } } + 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 28aa3d2d4e..f5f0fcb938 100644 --- a/tests/Symfony/Tests/Component/Console/ApplicationTest.php +++ b/tests/Symfony/Tests/Component/Console/ApplicationTest.php @@ -255,6 +255,15 @@ class ApplicationTest extends \PHPUnit_Framework_TestCase $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 0000000000..19f893b0c8 --- /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 13/14] [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 f5f0fcb938..4282c2368f 100644 --- a/tests/Symfony/Tests/Component/Console/ApplicationTest.php +++ b/tests/Symfony/Tests/Component/Console/ApplicationTest.php @@ -201,8 +201,11 @@ class ApplicationTest extends \PHPUnit_Framework_TestCase 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 @@ class ApplicationTest extends \PHPUnit_Framework_TestCase 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 14/14] [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 cac6f80e55..db574589db 100644 --- a/src/Symfony/Component/Console/Application.php +++ b/src/Symfony/Component/Console/Application.php @@ -789,6 +789,11 @@ class Application } } + /** + * 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 @@ class Application } } + /** + * 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')) {