Merge branch '2.8' into 3.0
* 2.8: [Process] Fix stream_select priority when writing to stdin [Form] NumberToLocalizedStringTransformer should return floats when possible [Form] remove useless code in ChoiceType [DependencyInjection] Enabled alias for service_container Conflicts: src/Symfony/Component/DependencyInjection/Tests/Compiler/ReplaceAliasByActualDefinitionPassTest.php src/Symfony/Component/Form/Extension/Core/Type/ChoiceType.php
This commit is contained in:
commit
c3f0bfe36b
@ -42,6 +42,10 @@ class ReplaceAliasByActualDefinitionPass implements CompilerPassInterface
|
||||
foreach ($container->getAliases() as $id => $alias) {
|
||||
$aliasId = (string) $alias;
|
||||
|
||||
if ('service_container' === $aliasId) {
|
||||
continue;
|
||||
}
|
||||
|
||||
try {
|
||||
$definition = $container->getDefinition($aliasId);
|
||||
} catch (InvalidArgumentException $e) {
|
||||
|
@ -34,6 +34,8 @@ class ReplaceAliasByActualDefinitionPassTest extends \PHPUnit_Framework_TestCase
|
||||
$container->setAlias('a_alias', 'a');
|
||||
$container->setAlias('b_alias', 'b');
|
||||
|
||||
$container->setAlias('container', 'service_container');
|
||||
|
||||
$this->process($container);
|
||||
|
||||
$this->assertTrue($container->has('a'), '->process() does nothing to public definitions.');
|
||||
@ -44,6 +46,8 @@ class ReplaceAliasByActualDefinitionPassTest extends \PHPUnit_Framework_TestCase
|
||||
'->process() replaces alias to actual.'
|
||||
);
|
||||
|
||||
$this->assertTrue($container->has('container'));
|
||||
|
||||
$resolvedFactory = $aDefinition->getFactory(false);
|
||||
$this->assertSame('b_alias', (string) $resolvedFactory[0]);
|
||||
}
|
||||
|
@ -181,6 +181,10 @@ class NumberToLocalizedStringTransformer implements DataTransformerInterface
|
||||
throw new TransformationFailedException('I don\'t have a clear idea what infinity looks like');
|
||||
}
|
||||
|
||||
if (is_int($result) && $result === (int) $float = (float) $result) {
|
||||
$result = $float;
|
||||
}
|
||||
|
||||
if (false !== $encoding = mb_detect_encoding($value, null, true)) {
|
||||
$length = mb_strlen($value, $encoding);
|
||||
$remainder = mb_substr($value, $position, $length, $encoding);
|
||||
|
@ -346,7 +346,7 @@ class ChoiceType extends AbstractType
|
||||
$resolver->setAllowedTypes('choice_value', array('null', 'callable', 'string', 'Symfony\Component\PropertyAccess\PropertyPath'));
|
||||
$resolver->setAllowedTypes('choice_attr', array('null', 'array', 'callable', 'string', 'Symfony\Component\PropertyAccess\PropertyPath'));
|
||||
$resolver->setAllowedTypes('preferred_choices', array('array', '\Traversable', 'callable', 'string', 'Symfony\Component\PropertyAccess\PropertyPath'));
|
||||
$resolver->setAllowedTypes('group_by', array('null', 'array', '\Traversable', 'callable', 'string', 'Symfony\Component\PropertyAccess\PropertyPath'));
|
||||
$resolver->setAllowedTypes('group_by', array('null', 'callable', 'string', 'Symfony\Component\PropertyAccess\PropertyPath'));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -429,12 +429,6 @@ class ChoiceType extends AbstractType
|
||||
|
||||
private function createChoiceListView(ChoiceListInterface $choiceList, array $options)
|
||||
{
|
||||
// If no explicit grouping information is given, use the structural
|
||||
// information from the "choices" option for creating groups
|
||||
if (!$options['group_by'] && $options['choices']) {
|
||||
$options['group_by'] = $options['choices'];
|
||||
}
|
||||
|
||||
return $this->choiceListFactory->createView(
|
||||
$choiceList,
|
||||
$options['preferred_choices'],
|
||||
|
@ -637,10 +637,17 @@ class NumberToLocalizedStringTransformerTest extends \PHPUnit_Framework_TestCase
|
||||
$transformer->reverseTransform("12\xc2\xa0345,678foo");
|
||||
}
|
||||
|
||||
public function testReverseTransformBigint()
|
||||
public function testReverseTransformBigInt()
|
||||
{
|
||||
$transformer = new NumberToLocalizedStringTransformer(null, true);
|
||||
|
||||
$this->assertEquals(PHP_INT_MAX - 1, (int) $transformer->reverseTransform((string) (PHP_INT_MAX - 1)));
|
||||
}
|
||||
|
||||
public function testReverseTransformSmallInt()
|
||||
{
|
||||
$transformer = new NumberToLocalizedStringTransformer(null, true);
|
||||
|
||||
$this->assertSame(1.0, $transformer->reverseTransform('1'));
|
||||
}
|
||||
}
|
||||
|
@ -22,10 +22,9 @@ abstract class AbstractPipes implements PipesInterface
|
||||
public $pipes = array();
|
||||
|
||||
/** @var string */
|
||||
protected $inputBuffer = '';
|
||||
private $inputBuffer = '';
|
||||
/** @var resource|null */
|
||||
protected $input;
|
||||
|
||||
private $input;
|
||||
/** @var bool */
|
||||
private $blocked = true;
|
||||
|
||||
@ -91,9 +90,8 @@ abstract class AbstractPipes implements PipesInterface
|
||||
if (!isset($this->pipes[0])) {
|
||||
return;
|
||||
}
|
||||
|
||||
$e = array();
|
||||
$r = null !== $this->input ? array($this->input) : $e;
|
||||
$input = $this->input;
|
||||
$r = $e = array();
|
||||
$w = array($this->pipes[0]);
|
||||
|
||||
// let's have a look if something changed in streams
|
||||
@ -110,7 +108,7 @@ abstract class AbstractPipes implements PipesInterface
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($r as $input) {
|
||||
if ($input) {
|
||||
for (;;) {
|
||||
$data = fread($input, self::CHUNK_SIZE);
|
||||
if (!isset($data[0])) {
|
||||
@ -124,7 +122,7 @@ abstract class AbstractPipes implements PipesInterface
|
||||
return array($this->pipes[0]);
|
||||
}
|
||||
}
|
||||
if (!isset($data[0]) && feof($input)) {
|
||||
if (feof($input)) {
|
||||
// no more data to read on input resource
|
||||
// use an empty buffer in the next reads
|
||||
$this->input = null;
|
||||
|
@ -158,7 +158,7 @@ class Process
|
||||
$this->setEnv($env);
|
||||
}
|
||||
|
||||
$this->input = $input;
|
||||
$this->setInput($input);
|
||||
$this->setTimeout($timeout);
|
||||
$this->useFileHandles = '\\' === DIRECTORY_SEPARATOR;
|
||||
$this->pty = false;
|
||||
|
@ -80,7 +80,7 @@ class ProcessUtils
|
||||
* @param string $caller The name of method call that validates the input
|
||||
* @param mixed $input The input to validate
|
||||
*
|
||||
* @return string The validated input
|
||||
* @return mixed The validated input
|
||||
*
|
||||
* @throws InvalidArgumentException In case the input is not valid
|
||||
*/
|
||||
@ -90,6 +90,9 @@ class ProcessUtils
|
||||
if (is_resource($input)) {
|
||||
return $input;
|
||||
}
|
||||
if (is_string($input)) {
|
||||
return $input;
|
||||
}
|
||||
if (is_scalar($input)) {
|
||||
return (string) $input;
|
||||
}
|
||||
|
@ -209,6 +209,24 @@ class ProcessTest extends \PHPUnit_Framework_TestCase
|
||||
$this->assertEquals($expectedLength, strlen($p->getErrorOutput()));
|
||||
}
|
||||
|
||||
public function testLiveStreamAsInput()
|
||||
{
|
||||
$stream = fopen('php://memory', 'r+');
|
||||
fwrite($stream, 'hello');
|
||||
rewind($stream);
|
||||
|
||||
$p = $this->getProcess(sprintf('%s -r %s', self::$phpBin, escapeshellarg('stream_copy_to_stream(STDIN, STDOUT);')));
|
||||
$p->setInput($stream);
|
||||
$p->start(function ($type, $data) use ($stream) {
|
||||
if ('hello' === $data) {
|
||||
fclose($stream);
|
||||
}
|
||||
});
|
||||
$p->wait();
|
||||
|
||||
$this->assertSame('hello', $p->getOutput());
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Symfony\Component\Process\Exception\LogicException
|
||||
* @expectedExceptionMessage Input can not be set while the process is running.
|
||||
|
Reference in New Issue
Block a user