10000 merged 2.0 · symfony/symfony@a6cdddd · GitHub
[go: up one dir, main page]

Skip to content

Commit a6cdddd

Browse files
committed
merged 2.0
2 parents cfe2640 + 9641c55 commit a6cdddd

File tree

10 files changed

+38
-14
lines changed

10 files changed

+38
-14
lines changed

src/Symfony/Bridge/Doctrine/Form/ChoiceList/EntityChoiceList.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ class EntityChoiceList extends ArrayChoiceList
9797
* @param QueryBuilder|\Closure $queryBuilder An optional query builder
9898
* @param array|\Closure $choices An array of choices or a function returning an array
9999
*/
100-
public function __construct(EntityManager $em, $class, $property = null, $queryBuilder = null, $choices = array(), $groupBy = null)
100+
public function __construct(EntityManager $em, $class, $property = null, $queryBuilder = null, $choices = null, $groupBy = null)
101101
{
102102
// If a query builder was passed, it must be a closure or QueryBuilder
103103
// instance
@@ -126,7 +126,11 @@ public function __construct(EntityManager $em, $class, $property = null, $queryB
126126
$this->propertyPath = new PropertyPath($property);
127127
}
128128

129-
parent::__construct($choices);
129+
if (!is_array($choices) && !$choices instanceof \Closure && !is_null($choices)) {
130+
throw new UnexpectedTypeException($choices, 'array or \Closure or null');
131+
}
132+
133+
$this->choices = $choices;
130134
}
131135

