Merge branch '2.7' into 2.8

* 2.7:
  [Console] Do not duplicate Helper::strlen() code
  [FrameworkBundle] Adding the extension XML
  [Form] Minor: Fix comment in ChoiceType
  [FrameworkBundle] AbstractConfigCommand: do not try registering bundles twice
This commit is contained in:
Fabien Potencier 2017-05-11 09:41:12 -07:00
commit 433dfd42a1
4 changed files with 7 additions and 14 deletions

View File

@ -92,7 +92,7 @@ abstract class AbstractConfigCommand extends ContainerDebugCommand
// Re-build bundle manually to initialize DI extensions that can be extended by other bundles in their build() method
// as this method is not called when the container is loaded from the cache.
$container = $this->getContainerBuilder();
$bundles = $this->getContainer()->get('kernel')->registerBundles();
$bundles = $this->getContainer()->get('kernel')->getBundles();
foreach ($bundles as $bundle) {
if ($extension = $bundle->getContainerExtension()) {
$container->registerExtension($extension);

View File

@ -17,6 +17,7 @@
],
"require": {
"php": ">=5.3.9",
"ext-xml": "*",
"symfony/asset": "~2.7|~3.0.0",
"symfony/class-loader": "~2.1|~3.0.0",
"symfony/dependency-injection": "~2.8",

View File

@ -16,6 +16,7 @@ use Symfony\Component\Console\Descriptor\XmlDescriptor;
use Symfony\Component\Console\Exception\ExceptionInterface;
use Symfony\Component\Console\Formatter\OutputFormatter;
use Symfony\Component\Console\Helper\DebugFormatterHelper;
use Symfony\Component\Console\Helper\Helper;
use Symfony\Component\Console\Helper\ProcessHelper;
use Symfony\Component\Console\Helper\QuestionHelper;
use Symfony\Component\Console\Input\InputInterface;
@ -656,7 +657,7 @@ class Application
do {
$title = sprintf(' [%s] ', get_class($e));
$len = $this->stringWidth($title);
$len = Helper::strlen($title);
$width = $this->getTerminalWidth() ? $this->getTerminalWidth() - 1 : PHP_INT_MAX;
// HHVM only accepts 32 bits integer in str_split, even when PHP_INT_MAX is a 64 bit integer: https://github.com/facebook/hhvm/issues/1327
@ -667,7 +668,7 @@ class Application
foreach (preg_split('/\r?\n/', $e->getMessage()) as $line) {
foreach ($this->splitStringByWidth($line, $width - 4) as $line) {
// pre-format lines to get the right string length
$lineLength = $this->stringWidth($line) + 4;
$lineLength = Helper::strlen($line) + 4;
$lines[] = array($line, $lineLength);
$len = max($lineLength, $len);
@ -676,7 +677,7 @@ class Application
$messages = array();
$messages[] = $emptyLine = sprintf('<error>%s</error>', str_repeat(' ', $len));
$messages[] = sprintf('<error>%s%s</error>', $title, str_repeat(' ', max(0, $len - $this->stringWidth($title))));
$messages[] = sprintf('<error>%s%s</error>', $title, str_repeat(' ', max(0, $len - Helper::strlen($title))));
foreach ($lines as $line) {
$messages[] = sprintf('<error> %s %s</error>', OutputFormatter::escape($line[0]), str_repeat(' ', $len - $line[1]));
}
@ -1097,15 +1098,6 @@ class Application
$this->defaultCommand = $commandName;
}
private function stringWidth($string)
{
if (false === $encoding = mb_detect_encoding($string, null, true)) {
return strlen($string);
}
return mb_strwidth($string, $encoding);
}
private function splitStringByWidth($string, $width)
{
// str_split is not suitable for multi-byte characters, we should use preg_split to get char array properly.

View File

@ -162,7 +162,7 @@ class ChoiceType extends AbstractType
}
// To avoid issues when the submitted choices are arrays (i.e. array to string conversions),
// we have to ensure that all elements of the submitted choice data are strings or null.
// we have to ensure that all elements of the submitted choice data are NULL, strings or ints.
$builder->addEventListener(FormEvents::PRE_SUBMIT, function (FormEvent $event) {
$data = $event->getData();