8000 Merge branch '2.5' · symfony/symfony@27a2280 · GitHub
[go: up one dir, main page]

Skip to content
65E9

Commit 27a2280

Browse files
committed
Merge branch '2.5'
* 2.5: (33 commits) [Validator] Added Swedish translations [Validator] Fixed ExpressionValidator when the validation root is not an object [Validator] Fixed: Made it possible (again) to pass a class name to Validator::validatePropertyValue() Fix incorrect romanian plural translations fix axes handling in Crawler::filterXPath() fix some docblocks Fixed self-reference in 'service_container' service breaks garbage collection (and clone). [Process] Fix tests when pcntl is not available. [DependencyInjection] Roll back changes made to generated files. [Console] Roll back changes made to fixture files. Issue #11489 Added some CA and ES translations [Validator] Added more detailed inline documentation [Validator] Removed information from the violation output if the value is an array, object or resource partially reverted previous commit fixed CS Add point about ConsoleLogger to Console 2.5 changelog [Validator] Fixed failing tests [Validator] CS fixes [FrameworkBundle] Made ConstraintValidatorFactory aware of the legacy validators [Validator] Added extensive test coverage for the constraint validators for the different APIs ... Conflicts: src/Symfony/Component/Validator/Resources/translations/validators.ca.xlf
2 parents 3ecf685 + 98c0621 commit 27a2280

File tree

226 files changed

+5518
-2014
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

226 files changed

+5518
-2014
lines changed