132136
/**
@@ -144,7 +148,7 @@ protected function load()
144148
{
145149
parent::load();
146150

147-
if ($this->choices) {
151+
if (is_array($this->choices)) {
148152
$entities = $this->choices;
149153
} else if ($qb = $this->queryBuilder) {
150154
$entities = $qb->getQuery()->execute();

src/Symfony/Bridge/Doctrine/Form/Type/EntityType.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public function getDefaultOptions(array $options)
4747
'class' => null,
4848
'property' => null,
4949
'query_builder' => null,
50-
'choices' => array(),
50+
'choices' => null,
5151
'group_by' => null,
5252
);
5353

src/Symfony/Bundle/FrameworkBundle/Controller/ControllerResolver.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,15 +58,15 @@ protected function createController($controller)
5858
$controller = $this->parser->parse($controller);
5959
} elseif (1 == $count) {
6060
// controller in the service:method notation
61-
list($service, $method) = explode(':', $controller);
61+
list($service, $method) = explode(':', $controller, 2);
6262

6363
return array($this->container->get($service), $method);
6464
} else {
6565
throw new \LogicException(sprintf('Unable to parse the controller name "%s".', $controller));
6666
}
6767
}
6868

69-
list($class, $method) = explode('::', $controller);
69+
list($class, $method) = explode('::', $controller, 2);
7070

7171
if (!class_exists($class)) {
7272
throw new \InvalidArgumentException(sprintf('Class "%s" does not exist.', $class));

src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ private function registerProfilerConfiguration(array $config, ContainerBuilder $
209209
'file' => 'Symfony\Component\HttpKernel\Profiler\FileProfilerStorage',
210210
'mongodb' => 'Symfony\Component\HttpKernel\Profiler\MongoDbProfilerStorage',
211211
);
212-
list($class, ) = explode(':', $config['dsn']);
212+
list($class, ) = explode(':', $config['dsn'], 2);
213213
if (!isset($supported[$class])) {
214214
throw new \LogicException(sprintf('Driver "%s" is not supported for the profiler.', $class));
215215
}
@@ -526,7 +526,7 @@ private function registerTranslatorConfiguration(array $config, ContainerBuilder
526526
})->in($dirs);
527527
foreach ($finder as $file) {
528528
// filename is domain.locale.format
529-
list($domain, $locale, $format) = explode('.', $file->getBasename());
529+
list($domain, $locale, $format) = explode('.', $file->getBasename(), 3);
530530

531531
$translator->addMethodCall('addResource', array($format, (string) $file, $locale, $domain));
532532
}

src/Symfony/Bundle/FrameworkBundle/Templating/Helper/CodeHelper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ public function abbrClass($class)
8686
public function abbrMethod($method)
8787
{
8888
if (false !== strpos($method, '::')) {
89-
list($class, $method) = explode('::', $method);
89+
list($class, $method) = explode('::', $method, 2);
9090
$result = sprintf("%s::%s()", $this->abbrClass($class), $method);
9191
} else if ('Closure' === $method) {
9292
$result = sprintf("<abbr title=\"%s\">%s</abbr>", $method, $method);

src/Symfony/Bundle/FrameworkBundle/Tests/Templating/Helper/Fixtures/StubTemplateNameParser.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public function __construct($root, $rootTheme)
2828

2929
public function parse($name)
3030
{
31-
list($bundle, $controller, $template) = explode(':', $name);
31+
list($bundle, $controller, $template) = explode(':', $name, 3);
3232

3333
if ($template[0] == '_') {
3434
$path = $this->rootTheme.'/Custom/'.$template;

src/Symfony/Component/HttpFoundation/RequestMatcher.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ protected function checkIp($requestIp, $ip)
172172
protected function checkIp4($requestIp, $ip)
173173
{
174174
if (false !== strpos($ip, '/')) {
175-
list($address, $netmask) = explode('/', $ip);
175+
list($address, $netmask) = explode('/', $ip, 2);
176176

177177
if ($netmask < 1 || $netmask > 32) {
178178
return false;
@@ -202,7 +202,7 @@ protected function checkIp6($requestIp, $ip)
202202
throw new \RuntimeException('Unable to check Ipv6. Check that PHP was not compiled with option "disable-ipv6".');
203203
}
204204

205-
list($address, $netmask) = explode('/', $ip);
205+
list($address, $netmask) = explode('/', $ip, 2);
206206

207207
$bytesAddr = unpack("n*", inet_pton($address));
208208
$bytesTest = unpack("n*", inet_pton($requestIp));

src/Symfony/Component/HttpKernel/Controller/ControllerResolver.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ protected function createController($controller)
145145
throw new \InvalidArgumentException(sprintf('Unable to find controller "%s".', $controller));
146146
}
147147

148-
list($class, $method) = explode('::', $controller);
148+
list($class, $method) = explode('::', $controller, 2);
149149

150150
if (!class_exists($class)) {
151151
throw new \InvalidArgumentException(sprintf('Class "%s" does not exist.', $class));

src/Symfony/Component/Validator/Mapping/Loader/FileLoader.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ protected function newConstraint($name, $options)
5959
if (strpos($name, '\\') !== false && class_exists($name)) {
6060
$className = (string) $name;
6161
} else if (strpos($name, ':') !== false) {
62-
list($prefix, $className) = explode(':', $name);
62+
list($prefix, $className) = explode(':', $name, 2);
6363

6464
if (!isset($this->namespaces[$prefix])) {
6565
throw new MappingException(sprintf('Undefined namespace prefix "%s"', $prefix));

tests/Symfony/Tests/Bridge/Doctrine/Form/ChoiceList/EntityChoiceListTest.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,26 @@ public function testFlattenedChoicesAreManaged()
9292
$this->assertSame(array(1 => 'Foo', 2 => 'Bar'), $choiceList->getChoices());
9393
}
9494

95+
public function testEmptyChoicesAreManaged()
96+
{
97+
$entity1 = new SingleIdentEntity(1, 'Foo');
98+
$entity2 = new SingleIdentEntity(2, 'Bar');
99+
100+
// Persist for managed state
101+
$this->em->persist($entity1);
102+
$this->em->persist($entity2);
103+
104+
$choiceList = new EntityChoiceList(
105+
$this->em,
106+
self::SINGLE_IDENT_CLASS,
107+
'name',
108+
null,
109+
array()
110+
);
111+
112+
$this->assertSame(array(), $choiceList->getChoices());
113+
}
114+
95115
public function testNestedChoicesAreManaged()
96116
{
97117
$entity1 = new SingleIdentEntity(1, 'Foo');

0 commit comments

Comments
 (0)
0