diff --git a/src/Symfony/Bundle/FrameworkBundle/Console/Application.php b/src/Symfony/Bundle/FrameworkBundle/Console/Application.php index 06a8698cf1..90d19c60e3 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Console/Application.php +++ b/src/Symfony/Bundle/FrameworkBundle/Console/Application.php @@ -27,6 +27,7 @@ use Symfony\Component\HttpKernel\Bundle\Bundle; class Application extends BaseApplication { private $kernel; + private $commandsRegistered = false; /** * Constructor. @@ -65,7 +66,11 @@ class Application extends BaseApplication */ public function doRun(InputInterface $input, OutputInterface $output) { - $this->registerCommands(); + if (!$this->commandsRegistered) { + $this->registerCommands(); + + $this->commandsRegistered = true; + } $this->setDispatcher($this->kernel->getContainer()->get('event_dispatcher')); diff --git a/src/Symfony/Component/Console/Input/ArgvInput.php b/src/Symfony/Component/Console/Input/ArgvInput.php index 6a4d1d506f..e19f629550 100644 --- a/src/Symfony/Component/Console/Input/ArgvInput.php +++ b/src/Symfony/Component/Console/Input/ArgvInput.php @@ -134,7 +134,7 @@ class ArgvInput extends Input break; } else { - $this->addLongOption($option->getName(), true); + $this->addLongOption($option->getName(), null); } } } @@ -220,6 +220,10 @@ class ArgvInput extends Input $value = null; } + if (null !== $value && !$option->acceptValue()) { + throw new \RuntimeException(sprintf('The "--%s" option does not accept a value.', $name, $value)); + } + if (null === $value && $option->acceptValue() && count($this->parsed)) { // if option accepts an optional or mandatory argument // let's see if there is one provided diff --git a/src/Symfony/Component/Console/Tests/Input/ArgvInputTest.php b/src/Symfony/Component/Console/Tests/Input/ArgvInputTest.php index 8e07c4c558..c6ad757e23 100644 --- a/src/Symfony/Component/Console/Tests/Input/ArgvInputTest.php +++ b/src/Symfony/Component/Console/Tests/Input/ArgvInputTest.php @@ -175,6 +175,11 @@ class ArgvInputTest extends \PHPUnit_Framework_TestCase new InputDefinition(array(new InputOption('foo', 'f', InputOption::VALUE_NONE))), 'The "-o" option does not exist.' ), + array( + array('cli.php', '--foo=bar'), + new InputDefinition(array(new InputOption('foo', 'f', InputOption::VALUE_NONE))), + 'The "--foo" option does not accept a value.' + ), array( array('cli.php', 'foo', 'bar'), new InputDefinition(), diff --git a/src/Symfony/Component/DomCrawler/Link.php b/src/Symfony/Component/DomCrawler/Link.php index 293d4e03f4..d1d1e518da 100644 --- a/src/Symfony/Component/DomCrawler/Link.php +++ b/src/Symfony/Component/DomCrawler/Link.php @@ -125,7 +125,7 @@ class Link return preg_replace('#^([^/]*)//.*$#', '$1', $this->currentUri).$uri; } - $baseUri = preg_replace('#^(.*?//[^/]+)(?:\/.*)?$#', '$1', $this->currentUri); + $baseUri = preg_replace('#^(.*?//[^/]*)(?:\/.*)?$#', '$1', $this->currentUri); // absolute path if ('/' === $uri[0]) { diff --git a/src/Symfony/Component/DomCrawler/Tests/LinkTest.php b/src/Symfony/Component/DomCrawler/Tests/LinkTest.php index 1761470500..136723a668 100644 --- a/src/Symfony/Component/DomCrawler/Tests/LinkTest.php +++ b/src/Symfony/Component/DomCrawler/Tests/LinkTest.php @@ -122,6 +122,11 @@ class LinkTest extends \PHPUnit_Framework_TestCase array('../bar/./../../foo', 'http://localhost/bar/foo/', 'http://localhost/foo'), array('../../', 'http://localhost/', 'http://localhost/'), array('../../', 'http://localhost', 'http://localhost/'), + + array('/foo', 'file:///', 'file:///foo'), + array('/foo', 'file:///bar/baz', 'file:///foo'), + array('foo', 'file:///', 'file:///foo'), + array('foo', 'file:///bar/baz', 'file:///bar/foo'), ); } } diff --git a/src/Symfony/Component/Finder/SplFileInfo.php b/src/Symfony/Component/Finder/SplFileInfo.php index e7e58f757c..d911fe06e8 100644 --- a/src/Symfony/Component/Finder/SplFileInfo.php +++ b/src/Symfony/Component/Finder/SplFileInfo.php @@ -65,7 +65,7 @@ class SplFileInfo extends \SplFileInfo public function getContents() { $level = error_reporting(0); - $content = file_get_contents($this->getRealpath()); + $content = file_get_contents($this->getPathname()); error_reporting($level); if (false === $content) { $error = error_get_last(); diff --git a/src/Symfony/Component/Form/Extension/Core/Type/DateType.php b/src/Symfony/Component/Form/Extension/Core/Type/DateType.php index a4a55a2af5..93d3502e95 100644 --- a/src/Symfony/Component/Form/Extension/Core/Type/DateType.php +++ b/src/Symfony/Component/Form/Extension/Core/Type/DateType.php @@ -144,7 +144,7 @@ class DateType extends AbstractType // set right order with respect to locale (e.g.: de_DE=dd.MM.yy; en_US=M/d/yy) // lookup various formats at http://userguide.icu-project.org/formatparse/datetime - if (preg_match('/^([yMd]+).+([yMd]+).+([yMd]+)$/', $pattern)) { + if (preg_match('/^([yMd]+)[^yMd]*([yMd]+)[^yMd]*([yMd]+)$/', $pattern)) { $pattern = preg_replace(array('/y+/', '/M+/', '/d+/'), array('{{ year }}', '{{ month }}', '{{ day }}'), $pattern); } else { // default fallback diff --git a/src/Symfony/Component/Form/Tests/Extension/Core/Type/DateTypeTest.php b/src/Symfony/Component/Form/Tests/Extension/Core/Type/DateTypeTest.php index da6b4657fa..2aa155e753 100644 --- a/src/Symfony/Component/Form/Tests/Extension/Core/Type/DateTypeTest.php +++ b/src/Symfony/Component/Form/Tests/Extension/Core/Type/DateTypeTest.php @@ -271,6 +271,29 @@ class DateTypeTest extends TypeTestCase $this->assertEquals('06*2010*02', $form->getViewData()); } + /** + * @dataProvider provideDateFormats + */ + public function testDatePatternWithFormatOption($format, $pattern) + { + $form = $this->factory->create('date', null, array( + 'format' => $format, + )); + + $view = $form->createView(); + + $this->assertEquals($pattern, $view->vars['date_pattern']); + } + + public function provideDateFormats() + { + return array( + array('dMy', '{{ day }}{{ month }}{{ year }}'), + array('d-M-yyyy', '{{ day }}-{{ month }}-{{ year }}'), + array('M d y', '{{ month }} {{ day }} {{ year }}'), + ); + } + /** * This test is to check that the strings '0', '1', '2', '3' are no accepted * as valid IntlDateFormatter constants for FULL, LONG, MEDIUM or SHORT respectively. diff --git a/src/Symfony/Component/Process/Process.php b/src/Symfony/Component/Process/Process.php index 4822e8863e..5e812daf57 100644 --- a/src/Symfony/Component/Process/Process.php +++ b/src/Symfony/Component/Process/Process.php @@ -147,10 +147,7 @@ class Process $this->cwd = getcwd(); } if (null !== $env) { - $this->env = array(); - foreach ($env as $key => $value) { - $this->env[(binary) $key] = (binary) $value; - } + $this->setEnv($env); } else { $this->env = null; } @@ -942,13 +939,25 @@ class Process /** * Sets the environment variables. * + * An environment variable value should be a string. + * If it is an array, the variable is ignored. + * + * That happens in PHP when 'argv' is registered into + * the $_ENV array for instance. + * * @param array $env The new environment variables * * @return self The current Process instance */ public function setEnv(array $env) { - $this->env = $env; + // Process can not handle env values that are arrays + $env = array_filter($env, function ($value) { if (!is_array($value)) { return true; } }); + + $this->env = array(); + foreach ($env as $key => $value) { + $this->env[(binary) $key] = (binary) $value; + } return $this; } diff --git a/src/Symfony/Component/Process/Tests/ProcessBuilderTest.php b/src/Symfony/Component/Process/Tests/ProcessBuilderTest.php index 1f95396891..4c88b55ce1 100644 --- a/src/Symfony/Component/Process/Tests/ProcessBuilderTest.php +++ b/src/Symfony/Component/Process/Tests/ProcessBuilderTest.php @@ -45,6 +45,22 @@ class ProcessBuilderTest extends \PHPUnit_Framework_TestCase $_ENV = $snapshot; } + public function testProcessBuilderShouldNotPassEnvArrays() + { + $snapshot = $_ENV; + $_ENV = array('a' => array('b', 'c'), 'd' => 'e', 'f' => 'g'); + $expected = array('d' => 'e', 'f' => 'g'); + + $pb = new ProcessBuilder(); + $pb->add('a')->inheritEnvironmentVariables() + ->setEnv('d', 'e'); + $proc = $pb->getProcess(); + + $this->assertEquals($expected, $proc->getEnv(), '->inheritEnvironmentVariables() removes array values from $_ENV'); + + $_ENV = $snapshot; + } + public function testInheritEnvironmentVarsByDefault() { $pb = new ProcessBuilder();