Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e0eb6d4

Browse files
committed
Merge branch '2.8' into 3.0
* 2.8: Set the redraw frequency at least to 1. Setting it to 0 would otherwise produce an error. [Process] Unset callback after stop to free memory Improve error message for undefined DIC aliases [VarDumper] fixed .sf-dump z-index [Validator] Updated Luxembourgish translations for 2.8 Disallow http-kernel 3.x, fixes #16837. [DependencyInjection] Validate class names and factory methods ampq → amqp Fix typo Refactoring EntityUserProvider::__construct() to not do work, cause cache warm error [Form] Add context to FormFactory deprecations CS: remove unneeded parentheses around control statements [TwigBridge] Clean deps now that 2.8.0 is tagged
2 parents 39ed359 + 54c553c commit e0eb6d4

File tree

19 files changed

+157
-52
lines changed

19 files changed

+157
-52
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public function getEntities()
5555
*/
5656
public function getEntitiesByIds($identifier, array $values)
5757
{
58-
$qb = clone ($this->queryBuilder);
58+
$qb = clone $this->queryBuilder;
5959
$alias = current($qb->getRootAliases());
6060
$parameter = 'ORMQueryBuilderLoader_getEntitiesByIds_'.$identifier;
6161
$where = $qb->expr()->in($alias.'.'.$identifier, ':'.$parameter);

src/Symfony/Bridge/Doctrine/Security/User/EntityUserProvider.php

Lines changed: 50 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -27,22 +27,17 @@
2727
*/
2828
class EntityUserProvider implements UserProviderInterface
2929
{
30+
private $registry;
31+
private $managerName;
32+
private $classOrAlias;
3033
private $class;
31-
private $repository;
3234
private $property;
33-
private $metadata;
3435

35-
public function __construct(ManagerRegistry $registry, $class, $property = null, $managerName = null)
36+
public function __construct(ManagerRegistry $registry, $classOrAlias, $property = null, $managerName = null)
3637
{
37-
$em = $registry->getManager($managerName);
38-
$this->class = $class;
39-
$this->metadata = $em->getClassMetadata($class);
40-
41-
if (false !== strpos($this->class, ':')) {
42-
$this->class = $this->metadata->getName();
43-
}
44-
45-
$this->repository = $em->getRepository($class);
38+
$this->registry = $registry;
39+
$this->managerName = $managerName;
40+
$this->classOrAlias = $classOrAlias;
4641
$this->property = $property;
4742
}
4843

@@ -51,14 +46,15 @@ public function __construct(ManagerRegistry $registry, $class, $property = null,
5146
*/
5247
public function loadUserByUsername($username)
5348
{
49+
$repository = $this->getRepository();
5450
if (null !== $this->property) {
55-
$user = $this->repository->findOneBy(array($this->property => $username));
51+
$user = $repository->findOneBy(array($this->property => $username));
5652
} else {
57-
if (!$this->repository instanceof UserLoaderInterface) {
58-
throw new \InvalidArgumentException(sprintf('The Doctrine repository "%s" must implement Symfony\Bridge\Doctrine\Security\User\UserLoaderInterface.', get_class($this->repository)));
53+
if (!$repository instanceof UserLoaderInterface) {
54+
throw new \InvalidArgumentException(sprintf('The Doctrine repository "%s" must implement Symfony\Bridge\Doctrine\Security\User\UserLoaderInterface.', get_class($repository)));
5955
}
6056

61-
$user = $this->repository->loadUserByUsername($username);
57+
$user = $repository->loadUserByUsername($username);
6258
}
6359

6460
if (null === $user) {
@@ -73,26 +69,28 @@ public function loadUserByUsername($username)
7369
*/
7470
public function refreshUser(UserInterface $user)
7571
{
76-
if (!$user instanceof $this->class) {
72+
$class = $this->getClass();
73+
if (!$user instanceof $class) {
7774
throw new UnsupportedUserException(sprintf('Instances of "%s" are not supported.', get_class($user)));
7875
}
7976

80-
if ($this->repository instanceof UserProviderInterface) {
81-
$refreshedUser = $this->repository->refreshUser($user);
77+
$repository = $this->getRepository();
78+
if ($repository instanceof UserProviderInterface) {
79+
$refreshedUser = $repository->refreshUser($user);
8280
} else {
8381
// The user must be reloaded via the primary key as all other data
8482
// might have changed without proper persistence in the database.
8583
// That's the case when the user has been changed by a form with
8684
// validation errors.
87-
if (!$id = $this->metadata->getIdentifierValues($user)) {
85+
if (!$id = $this->getClassMetadata()->getIdentifierValues($user)) {
8886
throw new \InvalidArgumentException('You cannot refresh a user '.
8987
'from the EntityUserProvider that does not contain an identifier. '.
9088
'The user object has to be serialized with its own identifier '.
9189
'mapped by Doctrine.'
9290
);
9391
}
9492

95-
$refreshedUser = $this->repository->find($id);
93+
$refreshedUser = $repository->find($id);
9694
if (null === $refreshedUser) {
9795
throw new UsernameNotFoundException(sprintf('User with id %s not found', json_encode($id)));
9896
}
@@ -106,6 +104,36 @@ public function refreshUser(UserInterface $user)
106104
*/
107105
public function supportsClass($class)
108106
{
109-
return $class === $this->class || is_subclass_of($class, $this->class);
107+
return $class === $this->getClass() || is_subclass_of($class, $this->getClass());
108+
}
109+
110+
private function getObjectManager()
111+
{
112+
return $this->registry->getManager($this->managerName);
113+
}
114+
115+
private function getRepository()
116+
{
117+
return $this->getObjectManager()->getRepository($this->classOrAlias);
118+
}
119+
120+
private function getClass()
121+
{
122+
if (null === $this->class) {
123+
$class = $this->classOrAlias;
124+
125+
if (false !== strpos($class, ':')) {
126+
$class = $this->getClassMetadata()->getName();
127+
}
128+
129+
$this->class = $class;
130+
}
131+
132+
return $this->class;
133+
}
134+
135+
private function getClassMetadata()
136+
{
137+
return $this->getObjectManager()->getClassMetadata($this->classOrAlias);
110138
}
111139
}

src/Symfony/Bridge/Doctrine/Tests/Security/User/EntityUserProviderTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ public function testLoadUserByUserNameShouldDeclineInvalidInterface()
125125
private function getManager($em, $name = null)
126126
{
127127
$manager = $this->getMock('Doctrine\Common\Persistence\ManagerRegistry');
128-
$manager->expects($this->once())
128+
$manager->expects($this->any())
129129
->method('getManager')
130130
->with($this->equalTo($name))
131131
->will($this->returnValue($em));

src/Symfony/Bridge/Twig/composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
"require-dev": {
2323
"symfony/asset": "~2.8|~3.0",
2424
"symfony/finder": "~2.8|~3.0",
25-
"symfony/form": "~2.8,>2.8-BETA1|~3.0,>3.0-BETA1",
25+
"symfony/form": "~2.8|~3.0",
2626
"symfony/http-kernel": "~2.8|~3.0",
2727
"symfony/polyfill-intl-icu": "~1.0",
2828
"symfony/routing": "~2.8|~3.0",

src/Symfony/Component/Console/Helper/ProgressBar.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,8 @@ public function __construct(OutputInterface $output, $max = 0)
6868
// disable overwrite when output does not support ANSI codes.
6969
$this->overwrite = false;
7070

71-
if ($this->max > 10) {
72-
// set a reasonable redraw frequency so output isn't flooded
73-
$this->setRedrawFrequency($max / 10);
74-
}
71+
// set a reasonable redraw frequency so output isn't flooded
72+
$this->setRedrawFrequency($max / 10);
7573
}
7674

7775
$this->startTime = time();
@@ -301,11 +299,11 @@ public function setFormat($format)
301299
/**
302300
* Sets the redraw frequency.
303301
*
304-
* @param int $freq The frequency in steps
302+
* @param int|float $freq The frequency in steps
305303
*/
306304
public function setRedrawFrequency($freq)
307305
{
308-
$this->redrawFreq = (int) $freq;
306+
$this->redrawFreq = max((int) $freq, 1);
309307
}
310308

311309
/**

src/Symfony/Component/Console/Tests/Helper/ProgressBarTest.php

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ public function testRegressProgress()
296296

297297
public function testRedrawFrequency()
298298
{
299-
$bar = $this->getMock('Symfony\Component\Console\Helper\ProgressBar', array('display'), array($output = $this->getOutputStream(), 6));
299+
$bar = $this->getMock('Symfony\Component\Console\Helper\ProgressBar', array('display'), array($this->getOutputStream(), 6));
300300
$bar->expects($this->exactly(4))->method('display');
301301

302302
$bar->setRedrawFrequency(2);
@@ -307,6 +307,26 @@ public function testRedrawFrequency()
307307
$bar->advance(1);
308308
}
309309

310+
public function testRedrawFrequencyIsAtLeastOneIfZeroGiven()
311+
{
312+
$bar = $this->getMock('Symfony\Component\Console\Helper\ProgressBar', array('display'), array($this->getOutputStream()));
313+
314+
$bar->expects($this->exactly(2))->method('display');
315+
$bar->setRedrawFrequency(0);
316+
$bar->start();
317+
$bar->advance();
318+
}
319+
320+
public function testRedrawFrequencyIsAtLeastOneIfSmallerOneGiven()
321+
{
322+
$bar = $this->getMock('Symfony\Component\Console\Helper\ProgressBar', array('display'), array($this->getOutputStream()));
323+
324+
$bar->expects($this->exactly(2))->method('display');
325+
$bar->setRedrawFrequency(0.9);
326+
$bar->start();
327+
$bar->advance();
328+
}
329+
310330
public function testMultiByteSupport()
311331
{
312332
$bar = new ProgressBar($output = $this->getOutputStream());

src/Symfony/Component/DependencyInjection/Compiler/ReplaceAliasByActualDefinitionPass.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public function process(ContainerBuilder $container)
4545
try {
4646
$definition = $container->getDefinition($aliasId);
4747
} catch (InvalidArgumentException $e) {
48-
throw new InvalidArgumentException(sprintf('Unable to replace alias "%s" with "%s".', $alias, $id), null, $e);
48+
throw new InvalidArgumentException(sprintf('Unable to replace alias "%s" with actual definition "%s".', $id, $alias), null, $e);
4949
}
5050

5151
if ($definition->isPublic()) {

src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -689,6 +689,10 @@ private function addNewInstance($id, Definition $definition, $return, $instantia
689689
if (null !== $definition->getFactory()) {
690690
$callable = $definition->getFactory();
691691
if (is_array($callable)) {
692+
if (!preg_match('/^[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*$/', $callable[1])) {
693+
throw new RuntimeException(sprintf('Cannot dump definition because of invalid factory method (%s)', $callable[1] ?: 'n/a'));
694+
}
695+
692696
if ($callable[0] instanceof Reference
693697
|| ($callable[0] instanceof Definition && $this->definitionVariables->contains($callable[0]))) {
694698
return sprintf(" $return{$instantiation}%s->%s(%s);\n", $this->dumpValue($callable[0]), $callable[1], $arguments ? implode(', ', $arguments) : '');
@@ -1201,8 +1205,12 @@ private function dumpValue($value, $interpolate = true)
12011205
}
12021206

12031207
if (is_array($factory)) {
1208+
if (!preg_match('/^[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*$/', $factory[1])) {
1209+
throw new RuntimeException(sprintf('Cannot dump definition because of invalid factory method (%s)', $factory[1] ?: 'n/a'));
1210+
}
1211+
12041212
if (is_string($factory[0])) {
1205-
return sprintf('\\%s::%s(%s)', $factory[0], $factory[1], implode(', ', $arguments));
1213+
return sprintf('%s::%s(%s)', $this->dumpLiteralClass($this->dumpValue($factory[0])), $factory[1], implode(', ', $arguments));
12061214
}
12071215

12081216
if ($factory[0] instanceof Definition) {
@@ -1221,12 +1229,8 @@ private function dumpValue($value, $interpolate = true)
12211229
if (null === $class) {
12221230
throw new RuntimeException('Cannot dump definitions which have no class nor factory.');
12231231
}
1224-
$class = $this->dumpValue($class);
1225-
if (false !== strpos($class, '$')) {
1226-
throw new RuntimeException('Cannot dump definitions which have a variable class name.');
1227-
}
12281232

1229-
return sprintf('new \\%s(%s)', substr(str_replace('\\\\', '\\', $class), 1, -1), implode(', ', $arguments));
1233+
return sprintf('new %s(%s)', $this->dumpLiteralClass($this->dumpValue($class)), implode(', ', $arguments));
12301234
} elseif ($value instanceof Variable) {
12311235
return '$'.$value;
12321236
} elseif ($value instanceof Reference) {
@@ -1266,9 +1270,18 @@ private function dumpValue($value, $interpolate = true)
12661270
* @param string $class
12671271
*
12681272
* @return string
1273+
*
1274+
* @throws RuntimeException
12691275
*/
12701276
private function dumpLiteralClass($class)
12711277
{
1278+
if (false !== strpos($class, '$')) {
1279+
throw new RuntimeException('Cannot dump definitions which have a variable class name.');
1280+
}
1281+
if (0 !== strpos($class, "'") || !preg_match('/^\'[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*(\\\{2}[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*)*\'$/', $class)) {
1282+
throw new RuntimeException(sprintf('Cannot dump definition because of invalid class name (%s)', $class ?: 'n/a'));
1283+
}
1284+
12721285
return '\\'.substr(str_replace('\\\\', '\\', $class), 1, -1);
12731286
}
12741287

src/Symfony/Component/DependencyInjection/Tests/Dumper/PhpDumperTest.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,31 @@ public function testAddServiceInvalidServiceId()
144144
$dumper->dump();
145145
}
146146

147+
/**
148+
* @dataProvider provideInvalidFactories
149+
* @expectedException Symfony\Component\DependencyInjection\Exception\RuntimeException
150+
* @expectedExceptionMessage Cannot dump definition
151+
*/
152+
public function testInvalidFactories($factory)
153+
{
154+
$container = new ContainerBuilder();
155+
$def = new Definition('stdClass');
156+
$def->setFactory($factory);
157+
$container->setDefinition('bar', $def);
158+
$dumper = new PhpDumper($container);
159+
$dumper->dump();
160+
}
161+
162+
public function provideInvalidFactories()
163+
{
164+
return array(
165+
array(array('', 'method')),
166+
array(array('class', '')),
167+
array(array('...', 'method')),
168+
array(array('class', '...')),
169+
);
170+
}
171+
147172
public function testAliases()
148173
{
149174
$container = include self::$fixturesPath.'/containers/container9.php';

src/Symfony/Component/Filesystem/Filesystem.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -443,13 +443,13 @@ public function mirror($originDir, $targetDir, \Traversable $iterator = null, $o
443443
*/
444444
public function isAbsolutePath($file)
445445
{
446-
return (strspn($file, '/\\', 0, 1)
446+
return strspn($file, '/\\', 0, 1)
447447
|| (strlen($file) > 3 && ctype_alpha($file[0])
448448
&& substr($file, 1, 1) === ':'
449449
&& (strspn($file, '/\\', 2, 1))
450450
)
451451
|| null !== parse_url($file, PHP_URL_SCHEME)
452-
);
452+
;
453453
}
454454

455455
/**

src/Symfony/Component/Finder/Iterator/SortableIterator.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,15 +55,15 @@ public function __construct(\Traversable $iterator, $sort)
5555
};
5656
} elseif (self::SORT_BY_ACCESSED_TIME === $sort) {
5757
$this->sort = function ($a, $b) {
58-
return ($a->getATime() - $b->getATime());
58+
return $a->getATime() - $b->getATime();
5959
};
6060
} elseif (self::SORT_BY_CHANGED_TIME === $sort) {
6161
$this->sort = function ($a, $b) {
62-
return ($a->getCTime() - $b->getCTime());
62+
return $a->getCTime() - $b->getCTime();
6363
};
6464
} elseif (self::SORT_BY_MODIFIED_TIME === $sort) {
6565
$this->sort = function ($a, $b) {
66-
return ($a->getMTime() - $b->getMTime());
66+
return $a->getMTime() - $b->getMTime();
6767
};
6868
} elseif (is_callable($sort)) {
6969
$this->sort = $sort;

src/Symfony/Component/HttpFoundation/Response.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -976,7 +976,7 @@ public function getVary()
976976
* Sets the Vary header.
977977
*
978978
* @param string|array $headers
979-
* @param bool $replace Whether to replace the actual value of not (true by default)
979+
* @param bool $replace Whether to replace the actual value or not (true by default)
980980
*
981981
* @return Response
982982
*/

src/Symfony/Component/HttpFoundation/Session/Storage/Proxy/AbstractProxy.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public function getSaveHandlerName()
4747
*/
4848
public function isSessionHandlerInterface()
4949
{
50-
return ($this instanceof \SessionHandlerInterface);
50+
return $this instanceof \SessionHandlerInterface;
5151
}
5252

5353
/**

src/Symfony/Component/Intl/DateFormatter/DateFormat/FullTransformer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ public function getReverseMatchingRegExp($pattern)
212212
*/
213213
public function isQuoteMatch($quoteMatch)
214214
{
215-
return ("'" === $quoteMatch[0]);
215+
return "'" === $quoteMatch[0];
216216
}
217217

218218
/**

src/Symfony/Component/Process/Process.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1370,6 +1370,11 @@ private function close()
13701370
$this->exitcode = 128 + $this->processInformation['termsig'];
13711371
}
13721372

1373+
// Free memory from self-reference callback created by buildCallback
1374+
// Doing so in other contexts like __destruct or by garbage collector is ineffective
1375+
// Now pipes are closed, so the callback is no longer necessary
1376+
$this->callback = null;
1377+
13731378
return $this->exitcode;
13741379
}
13751380

0 commit comments

Comments
 (0)