8000 Merge branch '2.7' · symfony/symfony@b33b1dc · GitHub
[go: up one dir, main page]

Skip to content
8000

Commit b33b1dc

Browse files
committed
Merge branch '2.7'
* 2.7: (24 commits) bumped Symfony version to 2.6.4 updated VERSION for 2.6.3 updated CHANGELOG for 2.6.3 bumped Symfony version to 2.6.3 updated VERSION for 2.6.2 updated CHANGELOG for 2.6.2 bumped Symfony version to 2.5.10 updated VERSION for 2.5.9 updated CHANGELOG for 2.5.9 [FrameworkBundle] Use security.token_storage service in Controller::getUser() bumped Symfony version to 2.3.25 updated VERSION for 2.3.24 update CONTRIBUTORS for 2.3.24 added missing E_USER_DEPRECATED argument to trigger_error() calls Removed unneeded version requirements updated CHANGELOG for 2.3.24 fixed tests [Security] Don't destroy the session on buggy php releases. Enhance deprecation summary at end of tests [2.7] silence deprecations for getFactory*() BC layer ... Conflicts: CHANGELOG-2.3.md CHANGELOG-2.5.md CHANGELOG-2.6.md src/Symfony/Component/Form/Tests/ResolvedFormTypeTest.php
2 parents e60a007 + 0577065 commit b33b1dc

32 files changed

+760
-282
lines changed

CONTRIBUTORS.md

Lines changed: 59 additions & 30 deletions
Large diffs are not rendered by default.

autoload.php.dist

Lines changed: 65 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,19 @@ class DeprecationErrorHandler
2020
if (self::$isRegistered) {
2121
return;
2222
}
23-
$deprecations = array(0);
24-
$oldErrorHandler = set 10000 _error_handler(function ($type, $msg, $file, $line, $context) use (&$deprecations) {
23+
$deprecations = array(
24+
'remainingCount' => 0,
25+
'legacyCount' => 0,
26+
'otherCount' => 0,
27+
'remaining' => array(),
28+
'legacy' => array(),
29+
'other' => array(),
30+
);
31+
$deprecationHandler = function ($type, $msg, $file, $line, $context) use (&$deprecations) {
2532
if (E_USER_DEPRECATED !== $type) {
2633
return PHPUnit_Util_ErrorHandler::handleError($type, $msg, $file, $line, $context);
2734
}
2835

29-
++$deprecations[0];
3036
$trace = debug_backtrace(PHP_VERSION_ID >= 50400 ? DEBUG_BACKTRACE_IGNORE_ARGS : false);
3137

3238
$i = count($trace);
@@ -35,13 +41,24 @@ class DeprecationErrorHandler
3541
}
3642

3743
if (isset($trace[$i]['class'])) {
38-
if (isset($deprecations[$trace[$i]['class']][$trace[$i]['function']][$msg])) {
39-
++$deprecations[$trace[$i]['class']][$trace[$i]['function']][$msg];
44+
$class = $trace[$i]['class'];
45+
$method = $trace[$i]['function'];
46+
47+
$type = 0 === strpos($method, 'testLegacy') || 0 === strpos($method, 'provideLegacy') || strpos($class, '\Legacy') ? 'legacy' : 'remaining';
48+
49+
if ('legacy' === $type && 0 === (error_reporting() & E_USER_DEPRECATED)) {
50+
@++$deprecations[$type]['Silenced']['count'];
4051
} else {
41-
$deprecations[$trace[$i]['class']][$trace[$i]['function']][$msg] = 1;
52+
@++$deprecations[$type][$msg]['count'];
53+
@++$deprecations[$type][$msg][$class.'::'.$method];
4254
}
55+
} else {
56+
$type = 'other';
57+
@++$deprecations[$type][$msg]['count'];
4358
}
44-
});
59+
++$deprecations[$type.'Count'];
60+
};
61+
$oldErrorHandler = set_error_handler($deprecationHandler);
4562

