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

Skip to content

Commit d0e8476

Browse files
committed
Merge branch '3.2'
* 3.2: [FrameworkBundle] Ignore AnnotationException exceptions in the AnnotationsCacheWarmer fixed @return when returning this or static override property constraints in child class removed unneeded comment [Console] improved code coverage of Command class [FrameworkBundle] Make TemplateController working without the Templating component [FrameworkBundle] Allow multiple transactions with the same name Only count on arrays or countables to avoid warnings in PHP 7.2
2 parents 5a0157f + f4a6359 commit d0e8476

File tree

93 files changed

+714
-392
lines changed

Some content is hidden

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

93 files changed

+714
-392
lines changed

src/Symfony/Bridge/Twig/NodeVisitor/Scope.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public function __construct(Scope $parent = null)
4242
/**
4343
* Opens a new child scope.
4444
*
45-
* @return Scope
45+
* @return self
4646
*/
4747
public function enter()
4848
{
@@ -52,7 +52,7 @@ public function enter()
5252
/**
5353
* Closes current scope and returns parent one.
5454
*
55-
* @return Scope|null
55+
* @return self|null
5656
*/
5757
public function leave()
5858
{
@@ -67,7 +67,7 @@ public function leave()
6767
* @param string $key
6868
* @param mixed $value
6969
*
70-
* @return Scope Current scope
70+
* @return $this
7171
*
7272
* @throws \LogicException
7373
*/

src/Symfony/Bundle/FrameworkBundle/CacheWarmer/AnnotationsCacheWarmer.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace Symfony\Bundle\FrameworkBundle\CacheWarmer;
1313

14+
use Doctrine\Common\Annotations\AnnotationException;
1415
use Doctrine\Common\Annotations\CachedReader;
1516
use Doctrine\Common\Annotations\Reader;
1617
use Psr\Cache\CacheItemPoolInterface;
@@ -75,6 +76,15 @@ public function warmUp($cacheDir)
7576
$this->readAllComponents($reader, $class);
7677
} catch (\ReflectionException $e) {
7778
// ignore failing reflection
79+
} catch (AnnotationException $e) {
80+
/*
81+
* Ignore any AnnotationException to not break the cache warming process if an Annotation is badly
82+
* configured or could not be found / read / etc.
83+
*
84+
* In particular cases, an Annotation in your code can be used and defined only for a specific
85+
* environment but is always added to the annotations.map file by some Symfony default behaviors,
86+
* and you always end up with a not found Annotation.
87+
*/
7888
}
7989
}
8090
} finally {

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,13 @@ class TemplateController implements ContainerAwareInterface
3636
*/
3737
public function templateAction($template, $maxAge = null, $sharedAge = null, $private = null)
3838
{
39-
/** @var $response \Symfony\Component\HttpFoundation\Response */
40-
$response = $this->container->get('templating')->renderResponse($template);
39+
if ($this->container->has('templating')) {
40+
$response = $this->container->get('templating')->renderResponse($template);
41+
} elseif ($this->container->has('twig')) {
42+
$response = new Response($this->container->get('twig')->render($template));
43+
} else {
44+
throw new \LogicException('You can not use the TemplateController if the Templating Component or the Twig Bundle are not available.');
45+
}
4146

4247
if ($maxAge) {
4348
$response->setMaxAge($maxAge);

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

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,11 +296,33 @@ private function addWorkflowSection(ArrayNodeDefinition $rootNode)
296296
->end()
297297
->end()
298298
->arrayNode('transitions')
299-
->useAttributeAsKey('name')
299+
->beforeNormalization()
300+
->always()
301+
->then(function ($transitions) {
302+
// It's an indexed array, we let the validation occurs
303+
if (isset($transitions[0])) {
304+
return $transitions;
305+
}
306+
307+
foreach ($transitions as $name => $transition) {
308+
if (array_key_exists('name', $transition)) {
309+
continue;
310+
}
311+
$transition['name'] = $name;
312+
$transitions[$name] = $transition;
313+
}
314+
315+
return $transitions;
316+
})
317+
->end()
300318
->isRequired()
301319
->requiresAtLeastOneElement()
302320
->prototype('array')
303321
->children()
322+
->scalarNode('name')
323+
->isRequired()
324+
->cannotBeEmpty()
325+
->end()
304326
->arrayNode('from')
305327
->beforeNormalization()
306328
->ifString()

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -417,13 +417,13 @@ private function registerWorkflowConfiguration(array $workflows, ContainerBuilde
417417
$type = $workflow['type'];
418418

419419
$transitions = array();
420-
foreach ($workflow['transitions'] as $transitionName => $transition) {
420+
foreach ($workflow['transitions'] as $transition) {
421421
if ($type === 'workflow') {
422-
$transitions[] = new Definition(Workflow\Transition::class, array($transitionName, $transition['from'], $transition['to']));
422+
$transitions[] = new Definition(Workflow\Transition::class, array($transition['name'], $transition['from'], $transition['to']));
423423
} elseif ($type === 'state_machine') {
424424
foreach ($transition['from'] as $from) {
425425
foreach ($transition['to'] as $to) {
426-
$transitions[] = new Definition(Workflow\Transition::class, array($transitionName, $from, $to));
426+
$transitions[] = new Definition(Workflow\Transition::class, array($transition['name'], $from, $to));
427427
}
428428
}
429429
}
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <[email protected]>
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\Tests\Controller;
13+
14+
use Symfony\Bundle\FrameworkBundle\Controller\TemplateController;
15+
use Symfony\Bundle\FrameworkBundle\Tests\TestCase;
16+
use Symfony\Component\HttpFoundation\Response;
17+
18+
/**
19+
* @author Kévin Dunglas <[email protected]>
20+
*/
21+
class TemplateControllerTest extends TestCase
22+
{
23+
public function testTwig()
24+
{
25+
$twig = $this->getMockBuilder('\Twig_Environment')->disableOriginalConstructor()->getMock();
26+
$twig->expects($this->once())->method('render')->willReturn('bar');
27+
28+
$container = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerInterface')->getMock();
29+
$container->expects($this->at(0))->method('has')->will($this->returnValue(false));
30+
$container->expects($this->at(1))->method('has')->will($this->returnValue(true));
31+
$container->expects($this->at(2))->method('get')->will($this->returnValue($twig));
32+
33+
$controller = new TemplateController();
34+
$controller->setContainer($container);
35+
36+
$this->assertEquals('bar', $controller->templateAction('mytemplate')->getContent());
37+
}
38+
39+
public function testTemplating()
40+
{
41+
$templating = $this->getMockBuilder('Symfony\Bundle\FrameworkBundle\Templating\EngineInterface')->getMock();
42+
$templating->expects($this->once())->method('renderResponse')->willReturn(new Response('bar'));
43+
44+
$container = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerInterface')->getMock();
45+
$container->expects($this->at(0))->method('has')->willReturn(true);
46+
$container->expects($this->at(1))->method('get')->will($this->returnValue($templating));
47+
48+
$controller = new TemplateController();
49+
$controller->setContainer($container);
50+
51+
$this->assertEquals('bar', $controller->templateAction('mytemplate')->getContent());
52+
}
53+
54+
/**
55+
* @expectedException \LogicException
56+
* @expectedExceptionMessage You can not use the TemplateController if the Templating Component or the Twig Bundle are not available.
57+
*/
58+
public function testNoTwigNorTemplating()
59+
{
60+
$container = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerInterface')->getMock();
61+
$container->expects($this->at(0))->method('has')->willReturn(false);
62+
$container->expects($this->at(1))->method('has')->willReturn(false);
63+
64+
$controller = new TemplateController();
65+
$controller->setContainer($container);
66+
67+
$controller->templateAction('mytemplate')->getContent();
68+
}
69+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<?php
2+
3+
use Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection\FrameworkExtensionTest;
4+
5+
$container->loadFromExtension('framework', array(
6+
'workflows' => array(
7+
'article' => array(
8+
'type' => 'workflow',
9+
'marking_store' => array(
10+
'type' => 'multiple_state',
11+
),
12+
'supports' => array(
13+
FrameworkExtensionTest::class,
14+
),
15+
'initial_place' => 'draft',
16+
'places' => array(
17+
'draft',
18+
'wait_for_journalist',
19+
'approved_by_journalist',
20+
'wait_for_spellchecker',
21+
'approved_by_spellchecker',
22+
'published',
23+
),
24+
'transitions' => array(
25+
'request_review' => array(
26+
'from' => 'draft',
27+
'to' => array('wait_for_journalist', 'wait_for_spellchecker'),
28+
),
29+
'journalist_approval' => array(
30+
'from' => 'wait_for_journalist',
31+
'to' => 'approved_by_journalist',
32+
),
33+
'spellchecker_approval' => array(
34+
'from' => 'wait_for_spellchecker',
35+
'to' => 'approved_by_spellchecker',
36+
),
37+
'publish' => array(
38+
'from' => array('approved_by_journalist', 'approved_by_spellchecker'),
39+
'to' => 'published',
40+
),
41+
'publish_editor_in_chief' => array(
42+
'name' => 'publish',
43+
'from' => 'draft',
44+
'to' => 'published',
45+
),
46+
),
47+
),
48+
),
49+
));
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<?xml version="1.0" ?>
2+
3+
<container xmlns="http://symfony.com/schema/dic/services"
4+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5+
xmlns:framework="http://symfony.com/schema/dic/symfony"
6+
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd
7+
http://symfony.com/schema/dic/symfony http://symfony.com/schema/dic/symfony/symfony-1.0.xsd">
8+
9+
<framework:config>
10+
<framework:workflow name="article" type="workflow" initial-place="draft">
11+
<framework:marking-store type="multiple_state">
12+
<framework:argument>a</framework:argument>
13+
<framework:argument>a</framework:argument>
14+
</framework:marking-store>
15+
<framework:support>Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection\FrameworkExtensionTest</framework:support>
16+
<framework:place>draft</framework:place>
17+
<framework:place>wait_for_journalist</framework:place>
18+
<framework:place>approved_by_journalist</framework:place>
19+
<framework:place>wait_for_spellchecker</framework:place>
20+
<framework:place>approved_by_spellchecker</framework:place>
21+
<framework:place>published</framework:place>
22+
<framework:transition name="request_review">
23+
<framework:from>draft</framework:from>
24+
<framework:to>wait_for_journalist</framework:to>
25+
<framework:to>wait_for_spellchecker</framework:to>
26+
</framework:transition>
27+
<framework:transition name="journalist_approval">
28+
<framework:from>wait_for_journalist</framework:from>
29+
<framework:to>approved_by_journalist</framework:to>
30+
</framework:transition>
31+
<framework:transition name="spellchecker_approval">
32+
<framework:from>wait_for_spellchecker</framework:from>
33+
<framework:to>approved_by_spellchecker</framework:to>
34+
</framework:transition>
35+
<framework:transition name="publish">
36+
<framework:from>approved_by_journalist</framework:from>
37+
<framework:from>approved_by_spellchecker</framework:from>
38+
<framework:to>published</framework:to>
39+
</framework:transition>
40+
<framework:transition name="publish">
41+
<framework:from>draft</framework:from>
42+
<framework:to>published</framework:to>
43+
</framework:transition>
44+
</framework:workflow>
45+
</framework:config>
46+
</container>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
framework:
2+
workflows:
3+
article:
4+
type: workflow
5+
marking_store:
6+
type: multiple_state
7+
supports:
8+
- Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection\FrameworkExtensionTest
9+
initial_place: draft
10+
places:
11+
- draft
12+
- wait_for_journalist
13+
- approved_by_journalist
14+
- wait_for_spellchecker
15+
- approved_by_spellchecker
16+
- published
17+
transitions:
18+
request_review:
19+
from: [draft]
20+
to: [wait_for_journalist, wait_for_spellchecker]
21+
journalist_approval:
22+
from: [wait_for_journalist]
23+
to: [approved_by_journalist]
24+
spellchecker_approval:
25+
from: [wait_for_spellchecker]
26+
to: [approved_by_spellchecker]
27+
publish:
28+
from: [approved_by_journalist, approved_by_spellchecker]
29+
to: [published]
30+
publish_editor_in_chief:
31+
name: publish
32+
from: [draft]
33+
to: [published]

src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,29 @@ public function testWorkflowCannotHaveBothArgumentsAndService()
190190
$this->createContainerFromFile('workflow_with_arguments_and_service');
191191
}
192192

193+
public function testWorkflowMultipleTransitionsWithSameName()
194+
{
195+
$container = $this->createContainerFromFile('workflow_with_multiple_transitions_with_same_name');
196+
197+
$this->assertTrue($container->hasDefinition('workflow.article', 'Workflow is registered as a service'));
198+
$this->assertTrue($container->hasDefinition('workflow.article.definition', 'Workflow definition is registered as a service'));
199+
200+
$workflowDefinition = $container->getDefinition('workflow.article.definition');
201+
202+
$transitions = $workflowDefinition->getArgument(1);
203+
204+
$this->assertCount(5, $transitions);
205+
206+
$this->assertSame('request_review', $transitions[0]->getArgument(0));
207+
$this->assertSame('journalist_approval', $transitions[1]->getArgument(0));
208+
$this->assertSame('spellchecker_approval', $transitions[2]->getArgument(0));
209+
$this->assertSame('publish', $transitions[3]->getArgument(0));
210+
$this->assertSame('publish', $transitions[4]->getArgument(0));
211+
212+
$this->assertSame(array('approved_by_journalist', 'approved_by_spellchecker'), $transitions[3]->getArgument(1));
213+
$this->assertSame(array('draft'), $transitions[4]->getArgument(1));
214+
}
215+
193216
public function testRouter()
194217
{
195218
$container = $this->createContainerFromFile('full');

src/Symfony/Component/BrowserKit/Cookie.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ public function __toString()
121121
* @param string $cookie A Set-Cookie header value
122122
* @param string $url The base URL
123123
*
124-
* @return Cookie A Cookie instance
124+
* @return static
125125
*
126126
* @throws \InvalidArgumentException
127127
*/

0 commit comments

Comments
 (0)