src/Symfony/Bridge/Doctrine/DependencyInjection/CompilerPass/RegisterMappingsPass.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ abstract class RegisterMappingsPass implements CompilerPassInterface
7474
* @param string[] $managerParameters list of container parameters
7575
* that could hold the manager name
7676
* @param string $driverPattern pattern to get the metadata driver service names
77-
* @param string $enabledParameter service container parameter that must be
77+
* @param string|false $enabledParameter service container parameter that must be
7878
* present to enable the mapping. Set to false
7979
* to not do any check, optional.
8080
*/

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -741,6 +741,7 @@ private function registerValidationConfiguration(array $config, ContainerBuilder
741741
switch ($config['api']) {
742742
case '2.4':
743743
$api = Validation::API_VERSION_2_4;
744+
$container->setParameter('validator.validator_factory.class', $container->getParameter('validator.legacy_validator_factory.class'));
744745
break;
745746
case '2.5':
746747
$api = Validation::API_VERSION_2_5;

src/Symfony/Bundle/FrameworkBundle/Resources/config/validator.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
<parameter key="validator.mapping.cache.apc.class">Symfony\Component\Validator\Mapping\Cache\ApcCache</parameter>
1212
<parameter key="validator.mapping.cache.prefix" />
1313
<parameter key="validator.validator_factory.class">Symfony\Bundle\FrameworkBundle\Validator\ConstraintValidatorFactory</parameter>
14+
<parameter key="validator.legacy_validator_factory.class">Symfony\Bundle\FrameworkBundle\Validator\LegacyConstraintValidatorFactory</parameter>
1415
<parameter key="validator.expression.class">Symfony\Component\Validator\Constraints\ExpressionValidator</parameter>
1516
<parameter key="validator.email.class">Symfony\Component\Validator\Constraints\EmailValidator</parameter>
1617
</parameters>
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Bundle\FrameworkBundle\Validator;
13+
14+
use Symfony\Component\DependencyInjection\ContainerInterface;
15+
use Symfony\Component\Validator\Constraint;
16+
use Symfony\Component\Validator\ConstraintValidatorFactoryInterface;
17+
use Symfony\Component\Validator\ConstraintValidatorInterface;
18+
use Symfony\Component\Validator\Exception\UnexpectedTypeException;
19+
20+
/**
21+
* Like {@link ConstraintValidatorFactory}, but aware of services compatible
22+
* with the 2.4 API.
23+
*
24+
* @author Bernhard Schussek <bschussek@gmail.com>
25+
* @author Kris Wallsmith <kris@symfony.com>
26+
*
27+
* @see ConstraintValidatorFactory
28+
*/
29+
class LegacyConstraintValidatorFactory implements ConstraintValidatorFactoryInterface
30+
{
31+
const BASE_NAMESPACE = 'Symfony\\Component\\Validator\\Constraints';
32+
33+
protected $container;
34+
protected $validators;
35+
36+
/**
37+
* Constructor.
38+
*
39+
* @param ContainerInterface $container The service container
40+
* @param array $validators An array of validators
41+
*/
42+
public function __construct(ContainerInterface $container, array $validators = array())
43+
{
44+
$this->container = $container;
45+
$this->validators = $validators;
46+
}
47+
48+
/**
49+
* Returns the validator for the supplied constraint.
50+
*
51+
* @param Constraint $constraint A constraint
52+
*
53+
* @return ConstraintValidatorInterface A validator for the supplied constraint
54+
*
55+
* @throws UnexpectedTypeException When the validator is not an instance of ConstraintValidatorInterface
56+
*/
57+
public function getInstance(Constraint $constraint)
58+
{
59+
$name = $constraint->validatedBy();
60+
61+
if (!isset($this->validators[$name])) {
62+
switch (get_class($constraint)) {
63+
case self::BASE_NAMESPACE.'\\All':
64+
$name = self::BASE_NAMESPACE.'\\LegacyAllValidator';
65+
break;
66+
case self::BASE_NAMESPACE.'\\Choice':
67+
$name = self::BASE_NAMESPACE.'\\LegacyChoiceValidator';
68+
break;
69+
case self::BASE_NAMESPACE.'\\Collection':
70+
$name = self::BASE_NAMESPACE.'\\LegacyCollectionValidator';
71+
break;
72+
case self::BASE_NAMESPACE.'\\Count':
73+
$name = self::BASE_NAMESPACE.'\\LegacyCountValidator';
74+
break;
75+
case self::BASE_NAMESPACE.'\\Length':
76+
$name = self::BASE_NAMESPACE.'\\LegacyLengthValidator';
77+
break;
78+
}
79+
80+
$this->validators[$name] = new $name();
81+
} elseif (is_string($this->validators[$name])) {
82+
$this->validators[$name] = $this->container->get($this->validators[$name]);
83+
}
84+
85+
if (!$this->validators[$name] instanceof ConstraintValidatorInterface) {
86+
throw new UnexpectedTypeException($this->validators[$name], 'Symfony\Component\Validator\ConstraintValidatorInterface');
87+
}
88+
89+
return $this->validators[$name];
90+
}
91+
}

src/Symfony/Component/Config/Definition/BaseNode.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,7 @@ public function getParent()
292292
*
293293
* @return mixed The finalized value
294294
*
295+
* @throws Exception
295296
* @throws InvalidConfigurationException
296297
*/
297298
final public function finalize($value)

src/Symfony/Component/Console/Application.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -876,6 +876,8 @@ protected function configureIO(InputInterface $input, OutputInterface $output)
876876
* @param OutputInterface $output An Output instance
877877
*
878878
* @return int 0 if everything went fine, or an error code
879+
*
880+
* @throws \Exception when the command being run threw an exception
879881
*/
880882
protected function doRunCommand(Command $command, InputInterface $input, OutputInterface $output)
881883
{

src/Symfony/Component/Console/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ CHANGELOG
1313
* deprecated the dialog helper (use the question helper instead)
1414
* deprecated TableHelper in favor of Table
1515
* deprecated ProgressHelper in favor of ProgressBar
16+
* added ConsoleLogger
1617
* added a question helper
1718
* added a way to set the process name of a command
1819
* added a way to set a default command instead of `ListCommand`

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public function __construct()
5454
* @param object $object
5555
* @param array $options
5656
*
57-
* @throws \InvalidArgumentException
57+
* @throws \InvalidArgumentException when the given format is not supported
5858
*/
5959
public function describe(OutputInterface $output, $object, array $options = array())
6060
{

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ public function askHiddenResponse(OutputInterface $output, $question, $fallback
328328
* @param OutputInterface $output An Output instance
329329
* @param string|array $question The question to ask
330330
* @param callable $validator A PHP callback
331-
* @param int $attempts Max number of times to ask before giving up (false by default, which means infinite)
331+
* @param int|false $attempts Max number of times to ask before giving up (false by default, which means infinite)
332332
* @param string $default The default answer if none is given by the user
333333
* @param array $autocomplete List of values to autocomplete
334334
*
@@ -357,7 +357,7 @@ public function askAndValidate(OutputInterface $output, $question, $validator, $
357357
* @param OutputInterface $output An Output instance
358358
* @param string|array $question The question to ask
359359
* @param callable $validator A PHP callback
360-
* @param int $attempts Max number of times to ask before giving up (false by default, which means infinite)
360+
* @param int|false $attempts Max number of times to ask before giving up (false by default, which means infinite)
361361
* @param bool $fallback In case the response can not be hidden, whether to fallback on non-hidden question or not
362362
*
363363
* @return string The response
@@ -451,7 +451,7 @@ private function hasSttyAvailable()
451451
* @param callable $interviewer A callable that will ask for a question and return the result
452452
* @param OutputInterface $output An Output instance
453453
* @param callable $validator A PHP callback
454-
* @param int $attempts Max number of times to ask before giving up ; false will ask infinitely
454+
* @param int|false $attempts Max number of times to ask before giving up ; false will ask infinitely
455455
*
456456
* @return string The validated response
457457
*

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ public function __construct()
4444
* @param int $layout self::LAYOUT_*
4545
*
4646
* @return TableHelper
47+
*
48+
* @throws InvalidArgumentException when the table layout is not known
4749
*/
4850
public function setLayout($layout)
4951
{

src/Symfony/Component/Console/Tests/Command/ListCommandTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public function testExecuteListsCommandsWithRawOption()
5050
public function testExecuteListsCommandsWithNamespaceArgument()
5151
{
5252

53-
require_once(realpath(__DIR__.'/../Fixtures/FooCommand.php'));
53+
require_once realpath(__DIR__.'/../Fixtures/FooCommand.php');
5454
$application = new Application();
5555
$application->add(new \FooCommand());
5656
$commandTester = new CommandTester($command = $application->get('list'));

src/Symfony/Component/DependencyInjection/Container.php

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,12 @@ public function set($id, $service, $scope = self::SCOPE_CONTAINER)
197197

198198
$id = strtolower($id);
199199

200+
if ('service_container' === $id) {
201+
// BC: 'service_container' is no longer a self-reference but always
202+
// $this, so ignore this call.
203+
// @todo Throw InvalidArgumentException in next major release.
204+
return;
205+
}
200206
if (self::SCOPE_CONTAINER !== $scope) {
201207
if (!isset($this->scopedServices[$scope])) {
202208
throw new RuntimeException(sprintf('You cannot set service "%s" of inactive scope.', $id));
@@ -233,6 +239,10 @@ public function has($id)
233239
{
234240
$id = strtolower($id);
235241

242+
if ('service_container' === $id) {
243+
return true;
244+
}
245+
236246
return isset($this->services[$id])
237247
|| array_key_exists($id, $this->services)
238248
|| isset($this->aliases[$id])
@@ -251,9 +261,10 @@ public function has($id)
251261
*
252262
* @return object The associated service
253263
*
254-
* @throws InvalidArgumentException if the service is not defined
264+
* @throws InvalidArgumentException if the service is not defined
255265
* @throws ServiceCircularReferenceException When a circular reference is detected
256-
* @throws ServiceNotFoundException When the service is not defined
266+
* @throws ServiceNotFoundException When the service is not defined
267+
* @throws \Exception if an exception has been thrown when the service has been resolved
257268
*
258269
* @see Reference
259270
*
@@ -269,6 +280,9 @@ public function get($id, $invalidBehavior = self::EXCEPTION_ON_INVALID_REFERENCE
269280
if ($strtolower) {
270281
$id = strtolower($id);
271282
}
283+
if ('service_container' === $id) {
284+
return $this;
285+
}
272286
if (isset($this->aliases[$id])) {
273287
$id = $this->aliases[$id];
274288
}
@@ -340,6 +354,12 @@ public function initialized($id)
340354
{
341355
$id = strtolower($id);
342356

357+
if ('service_container' === $id) {
358+
// BC: 'service_container' was a synthetic service previously.
359+
// @todo Change to false in next major release.
360+
return true;
361+
}
362+
343363
return isset($this->services[$id]) || array_key_exists($id, $this->services);
344364
}
345365

@@ -357,6 +377,7 @@ public function getServiceIds()
357377
$ids[] = self::underscore($match[1]);
358378
}
359379
}
380+
$ids[] = 'service_container';
360381

361382
return array_unique(array_merge($ids, array_keys($this->services)));
362383
}

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -429,7 +429,10 @@ private function addServiceProperties($id, $definition, $variableName = 'instanc
429429
*
430430
* @param string $id
431431
* @param Definition $definition
432+
*
432433
* @return string
434+
*
435+
* @throws ServiceCircularReferenceException when the container contains a circular reference
433436
*/
434437
private function addServiceInlinedDefinitionsSetup($id, $definition)
435438
{
@@ -640,6 +643,8 @@ private function addServices()
640643
*
641644
* @param string $id A service identifier
642645
* @param Definition $definition A Definition instance
646+
*
647+
* @return string|null
643648
*/
644649
private function addServiceSynchronizer($id, Definition $definition)
645650
{

src/Symfony/Component/DependencyInjection/Loader/YamlFileLoader.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,8 @@ private function parseDefinition($id, $service, $file)
248248
* @param string $file
249249
*
250250
* @return array The file content
251+
*
252+
* @throws InvalidArgumentException when the given file is not a local file or when it does not exist
251253
*/
252254
protected function loadFile($file)
253255
{

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ public function testAliases()
140140
eval('?>'.$dumper->dump(array('class' => 'Symfony_DI_PhpDumper_Test_Aliases')));
141141

142142
$container = new \Symfony_DI_PhpDumper_Test_Aliases();
143-
$container->set('foo', $foo = new \stdClass);
143+
$container->set('foo', $foo = new \stdClass());
144144
$this->assertSame($foo, $container->get('foo'));
145145
$this->assertSame($foo, $container->get('alias_for_foo'));
146146
$this->assertSame($foo, $container->get('alias_for_alias'));

src/Symfony/Component/DomCrawler/Crawler.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -918,7 +918,7 @@ private function relativize($xpath)
918918
$expression = $nonMatchingExpression;
919919
} elseif (0 === strpos($expression, 'descendant::')) {
920920
$expression = 'descendant-or-self::' . substr($expression, strlen('descendant::'));
921-
} elseif (0 !== strpos($expression, 'descendant-or-self::')) {
921+
} elseif (!preg_match('/^(ancestor|ancestor-or-self|attribute|child|descendant-or-self|following|following-sibling|parent|preceding|preceding-sibling|self)::/', $expression)) {
922922
$expression = 'self::' .$expression;
923923
}
924924
$expressions[] = $parenthesis.$expression;

src/Symfony/Component/DomCrawler/Tests/CrawlerTest.php

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -494,6 +494,74 @@ public function testFilterXPathWithAnUrl()
494494
$this->assertSame('Music', $crawler->text());
495495
}
496496

497+
public function testFilterXPathWithAncestorAxis()
498+
{
499+
$crawler = $this->createTestCrawler()->filterXPath('//form');
500+
501+
$this->assertCount(2, $crawler->filterXPath('ancestor::*'));
502+
}
503+
504+
public function testFilterXPathWithAncestorOrSelfAxis()
505+
{
506+
$crawler = $this->createTestCrawler()->filterXPath('//form');
507+
508+
$this->assertCount(3, $crawler->filterXPath('ancestor-or-self::*'));
509+
}
510+
511+
public function testFilterXPathWithAttributeAxis()
512+
{
513+
$crawler = $this->createTestCrawler()->filterXPath('//form');
514+
515+
$this->assertCount(2, $crawler->filterXPath('attribute::*'));
516+
}
517+
518+
public function testFilterXPathWithChildAxis()
519+
{
520+
$crawler = $this->createTestCrawler()->filterXPath('//body');
521+
522+
$this->assertCount(2, $crawler->filterXPath('child::input'));
523+
}
524+
525+
public function testFilterXPathWithFollowingAxis()
526+
{
527+
$crawler = $this->createTestCrawler()->filterXPath('//a');
528+
529+
$this->assertCount(3, $crawler->filterXPath('following::div'));
530+
}
531+
532+
public function testFilterXPathWithFollowingSiblingAxis()
533+
{
534+
$crawler = $this->createTestCrawler()->filterXPath('//a');
535+
536+
$this->assertCount(2, $crawler->filterXPath('following-sibling::div'));
537+
}
538+
539+
public function testFilterXPathWithParentAxis()
540+
{
541+
$crawler = $this->createTestCrawler()->filterXPath('//button');
542+
543+
$this->assertEquals('foo', $crawler->filterXPath('parent::*')->attr('action'));
544+
}
545+
546+
public function testFilterXPathWithPrecedingAxis()
547+
{
548+
$crawler = $this->createTestCrawler()->filterXPath('//form');
549+
550+
$this->assertCount(13, $crawler->filterXPath('preceding::*'));
551+
}
552+
553+
public function testFilterXPathWithPrecedingSiblingAxis()
554+
{
555+
$crawler = $this->createTestCrawler()->filterXPath('//form');
556+
557+
$this->assertCount(9, $crawler->filterXPath('preceding-sibling::*'));
558+
}
559+
560+
public function testFilterXPathWithSelfAxes()
561+
{
562+
$this->assertCount(1, $this->createTestCrawler()->filterXPath('self::*'));
563+
}
564+
497565
/**
498566
* @covers Symfony\Component\DomCrawler\Crawler::filter
499567
*/

src/Symfony/Component/Form/ButtonBuilder.php

Lines changed: 2 additions & 0 deletions
O 72DB riginal file line numberDiff line numberDiff line change
@@ -503,6 +503,8 @@ public function setRequestHandler(RequestHandlerInterface $requestHandler)
503503
*
504504
* @param bool $initialize
505505
*
506+
* @return ButtonBuilder
507+
*
506508
* @throws BadMethodCallException
507509
*/
508510
public function setAutoInitialize($initialize)

0 commit comments

Comments
 (0)
0