diff --git a/src/Symfony/Bridge/Doctrine/Form/ChoiceList/EntityChoiceList.php b/src/Symfony/Bridge/Doctrine/Form/ChoiceList/EntityChoiceList.php index b40777488a..1dbdfb04c8 100644 --- a/src/Symfony/Bridge/Doctrine/Form/ChoiceList/EntityChoiceList.php +++ b/src/Symfony/Bridge/Doctrine/Form/ChoiceList/EntityChoiceList.php @@ -97,7 +97,7 @@ class EntityChoiceList extends ArrayChoiceList * @param QueryBuilder|\Closure $queryBuilder An optional query builder * @param array|\Closure $choices An array of choices or a function returning an array */ - public function __construct(EntityManager $em, $class, $property = null, $queryBuilder = null, $choices = array(), $groupBy = null) + public function __construct(EntityManager $em, $class, $property = null, $queryBuilder = null, $choices = null, $groupBy = null) { // If a query builder was passed, it must be a closure or QueryBuilder // instance @@ -126,7 +126,11 @@ class EntityChoiceList extends ArrayChoiceList $this->propertyPath = new PropertyPath($property); } - parent::__construct($choices); + if (!is_array($choices) && !$choices instanceof \Closure && !is_null($choices)) { + throw new UnexpectedTypeException($choices, 'array or \Closure or null'); + } + + $this->choices = $choices; } /** @@ -144,7 +148,7 @@ class EntityChoiceList extends ArrayChoiceList { parent::load(); - if ($this->choices) { + if (is_array($this->choices)) { $entities = $this->choices; } else if ($qb = $this->queryBuilder) { $entities = $qb->getQuery()->execute(); diff --git a/src/Symfony/Bridge/Doctrine/Form/Type/EntityType.php b/src/Symfony/Bridge/Doctrine/Form/Type/EntityType.php index 81f6657f00..c641563b58 100644 --- a/src/Symfony/Bridge/Doctrine/Form/Type/EntityType.php +++ b/src/Symfony/Bridge/Doctrine/Form/Type/EntityType.php @@ -47,7 +47,7 @@ class EntityType extends AbstractType 'class' => null, 'property' => null, 'query_builder' => null, - 'choices' => array(), + 'choices' => null, 'group_by' => null, ); diff --git a/src/Symfony/Bundle/FrameworkBundle/Controller/ControllerResolver.php b/src/Symfony/Bundle/FrameworkBundle/Controller/ControllerResolver.php index 69c5556f88..317e98f753 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Controller/ControllerResolver.php +++ b/src/Symfony/Bundle/FrameworkBundle/Controller/ControllerResolver.php @@ -58,7 +58,7 @@ class ControllerResolver extends BaseControllerResolver $controller = $this->parser->parse($controller); } elseif (1 == $count) { // controller in the service:method notation - list($service, $method) = explode(':', $controller); + list($service, $method) = explode(':', $controller, 2); return array($this->container->get($service), $method); } else { @@ -66,7 +66,7 @@ class ControllerResolver extends BaseControllerResolver } } - list($class, $method) = explode('::', $controller); + list($class, $method) = explode('::', $controller, 2); if (!class_exists($class)) { throw new \InvalidArgumentException(sprintf('Class "%s" does not exist.', $class)); diff --git a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php index 14895bccc5..33ea63885a 100644 --- a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php +++ b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php @@ -209,7 +209,7 @@ class FrameworkExtension extends Extension 'file' => 'Symfony\Component\HttpKernel\Profiler\FileProfilerStorage', 'mongodb' => 'Symfony\Component\HttpKernel\Profiler\MongoDbProfilerStorage', ); - list($class, ) = explode(':', $config['dsn']); + list($class, ) = explode(':', $config['dsn'], 2); if (!isset($supported[$class])) { throw new \LogicException(sprintf('Driver "%s" is not supported for the profiler.', $class)); } @@ -526,7 +526,7 @@ class FrameworkExtension extends Extension })->in($dirs); foreach ($finder as $file) { // filename is domain.locale.format - list($domain, $locale, $format) = explode('.', $file->getBasename()); + list($domain, $locale, $format) = explode('.', $file->getBasename(), 3); $translator->addMethodCall('addResource', array($format, (string) $file, $locale, $domain)); } diff --git a/src/Symfony/Bundle/FrameworkBundle/Templating/Helper/CodeHelper.php b/src/Symfony/Bundle/FrameworkBundle/Templating/Helper/CodeHelper.php index b2f9d2d4b3..8d62401829 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Templating/Helper/CodeHelper.php +++ b/src/Symfony/Bundle/FrameworkBundle/Templating/Helper/CodeHelper.php @@ -86,7 +86,7 @@ class CodeHelper extends Helper public function abbrMethod($method) { if (false !== strpos($method, '::')) { - list($class, $method) = explode('::', $method); + list($class, $method) = explode('::', $method, 2); $result = sprintf("%s::%s()", $this->abbrClass($class), $method); } else if ('Closure' === $method) { $result = sprintf("%s", $method, $method); diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Templating/Helper/Fixtures/StubTemplateNameParser.php b/src/Symfony/Bundle/FrameworkBundle/Tests/Templating/Helper/Fixtures/StubTemplateNameParser.php index e42a1a5471..3a66454947 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/Templating/Helper/Fixtures/StubTemplateNameParser.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Templating/Helper/Fixtures/StubTemplateNameParser.php @@ -28,7 +28,7 @@ class StubTemplateNameParser implements TemplateNameParserInterface public function parse($name) { - list($bundle, $controller, $template) = explode(':', $name); + list($bundle, $controller, $template) = explode(':', $name, 3); if ($template[0] == '_') { $path = $this->rootTheme.'/Custom/'.$template; diff --git a/src/Symfony/Component/HttpFoundation/RequestMatcher.php b/src/Symfony/Component/HttpFoundation/RequestMatcher.php index d5e615e4c6..23950c1dd8 100644 --- a/src/Symfony/Component/HttpFoundation/RequestMatcher.php +++ b/src/Symfony/Component/HttpFoundation/RequestMatcher.php @@ -172,7 +172,7 @@ class RequestMatcher implements RequestMatcherInterface protected function checkIp4($requestIp, $ip) { if (false !== strpos($ip, '/')) { - list($address, $netmask) = explode('/', $ip); + list($address, $netmask) = explode('/', $ip, 2); if ($netmask < 1 || $netmask > 32) { return false; @@ -202,7 +202,7 @@ class RequestMatcher implements RequestMatcherInterface throw new \RuntimeException('Unable to check Ipv6. Check that PHP was not compiled with option "disable-ipv6".'); } - list($address, $netmask) = explode('/', $ip); + list($address, $netmask) = explode('/', $ip, 2); $bytesAddr = unpack("n*", inet_pton($address)); $bytesTest = unpack("n*", inet_pton($requestIp)); diff --git a/src/Symfony/Component/HttpKernel/Controller/ControllerResolver.php b/src/Symfony/Component/HttpKernel/Controller/ControllerResolver.php index d6e5d923be..56d0d6f141 100644 --- a/src/Symfony/Component/HttpKernel/Controller/ControllerResolver.php +++ b/src/Symfony/Component/HttpKernel/Controller/ControllerResolver.php @@ -145,7 +145,7 @@ class ControllerResolver implements ControllerResolverInterface throw new \InvalidArgumentException(sprintf('Unable to find controller "%s".', $controller)); } - list($class, $method) = explode('::', $controller); + list($class, $method) = explode('::', $controller, 2); if (!class_exists($class)) { throw new \InvalidArgumentException(sprintf('Class "%s" does not exist.', $class)); diff --git a/src/Symfony/Component/Validator/Mapping/Loader/FileLoader.php b/src/Symfony/Component/Validator/Mapping/Loader/FileLoader.php index e2f95522ca..6ff0c98a2a 100644 --- a/src/Symfony/Component/Validator/Mapping/Loader/FileLoader.php +++ b/src/Symfony/Component/Validator/Mapping/Loader/FileLoader.php @@ -59,7 +59,7 @@ abstract class FileLoader implements LoaderInterface if (strpos($name, '\\') !== false && class_exists($name)) { $className = (string) $name; } else if (strpos($name, ':') !== false) { - list($prefix, $className) = explode(':', $name); + list($prefix, $className) = explode(':', $name, 2); if (!isset($this->namespaces[$prefix])) { throw new MappingException(sprintf('Undefined namespace prefix "%s"', $prefix)); diff --git a/tests/Symfony/Tests/Bridge/Doctrine/Form/ChoiceList/EntityChoiceListTest.php b/tests/Symfony/Tests/Bridge/Doctrine/Form/ChoiceList/EntityChoiceListTest.php index db5cf0dc06..d37e0cf946 100644 --- a/tests/Symfony/Tests/Bridge/Doctrine/Form/ChoiceList/EntityChoiceListTest.php +++ b/tests/Symfony/Tests/Bridge/Doctrine/Form/ChoiceList/EntityChoiceListTest.php @@ -92,6 +92,26 @@ class EntityChoiceListTest extends DoctrineOrmTestCase $this->assertSame(array(1 => 'Foo', 2 => 'Bar'), $choiceList->getChoices()); } + public function testEmptyChoicesAreManaged() + { + $entity1 = new SingleIdentEntity(1, 'Foo'); + $entity2 = new SingleIdentEntity(2, 'Bar'); + + // Persist for managed state + $this->em->persist($entity1); + $this->em->persist($entity2); + + $choiceList = new EntityChoiceList( + $this->em, + self::SINGLE_IDENT_CLASS, + 'name', + null, + array() + ); + + $this->assertSame(array(), $choiceList->getChoices()); + } + public function testNestedChoicesAreManaged() { $entity1 = new SingleIdentEntity(1, 'Foo');