8000 Merge branch '2.8' into 3.1 · symfony/symfony@f07bf03 · GitHub
[go: up one dir, main page]

Skip to content

Commit f07bf03

Browse files
committed
Merge branch '2.8' into 3.1
* 2.8: [TwigBridge] removed deprecations added in Twig 1.27 PHP CS Fixer: use php_unit_dedicate_assert 3.0 Upgrade Guide: Added details describing how to pass data to a form through the options resolver fixed Filesystem:makePathRelative and added 2 more testcases no 304 response if method is not cacheable move tags from decorated to decorating service
2 parents af10027 + ee8203a commit f07bf03

File tree

27 files changed

+126
-44
lines changed

27 files changed

+126
-44
lines changed

.php_cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ return Symfony\CS\Config\Config::create()
66
->fixers(array(
77
'long_array_syntax',
88
'php_unit_construct',
9+
'php_unit_dedicate_assert',
910
))
1011
->finder(
1112
Symfony\CS\Finder\DefaultFinder::create()

UPGRADE-3.0.md

Lines changed: 52 additions & 0 deletions
10000
Original file line numberDiff line numberDiff line change
@@ -410,6 +410,58 @@ UPGRADE FROM 2.x to 3.0
410410
$form = $this->createForm(MyType::class);
411411
```
412412

413+
* Passing custom data to forms now needs to be done
414+
through the options resolver.
415+
416+
In the controller:
417+
418+
Before:
419+
```php
420+
$form = $this->createForm(new MyType($variable), $entity, array(
421+
'action' => $this->generateUrl('action_route'),
422+
'method' => 'PUT',
423+
));
424+
```
425+
After:
426+
```php
427+
$form = $this->createForm(MyType::class, $entity, array(
428+
'action' => $this->generateUrl('action_route'),
429+
'method' => 'PUT',
430+
'custom_value' => $variable,
431+
));
432+
```
433+
In the form type:
434+
435+
Before:
436+
```php
437+
class MyType extends AbstractType
438+
{
439+
private $value;
440+
441+
public function __construct($variableValue)
442+
{
443+
$this->value = $value;
444+
}
445+
// ...
446+
}
447+
```
448+
449+
After:
450+
```php
451+
public function buildForm(FormBuilderInterface $builder, array $options)
452+
{
453+
$value = $options['custom_value'];
454+
// ...
455+
}
456+
457+
public function configureOptions(OptionsResolver $resolver)
458+
{
459+
$resolver->setDefaults(array(
460+
'custom_value' => null,
461+
));
462+
}
463+
```
464+
413465
* The alias option of the `form.type_extension` tag was removed in favor of
414466
the `extended_type`/`extended-type` option.
415467

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
"require": {
1919
"php": ">=5.5.9",
2020
"doctrine/common": "~2.4",
21-
"twig/twig": "~1.26|~2.0",
21+
"twig/twig": "~1.27|~2.0",
2222
"psr/cache": "~1.0",
2323
"psr/log": "~1.0",
2424
"symfony/polyfill-intl-icu": "~1.0",

src/Symfony/Bridge/Twig/Command/LintCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ private function validate(\Twig_Environment $twig, $template, $file)
142142
try {
143143
$temporaryLoader = new \Twig_Loader_Array(array((string) $file => $template));
144144
$twig->setLoader($temporaryLoader);
145-
$nodeTree = $twig->parse($twig->tokenize($template, (string) $file));
145+
$nodeTree = $twig->parse($twig->tokenize(new \Twig_Source($template, (string) $file)));
146146
$twig->compile($nodeTree);
147147
$twig->setLoader($realLoader);
148148
} catch (\Twig_Error $e) {

src/Symfony/Bridge/Twig/Tests/Extension/RoutingExtensionTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public function testEscaping($template, $mustBeEscaped)
2323
$twig = new \Twig_Environment($this->getMock('Twig_LoaderInterface'), array('debug' => true, 'cache' => false, 'autoescape' => 'html', 'optimizations' => 0));
2424
$twig->addExtension(new RoutingExtension($this->getMock('Symfony\Component\Routing\Generator\UrlGeneratorInterface')));
2525

26-
$nodes = $twig->parse($twig->tokenize($template));
26+
$nodes = $twig->parse($twig->tokenize(new \Twig_Source($template)));
2727

2828
$this->assertSame($mustBeEscaped, $nodes->getNode('body')->getNode(0)->getNode('expr') instanceof \Twig_Node_Expression_Filter);
2929
}

src/Symfony/Bridge/Twig/Tests/Extension/TranslationExtensionTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public function testTrans($template, $expected, array $variables = array())
3636
$twig = new \Twig_Environment($loader, array('debug' => true, 'cache' => false));
3737
$twig->addExtension(new TranslationExtension(new Translator('en', new MessageSelector())));
3838

39-
echo $twig->compile($twig->parse($twig->tokenize($twig->getLoader()->getSource('index'), 'index')))."\n\n";
39+
echo $twig->compile($twig->parse($twig->tokenize(new \Twig_Source($twig->getLoader()->getSource('index'), 'index'))))."\n\n";
4040
$this->assertEquals($expected, $this->getTemplate($template)->render($variables));
4141
}
4242

src/Symfony/Bridge/Twig/Tests/NodeVisitor/TwigNodeProvider.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public static function getModule($content)
2525
new \Twig_Node_Expression_Array(array(), 0),
2626
new \Twig_Node_Expression_Array(array(), 0),
2727
null,
28-
null
28+
new \Twig_Source('')
2929
);
3030
}
3131

src/Symfony/Bridge/Twig/Tests/TokenParser/FormThemeTokenParserTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public function testCompile($source, $expected)
2323
{
2424
$env = new \Twig_Environment($this->getMock('Twig_LoaderInterface'), array('cache' => false, 'autoescape' => false, 'optimizations' => 0));
2525
$env->addTokenParser(new FormThemeTokenParser());
26-
$stream = $env->tokenize($source);
26+
$stream = $env->tokenize(new \Twig_Source($source));
2727
$parser = new \Twig_Parser($env);
2828

2929
$this->assertEquals($expected, $parser->parse($stream)->getNode('body')->getNode(0));

src/Symfony/Bridge/Twig/TokenParser/TransChoiceTokenParser.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public function parse(\Twig_Token $token)
6464
$body = $this->parser->subparse(array($this, 'decideTransChoiceFork'), true);
6565

6666
if (!$body instanceof \Twig_Node_Text && !$body instanceof \Twig_Node_Expression) {
67-
throw new \Twig_Error_Syntax('A message inside a transchoice tag must be a simple text.', $body->getLine(), $stream->getFilename());
67+
throw new \Twig_Error_Syntax('A message inside a transchoice tag must be a simple text.', $body->getLine(), $stream->getSourceContext()->getName());
6868
}
6969

7070
$stream->expect(\Twig_Token::BLOCK_END_TYPE);

src/Symfony/Bridge/Twig/TokenParser/TransTokenParser.php

Lines changed: 2 additions & 2 deletions
< 10000 /tr>
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public function parse(\Twig_Token $token)
5555
$stream->next();
5656
$locale = $this->parser->getExpressionParser()->parseExpression();
5757
} elseif (!$stream->test(\Twig_Token::BLOCK_END_TYPE)) {
58-
throw new \Twig_Error_Syntax('Unexpected token. Twig was looking for the "with", "from", or "into" keyword.', $stream->getCurrent()->getLine(), $stream->getFilename());
58+
throw new \Twig_Error_Syntax('Unexpected token. Twig was looking for the "with", "from", or "into" keyword.', $stream->getCurrent()->getLine(), $stream->getSourceContext()->getName());
5959
}
6060
}
6161

@@ -64,7 +64,7 @@ public function parse(\Twig_Token $token)
6464
$body = $this->parser->subparse(array($this, 'decideTransFork'), true);
6565

6666
if (!$body instanceof \Twig_Node_Text && !$body instanceof \Twig_Node_Expression) {
67-
throw new \Twig_Error_Syntax('A message inside a trans tag must be a simple text.', $body->getLine(), $stream->getFilename());
67+
throw new \Twig_Error_Syntax('A message inside a trans tag must be a simple text.', $body->getLine(), $stream->getSourceContext()->getName());
6868
}
6969

7070
$stream->expect(\Twig_Token::BLOCK_END_TYPE);

src/Symfony/Bridge/Twig/Translation/TwigExtractor.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,9 @@ public function extract($resource, MessageCatalogue $catalogue)
6262
$this->extractTemplate(file_get_contents($file->getPathname()), $catalogue);
6363
} catch (\Twig_Error $e) {
6464
if ($file instanceof SplFileInfo) {
65-
$e->setTemplateFile($file->getRelativePathname());
65+
$e->setTemplateName($file->getRelativePathname());
6666
} elseif ($file instanceof \SplFileInfo) {
67-
$e->setTemplateFile($file->getRealPath());
67+
$e->setTemplateName($file->getRealPath());
6868
}
6969

7070
throw $e;
@@ -85,7 +85,7 @@ protected function extractTemplate($template, MessageCatalogue $catalogue)
8585
$visitor = $this->twig->getExtension('Symfony\Bridge\Twig\Extension\TranslationExtension')->getTranslationNodeVisitor();
8686
$visitor->enable();
8787

88-
$this->twig->parse($this->twig->tokenize($template));
88+
$this->twig->parse($this->twig->tokenize(new \Twig_Source($template)));
8989

9090
foreach ($visitor->getMessages() as $message) {
9191
$catalogue->set(trim($message[0]), $this->prefix.trim($message[0]), $message[1] ?: $this->defaultDomain);

src/Symfony/Bridge/Twig/composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
],
1818
"require": {
1919
"php": ">=5.5.9",
20-
"twig/twig": "~1.26|~2.0"
20+
"twig/twig": "~1.27|~2.0"
2121
},
2222
"require-dev": {
2323
"symfony/asset": "~2.8|~3.0",

src/Symfony/Bundle/FrameworkBundle/Tests/Functional/ProfilerTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public function testProfilerIsDisabled($insulate)
3030
$client->enableProfiler();
3131
$crawler = $client->request('GET', '/profiler');
3232
$profile = $client->getProfile();
33-
$this->assertTrue(is_object($profile));
33+
$this->assertInternalType('object', $profile);
3434

3535
$client->request('GET', '/profiler');
3636
$this->assertFalse($client->getProfile());

src/Symfony/Bundle/SecurityBundle/composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
"symfony/yaml": "~2.8|~3.0",
4040
"symfony/expression-language": "~2.8|~3.0",
4141
"doctrine/doctrine-bundle": "~1.4",
42-
"twig/twig": "~1.26|~2.0"
42+
"twig/twig": "~1.27|~2.0"
4343
},
4444
"suggest": {
4545
"symfony/security-acl": "For using the ACL functionality of this bundle"

src/Symfony/Bundle/TwigBundle/DependencyInjection/Configuration.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ private function addTwigOptions(ArrayNodeDefinition $rootNode)
120120
$rootNode
121121
->fixXmlConfig('path')
122122
->children()
123-
->variableNode('autoescape')->defaultValue('filename')->end()
123+
->variableNode('autoescape')->defaultValue('name')->end()
124124
->scalarNode('autoescape_service')->defaultNull()->end()
125125
->scalarNode('autoescape_service_method')->defaultNull()->end()
126126
->scalarNode('base_template_class')->example('Twig_Template')->cannotBeEmpty()->end()

src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/TwigExtensionTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ public function testLoadDefaultTemplateEscapingGuesserConfiguration($format)
111111
$this->compileContainer($container);
112112

113113
$options = $container->getDefinition('twig')->getArgument(1);
114-
$this->assertEquals('filename', $options['autoescape']);
114+
$this->assertEquals('name', $options['autoescape']);
115115
}
116116

117117
public function testGlobalsWithDifferentTypesAndValues()

src/Symfony/Bundle/TwigBundle/Tests/Functional/CacheWarmingTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public function testCacheIsProperlyWarmedWhenTemplatingIsAvailable()
2828
$warmer->enableOptionalWarmers();
2929
$warmer->warmUp($kernel->getCacheDir());
3030

31-
$this->assertTrue(file_exists($kernel->getCacheDir().'/twig'));
31+
$this->assertFileExists($kernel->getCacheDir().'/twig');
3232
}
3333

3434
public function testCacheIsProperlyWarmedWhenTemplatingIsDisabled()
@@ -40,7 +40,7 @@ public function testCacheIsProperlyWarmedWhenTemplatingIsDisabled()
4040
$warmer->enableOptionalWarmers();
4141
$warmer->warmUp($kernel->getCacheDir());
4242

43-
$this->assertTrue(file_exists($kernel->getCacheDir().'/twig'));
43+
$this->assertFileExists($kernel->getCacheDir().'/twig');
4444
}
4545

4646
protected function setUp()

src/Symfony/Bundle/TwigBundle/TwigEngine.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ public function render($name, array $parameters = array())
5151
} catch (\Twig_Error $e) {
5252
if ($name instanceof TemplateReference) {
5353
try {
54-
// try to get the real file name of the template where the error occurred
55-
$e->setTemplateFile(sprintf('%s', $this->locator->locate($this->parser->parse($e->getTemplateFile()))));
54+
// try to get the real name of the template where the error occurred
55+
$e->setTemplateName(sprintf('%s', $this->locator->locate($this->parser->parse($e->getTemplateName()))));
5656
} catch (\Exception $e2) {
5757
}
5858
}

src/Symfony/Bundle/TwigBundle/composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
"symfony/twig-bridge": "~2.8|~3.0",
2222
"symfony/http-foundation": "~2.8|~3.0",
2323
"symfony/http-kernel": "~2.8|~3.0",
24-
"twig/twig": "~1.26|~2.0"
24+
"twig/twig": "~1.27|~2.0"
2525
},
2626
"require-dev": {
2727
"symfony/stopwatch": "~2.8|~3.0",

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,12 @@ public function process(ContainerBuilder $container)
5151
$public = $alias->isPublic();
5252
$container->setAlias($renamedId, new Alias((string) $alias, false));
5353
} else {
54-
$definition = $container->getDefinition($inner);
55-
$public = $definition->isPublic();
56-
$definition->setPublic(false);
57-
$container->setDefinition($renamedId, $definition);
54+
$decoratedDefinition = $container->getDefinition($inner);
55+
$definition->setTags($decoratedDefinition->getTags(), $definition->getTags());
56+
$public = $decoratedDefinition->isPublic();
57+
$decoratedDefinition->setPublic(false);
58+
$decoratedDefinition->setTags(array());
59+
$container->setDefinition($renamedId, $decoratedDefinition);
5860
}
5961

6062
$container->setAlias($inner, new Alias($id, $public));

src/Symfony/Component/DependencyInjection/Tests/Compiler/DecoratorServicePassTest.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,24 @@ public function testProcessWithPriority()
124124
$this->assertNull($quxDefinition->getDecoratedService());
125125
}
126126

127+
public function testProcessMovesTagsFromDecoratedDefinitionToDecoratingDefinition()
128+
{
129+
$container = new ContainerBuilder();
130+
$container
131+
->register('foo')
132+
->setTags(array('name' => 'bar'))
133+
;
134+
$container
135+
->register('baz')
136+
->setDecoratedService('foo')
137+
;
138+
139+
$this->process($container);
140+
141+
$this->assertEmpty($container->getDefinition('baz.inner')->getTags());
142+
$this->assertEquals(array('name' => 'bar'), $container->getDefinition('baz')->getTags());
143+
}
144+
127145
protected function process(ContainerBuilder $container)
128146
{
129147
$repeatedPass = new DecoratorServicePass();

src/Symfony/Component/Filesystem/Filesystem.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -369,10 +369,14 @@ public function makePathRelative($endPath, $startPath)
369369
}
370370

371371
// Determine how deep the start path is relative to the common path (ie, "web/bundles" = 2 levels)
372-
$depth = count($startPathArr) - $index;
372+
if (count($startPathArr) === 1 && $startPathArr[0] === '') {
373+
$depth = 0;
374+
} else {
375+
$depth = count($startPathArr) - $index;
376+
}
373377

374378
// When we need to traverse from the start, and we are starting from a root path, don't add '../'
375-
if ('/' === $startPath[0] && 0 === $index && 1 === $depth) {
379+
if ('/' === $startPath[0] && 0 === $index && 0 === $depth) {
376380
$traverser = '';
377381
} else {
378382
// Repeated "../" for each level need to reach the common path

src/Symfony/Component/Filesystem/Tests/FilesystemTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -840,6 +840,8 @@ public function providePathsForMakePathRelative()
840840
array('/a/aab/bb/', '/a/aa/', '../aab/bb/'),
841841
array('/a/aab/bb/', '/', 'a/aab/bb/'),
842842
array('/a/aab/bb/', '/b/aab', '../../a/aab/bb/'),
843+
array('/aab/bb', '/aa', '../aab/bb/'),
844+
array('/aab', '/aa', '../aab/'),
843845
);
844846

845847
if ('\\' === DIRECTORY_SEPARATOR) {

src/Symfony/Component/Form/Tests/Extension/Validator/Type/BaseValidatorExtensionTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public function testValidationGroupsCanBeSetToCallback()
5858
'validation_groups' => array($this, 'testValidationGroupsCanBeSetToCallback'),
5959
));
6060

61-
$this->assertTrue(is_callable($form->getConfig()->getOption('validation_groups')));
61+
$this->assertInternalType('callable', $form->getConfig()->getOption('validation_groups'));
6262
}
6363

6464
public function testValidationGroupsCanBeSetToClosure()
@@ -67,7 +67,7 @@ public function testValidationGroupsCanBeSetToClosure()
6767
'validation_groups' => function (FormInterface $form) { },
6868
));
6969

70-
$this->assertTrue(is_callable($form->getConfig()->getOption('validation_groups')));
70+
$this->assertInternalType('callable', $form->getConfig()->getOption('validation_groups'));
7171
}
7272

7373
abstract protected function createForm(array $options = array());

src/Symfony/Component/HttpFoundation/Response.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1008,7 +1008,7 @@ public function setVary($headers, $replace = true)
10081008
*/
10091009
public function isNotModified(Request $request)
10101010
{
1011-
if (!$request->isMethodSafe()) {
1011+
if (!$request->isMethodCacheable()) {
10121012
return false;
10131013
}
10141014

src/Symfony/Component/HttpKernel/DataCollector/DumpDataCollector.php

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -92,21 +92,24 @@ public function dump(Data $data)
9292

9393
break;
9494
} elseif (isset($trace[$i]['object']) && $trace[$i]['object'] instanceof \Twig_Template) {
95-
$info = $trace[$i]['object'];
96-
$name = $info->getTemplateName();
97-
$src = method_exists($info, 'getSource') ? $info->getSource() : $info->getEnvironment()->getLoader()->getSource($name);
98-
$info = $info->getDebugInfo();
95+
$template = $trace[$i]['object'];
96+
$name = $template->getTemplateName();
97+
$file = method_exists($template, 'getSourceContext') ? $template->getSourceContext()->getPath() : false;
98+
$src = method_exists($template, 'getSourceContext') ? $template->getSourceContext()->getCode() : (method_exists($template, 'getSource') ? $template->getSource() : false);
99+
$info = $template->getDebugInfo();
99100
if (null !== $src && isset($info[$trace[$i - 1]['line']])) {
100-
$file = false;
101101
$line = $info[$trace[$i - 1]['line']];
102-
$src = explode("\n", $src);
103-
$fileExcerpt = array();
104102

105-
for ($i = max($line - 3, 1), $max = min($line + 3, count($src)); $i <= $max; ++$i) {
106-
$fileExcerpt[] = '<li'.($i === $line ? ' class="selected"' : '').'><code>'.$this->htmlEncode($src[$i - 1]).'</code></li>';
107-
}
103+
if ($src) {
104+
$src = explode("\n", $src);
105+
$fileExcerpt = array();
106+
107+
for ($i = max($line - 3, 1), $max = min($line + 3, count($src)); $i <= $max; ++$i) {
108+
$fileExcerpt[] = '<li'.($i === $line ? ' class="selected"' : '').'><code>'.$this->htmlEncode($src[$i - 1]).'</code></li>';
109+
}
108110

109-
$fileExcerpt = '<ol start="'.max($line - 3, 1).'">'.implode("\n", $fileExcerpt).'</ol>';
111+
$fileExcerpt = '<ol start="'.max($line - 3, 1).'">'.implode("\n", $fileExcerpt).'</ol>';
112+
}
110113
}
111114
break;
112115
}

0 commit comments

Comments
 (0)
0