4663
if (null !== $oldErrorHandler) {
4764
restore_error_handler();
@@ -51,31 +68,52 @@ class DeprecationErrorHandler
5168
}
5269
} else {
5370
self::$isRegistered = true;
54-
register_shutdown_function(function () use (&$deprecations) {
55-
if ($deprecations[0]) {
56-
if (function_exists('posix_isatty') && @posix_isatty(STDOUT)) {
57-
echo "\n\x1B[43;30mDeprecation notices ($deprecations[0]):\x1B[0m\n";
58-
} else {
59-
echo "\nDeprecation notices ($deprecations[0]):\n";
60-
}
71+
register_shutdown_function(function () use (&$deprecations, $deprecationHandler) {
72+
73+
$colorize = new \SebastianBergmann\Environment\Console();
74+
75+
if ($colorize->hasColorSupport()) {
76+
$colorize = function ($str, $red) {
77+
$color = $red ? '41;37' : '43;30';
78+
79+
return "\x1B[{$color}m{$str}\x1B[0m";
80+
};
81+
} else {
82+
$colorize = function ($str) {return $str;};
83+
}
84+
85+
$currErrorHandler = set_error_handler('var_dump');
86+
restore_error_handler();
6187

62-
foreach ($deprecations as $class => $notices) {
63-
if (0 !== $class) {
64-
echo "\n{$class}\n";
65-
foreach ($notices as $method => $notices) {
66-
echo " ->{$method}()\n";
67-
foreach ($notices as $msg => $freq) {
68-
echo " {$msg}: $freq\n";
88+
if ($currErrorHandler !== $deprecationHandler) {
89+
echo "\n", $colorize('THE ERROR HANDLER HAS CHANGED!', true), "\n";
90+
}
91+
92+
$cmp = function ($a, $b) {
93+
return $b['count'] - $a['count'];
94+
};
95+
96+
foreach (array('remaining', 'legacy', 'other') as $type) {
97+
if ($deprecations[$type]) {
98+
echo "\n", $colorize(sprintf('%s deprecation notices (%d)', ucfirst($type), $deprecations[$type.'Count']), 'legacy' !== $type), "\n";
99+
100+
uasort($deprecations[$type], $cmp);
101+
102+
foreach ($deprecations[$type] as $msg => $notices) {
103+
echo "\n", $msg, ': ', $notices['count'], "x\n";
104+
105+
arsort($notices);
106+
107+
foreach ($notices as $method => $count) {
108+
if ('count' !== $method) {
109+
echo ' ', $count, 'x in ', preg_replace('/(.*)\\\\(.*?::.*?)$/', '$2 from $1', $method), "\n";
69110
}
70111
}
71112
}
72113
}
73-
} else {
74-
if (function_exists('posix_isatty') && @posix_isatty(STDOUT)) {
75-
echo "\n\x1B[42;30mNo deprecation notice\x1B[0m\n";
76-
} else {
77-
echo "\nNo deprecation notice\n";
78-
}
114+
}
115+
if (!empty($notices)) {
116+
echo "\n";
79117
}
80118
});
81119
}

src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/XmlDescriptor.php

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -331,16 +331,18 @@ private function getContainerDefinitionDocument(Definition $definition, $id = nu
331331

332332
$serviceXML->setAttribute('class', $definition->getClass());
333333

334-
if ($definition->getFactoryClass()) {
335-
$serviceXML->setAttribute('factory-class', $definition->getFactoryClass());
336-
}
334+
if (method_exists($definition, 'getFactoryMethod')) {
335+
if ($definition->getFactoryClass(false)) {
336+
$serviceXML->setAttribute('factory-class', $definition->getFactoryClass(false));
337+
}
337338

338-
if ($definition->getFactoryService()) {
339-
$serviceXML->setAttribute('factory-service', $definition->getFactoryService());
340-
}
339+
if ($definition->getFactoryService(false)) {
340+
$serviceXML->setAttribute('factory-service', $definition->getFactoryService(false));
341+
}
341342

342-
if ($definition->getFactoryMethod()) {
343-
$serviceXML->setAttribute('factory-method', $definition->getFactoryMethod());
343+
if ($definition->getFactoryMethod(false)) {
344+
$serviceXML->setAttribute('factory-method', $definition->getFactoryMethod(false));
345+
}
344346
}
345347

346348
if ($factory = $definition->getFactory()) {

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ protected function getDoctrine()
279279
}
280280

281281
/**
282-
* Get a user from the Security Context.
282+
* Get a user from the Security Token Storage.
283283
*
284284
* @return mixed
285285
*
@@ -289,15 +289,16 @@ protected function getDoctrine()
289289
*/
290290
protected function getUser()
291291
{
292-
if (!$this->container->has('security.context')) {
292+
if (!$this->container->has('security.token_storage')) {
293293
throw new \LogicException('The SecurityBundle is not registered in your application.');
294294
}
295295

296-
if (null === $token = $this->container->get('security.context')->getToken()) {
296+
if (null === $token = $this->container->get('security.token_storage')->getToken()) {
297297
return;
298298
}
299299

300300
if (!is_object($user = $token->getUser())) {
301+
// e.g. anonymous authentication
301302
return;
302303
}
303304

src/Symfony/Bundle/FrameworkBundle/Tests/Controller/ControllerTest.php

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,13 @@
1313

1414
use Symfony\Bundle\FrameworkBundle\Tests\TestCase;
1515
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
16+
use Symfony\Component\DependencyInjection\ContainerInterface;
1617
use Symfony\Component\HttpFoundation\Request;
1718
use Symfony\Component\HttpFoundation\RequestStack;
1819
use Symfony\Component\HttpFoundation\Response;
20+
use Symfony\Component\Security\Core\Authentication\Token\AnonymousToken;
21+
use Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken;
22+
use Symfony\Component\Security\Core\User\User;
1923

2024
class ControllerTest extends TestCase
2125
{
@@ -43,6 +47,95 @@ public function testForward()
4347
$response = $controller->forward('a_controller');
4448
$this->assertEquals('xml--fr', $response->getContent());
4549
}
50+
51+
public function testGetUser()
52+
{
53+
$user = new User('user', 'pass');
54+
$token = new UsernamePasswordToken($user, 'pass', 'default', array('ROLE_USER'));
55+
56+
$controller = new TestController();
57+
$controller->setContainer($this->getContainerWithTokenStorage($token));
58+
59+
$this->assertSame($controller->getUser(), $user);
60+
}
61+
62+
public function testGetUserAnonymousUserConvertedToNull()
63+
{
64+
$token = new AnonymousToken('default', 'anon.');
65+
66+
$controller = new TestController();
67+
$controller->setContainer($this->getContainerWithTokenStorage($token));
68+
69+
$this->assertNull($controller->getUser());
70+
}
71+
72+
public function testGetUserWithEmptyTokenStorage()
73+
{
74+
$controller = new TestController();
75+
$controller->setContainer($this->getContainerWithTokenStorage(null));
76+
77+
$this->assertNull($controller->getUser());
78+
}
79+
80+
/**
81+
* @expectedException \LogicException
82+
* @expectedExceptionMessage The SecurityBundle is not registered in your application.
83+
*/
84+
public function testGetUserWithEmptyContainer()
85+
{
86+
$container = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface');
87+
$container
88+
->expects($this->once())
89+
->method('has')
90+
->with('security.token_storage')
91+
->will($this->returnValue(false));
92+
93+
$controller = new TestController();
94+
$controller->setContainer($container);
95+
96+
$controller->getUser();
97+
}
98+
99+
/**
100+
* @param $token
101+
* @return ContainerInterface
102+
*/
103+
private function getContainerWithTokenStorage($token = null)
104+
{
105+
$tokenStorage = $this->getMock('Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorage');
106+
$tokenStorage
107+
->expects($this->once())
108+
->method('getToken')
109+
->will($this->returnValue($token));
110+
111+
$container = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface');
112+
$container
113+
->expects($this->once())
114+
->method('has')
115+
->with('security.token_storage')
116+
->will($this->returnValue(true));
117+
118+
$container
119+
->expects($this->once())
120+
->method('get')
121+
->with('security.token_storage')
122+
->will($this->returnValue($tokenStorage));
123+
124+
return $container;
125+
}
126+
}
127+
128+
class TestController extends Controller
129+
{
130+
public function forward($controller, array $path = array(), array $query = array())
131+
{
132+
return parent::forward($controller, $path, $query);
133+
}
134+
135+
public function getUser()
136+
{
137+
return parent::getUser();
138+
}
46139
}
47140

48141
class TestController extends Controller

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,8 @@ public function process(ContainerBuilder $container)
7171
$this->currentDefinition = $definition;
7272

7373
$this->processArguments($definition->getArguments());
74-
if ($definition->getFactoryService()) {
75-
$this->processArguments(array(new Reference($definition->getFactoryService())));
74+
if ($definition->getFactoryService(false)) {
75+
$this->processArguments(array(new Reference($definition->getFactoryService(false))));
7676
}
7777
if (is_array($definition->getFactory())) {
7878
$this->processArguments($definition->getFactory());
@@ -118,8 +118,8 @@ private function processArguments(array $arguments)
118118
if (is_array($argument->getFactory())) {
119119
$this->processArguments($argument->getFactory());
120120
}
121-
if ($argument->getFactoryService()) {
122-
$this->processArguments(array(new Reference($argument->getFactoryService())));
121+
if ($argument->getFactoryService(false)) {
122+
$this->processArguments(array(new Reference($argument->getFactoryService(false))));
123123
}
124124
}
125125
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,13 @@ public function process(ContainerBuilder $container)
5050
throw new RuntimeException(sprintf('A synthetic service ("%s") cannot be of scope "prototype".', $id));
5151
}
5252

53-
if ($definition->getFactory() && ($definition->getFactoryClass() || $definition->getFactoryService() || $definition->getFactoryMethod())) {
53+
if ($definition->getFactory() && ($definition->getFactoryClass(false) || $definition->getFactoryService(false) || $definition->getFactoryMethod(false))) {
5454
throw new RuntimeException(sprintf('A service ("%s") can use either the old or the new factory syntax, not both.', $id));
5555
}
5656

5757
// non-synthetic, non-abstract service has class
5858
if (!$definition->isAbstract() && !$definition->isSynthetic() && !$definition->getClass()) {
59-
if ($definition->getFactory() || $definition->getFactoryClass() || $definition->getFactoryService()) {
59+
if ($definition->getFactory() || $definition->getFactoryClass(false) || $definition->getFactoryService(false)) {
6060
throw new RuntimeException(sprintf('Please add the class to service "%s" even if it is constructed by a factory since we might need to add method calls based on compile-time checks.', $id));
6161
}
6262

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ private function isInlineableDefinition(ContainerBuilder $container, $id, Defini
148148
return false;
149149
}
150150

151-
if (count($ids) > 1 && $definition->getFactoryService()) {
151+
if (count($ids) > 1 && $definition->getFactoryService(false)) {
152152
return false;
153153
}
154154

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

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,15 @@ private function resolveDefinition($id, DefinitionDecorator $definition)
8181
$def->setArguments($parentDef->getArguments());
8282
$def->setMethodCalls($parentDef->getMethodCalls());
8383
$def->setProperties($parentDef->getProperties());
84-
$def->setFactoryClass($parentDef->getFactoryClass());
85-
$def->setFactoryMethod($parentDef->getFactoryMethod());
86-
$def->setFactoryService($parentDef->getFactoryService());
84+
if ($parentDef->getFactoryClass(false)) {
85+
$def->setFactoryClass($parentDef->getFactoryClass(false));
86+
}
87+
if ($parentDef->getFactoryMethod(false)) {
88+
$def->setFactoryMethod($parentDef->getFactoryMethod(false));
89+
}
90+
if ($parentDef->getFactoryService(false)) {
91+
$def->setFactoryService($parentDef->getFactoryService(false));
92+
}
8793
$def->setFactory($parentDef->getFactory());
8894
$def->setConfigurator($parentDef->getConfigurator());
8995
$def->setFile($parentDef->getFile());
@@ -96,13 +102,13 @@ private function resolveDefinition($id, DefinitionDecorator $definition)
96102
$def->setClass($definition->getClass());
97103
}
98104
if (isset($changes['factory_class'])) {
99-
$def->setFactoryClass($definition->getFactoryClass());
105+
$def->setFactoryClass($definition->getFactoryClass(false));
100106
}
101107
if (isset($changes['factory_method'])) {
102-
$def->setFactoryMethod($definition->getFactoryMethod());
108+
$def->setFactoryMethod($definition->getFactoryMethod(false));
103109
}
104110
if (isset($changes['factory_service'])) {
105-
$def->setFactoryService($definition->getFactoryService());
111+
$def->setFactoryService($definition->getFactoryService(false));
106112
}
107113
if (isset($changes['factory'])) {
108114
$def->setFactory($definition->getFactory());

src/Symfony/Component/DependencyInjection/ContainerBuilder.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -944,16 +944,16 @@ private function createService(Definition $definition, $id, $tryProxy = true)
944944
}
945945

946946
$service = call_user_func_array($factory, $arguments);
947-
} elseif (null !== $definition->getFactoryMethod()) {
948-
if (null !== $definition->getFactoryClass()) {
949-
$factory = $parameterBag->resolveValue($definition->getFactoryClass());
950-
} elseif (null !== $definition->getFactoryService()) {
951-
$factory = $this->get($parameterBag->resolveValue($definition->getFactoryService()));
947+
} elseif (null !== $definition->getFactoryMethod(false)) {
948+
if (null !== $definition->getFactoryClass(false)) {
949+
$factory = $parameterBag->resolveValue($definition->getFactoryClass(false));
950+
} elseif (null !== $definition->getFactoryService(false)) {
951+
$factory = $this->get($parameterBag->resolveValue($definition->getFactoryService(false)));
952952
} else {
953953
throw new RuntimeException(sprintf('Cannot create service "%s" from factory method without a factory service or factory class.', $id));
954954
}
955955

956-
$service = call_user_func_array(array($factory, $definition->getFactoryMethod()), $arguments);
956+
$service = call_user_func_array(array($factory, $definition->getFactoryMethod(false)), $arguments);
957957
} else {
958958
$r = new \ReflectionClass($parameterBag->resolveValue($definition->getClass()));
959959

0 commit comments

Comments
 (0)
0