Merge branch '2.2' into 2.3
* 2.2: Throw exception if value is passed to VALUE_NONE input, long syntax fixed date type format pattern regex [FrameworkBundle] tweaked previous merge (refs #8242) do not re-register commands each time a Console\Application is run [Process] moved env check to the Process class (refs #8227) fix issue where $_ENV contains array vals [DomCrawler] Fix handling file:// without a host [Form] corrected interface bind() method defined against in deprecation notice [Finder] Fix SplFileInfo::getContents isn't working with ssh2 protocol Conflicts: src/Symfony/Component/Console/Tests/Input/ArgvInputTest.php src/Symfony/Component/DomCrawler/Link.php src/Symfony/Component/Form/Form.php
This commit is contained in:
commit
d849d5d134
|
@ -27,6 +27,7 @@ use Symfony\Component\HttpKernel\Bundle\Bundle;
|
||||||
class Application extends BaseApplication
|
class Application extends BaseApplication
|
||||||
{
|
{
|
||||||
private $kernel;
|
private $kernel;
|
||||||
|
private $commandsRegistered = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor.
|
* Constructor.
|
||||||
|
@ -65,7 +66,11 @@ class Application extends BaseApplication
|
||||||
*/
|
*/
|
||||||
public function doRun(InputInterface $input, OutputInterface $output)
|
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'));
|
$this->setDispatcher($this->kernel->getContainer()->get('event_dispatcher'));
|
||||||
|
|
||||||
|
|
|
@ -134,7 +134,7 @@ class ArgvInput extends Input
|
||||||
|
|
||||||
break;
|
break;
|
||||||
} else {
|
} else {
|
||||||
$this->addLongOption($option->getName(), true);
|
$this->addLongOption($option->getName(), null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -220,6 +220,10 @@ class ArgvInput extends Input
|
||||||
$value = null;
|
$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 (null === $value && $option->acceptValue() && count($this->parsed)) {
|
||||||
// if option accepts an optional or mandatory argument
|
// if option accepts an optional or mandatory argument
|
||||||
// let's see if there is one provided
|
// let's see if there is one provided
|
||||||
|
|
|
@ -175,6 +175,11 @@ class ArgvInputTest extends \PHPUnit_Framework_TestCase
|
||||||
new InputDefinition(array(new InputOption('foo', 'f', InputOption::VALUE_NONE))),
|
new InputDefinition(array(new InputOption('foo', 'f', InputOption::VALUE_NONE))),
|
||||||
'The "-o" option does not exist.'
|
'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(
|
||||||
array('cli.php', 'foo', 'bar'),
|
array('cli.php', 'foo', 'bar'),
|
||||||
new InputDefinition(),
|
new InputDefinition(),
|
||||||
|
|
|
@ -125,7 +125,7 @@ class Link
|
||||||
return preg_replace('#^([^/]*)//.*$#', '$1', $this->currentUri).$uri;
|
return preg_replace('#^([^/]*)//.*$#', '$1', $this->currentUri).$uri;
|
||||||
}
|
}
|
||||||
|
|
||||||
$baseUri = preg_replace('#^(.*?//[^/]+)(?:\/.*)?$#', '$1', $this->currentUri);
|
$baseUri = preg_replace('#^(.*?//[^/]*)(?:\/.*)?$#', '$1', $this->currentUri);
|
||||||
|
|
||||||
// absolute path
|
// absolute path
|
||||||
if ('/' === $uri[0]) {
|
if ('/' === $uri[0]) {
|
||||||
|
|
|
@ -122,6 +122,11 @@ class LinkTest extends \PHPUnit_Framework_TestCase
|
||||||
array('../bar/./../../foo', 'http://localhost/bar/foo/', 'http://localhost/foo'),
|
array('../bar/./../../foo', 'http://localhost/bar/foo/', 'http://localhost/foo'),
|
||||||
array('../../', 'http://localhost/', 'http://localhost/'),
|
array('../../', 'http://localhost/', 'http://localhost/'),
|
||||||
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'),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -65,7 +65,7 @@ class SplFileInfo extends \SplFileInfo
|
||||||
public function getContents()
|
public function getContents()
|
||||||
{
|
{
|
||||||
$level = error_reporting(0);
|
$level = error_reporting(0);
|
||||||
$content = file_get_contents($this->getRealpath());
|
$content = file_get_contents($this->getPathname());
|
||||||
error_reporting($level);
|
error_reporting($level);
|
||||||
if (false === $content) {
|
if (false === $content) {
|
||||||
$error = error_get_last();
|
$error = error_get_last();
|
||||||
|
|
|
@ -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)
|
// 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
|
// 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);
|
$pattern = preg_replace(array('/y+/', '/M+/', '/d+/'), array('{{ year }}', '{{ month }}', '{{ day }}'), $pattern);
|
||||||
} else {
|
} else {
|
||||||
// default fallback
|
// default fallback
|
||||||
|
|
|
@ -271,6 +271,29 @@ class DateTypeTest extends TypeTestCase
|
||||||
$this->assertEquals('06*2010*02', $form->getViewData());
|
$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
|
* 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.
|
* as valid IntlDateFormatter constants for FULL, LONG, MEDIUM or SHORT respectively.
|
||||||
|
|
|
@ -147,10 +147,7 @@ class Process
|
||||||
$this->cwd = getcwd();
|
$this->cwd = getcwd();
|
||||||
}
|
}
|
||||||
if (null !== $env) {
|
if (null !== $env) {
|
||||||
$this->env = array();
|
$this->setEnv($env);
|
||||||
foreach ($env as $key => $value) {
|
|
||||||
$this->env[(binary) $key] = (binary) $value;
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
$this->env = null;
|
$this->env = null;
|
||||||
}
|
}
|
||||||
|
@ -942,13 +939,25 @@ class Process
|
||||||
/**
|
/**
|
||||||
* Sets the environment variables.
|
* 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
|
* @param array $env The new environment variables
|
||||||
*
|
*
|
||||||
* @return self The current Process instance
|
* @return self The current Process instance
|
||||||
*/
|
*/
|
||||||
public function setEnv(array $env)
|
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;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
|
@ -45,6 +45,22 @@ class ProcessBuilderTest extends \PHPUnit_Framework_TestCase
|
||||||
$_ENV = $snapshot;
|
$_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()
|
public function testInheritEnvironmentVarsByDefault()
|
||||||
{
|
{
|
||||||
$pb = new ProcessBuilder();
|
$pb = new ProcessBuilder();
|
||||||
|
|
Reference in New Issue