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

Skip to content

Commit d4e1cd9

Browse files
Merge branch '4.1'
* 4.1: [Debug] fix detecting overriden final/internal methods implemented using traits [Controller][ServiceValueResolver] Making method access case insensitive
2 parents 344b8ce + 92a22b0 commit d4e1cd9

File tree

8 files changed

+62
-20
lines changed

8 files changed

+62
-20
lines changed

src/Symfony/Component/Debug/DebugClassLoader.php

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -246,25 +246,23 @@ private function checkClass($class, $file = null)
246246
continue;
247247
}
248248

249-
// Method from a trait
250-
if ($method->getFilename() !== $refl->getFileName()) {
251-
continue;
252-
}
253-
254249
if ($isClass && $parent && isset(self::$finalMethods[$parent][$method->name])) {
255250
list($declaringClass, $message) = self::$finalMethods[$parent][$method->name];
256251
@trigger_error(sprintf('The "%s::%s()" method is considered final%s. It may change without further notice as of its next major version. You should not extend it from "%s".', $declaringClass, $method->name, $message, $name), E_USER_DEPRECATED);
257252
}
258253

259-
foreach ($parentAndTraits as $use) {
260-
if (isset(self::$internalMethods[$use][$method->name])) {
261-
list($declaringClass, $message) = self::$internalMethods[$use][$method->name];
262-
if (\strncmp($ns, $declaringClass, $len)) {
263-
@trigger_error(sprintf('The "%s::%s()" method is considered internal%s. It may change without further notice. You should not extend it from "%s".', $declaringClass, $method->name, $message, $name), E_USER_DEPRECATED);
264-
}
254+
if (isset(self::$internalMethods[$name][$method->name])) {
255+
list($declaringClass, $message) = self::$internalMethods[$name][$method->name];
256+
if (\strncmp($ns, $declaringClass, $len)) {
257+
@trigger_error(sprintf('The "%s::%s()" method is considered internal%s. It may change without further notice. You should not extend it from "%s".', $declaringClass, $method->name, $message, $name), E_USER_DEPRECATED);
265258
}
266259
}
267260

261+
// Method from a trait
262+
if ($method->getFilename() !== $refl->getFileName()) {
263+
continue;
264+
}
265+
268266
// Detect method annotations
269267
if (false === $doc = $method->getDocComment()) {
270268
continue;

src/Symfony/Component/Debug/Tests/DebugClassLoaderTest.php

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -220,24 +220,21 @@ class_exists('Test\\'.__NAMESPACE__.'\\ExtendsFinalClass', true);
220220

221221
public function testExtendedFinalMethod()
222222
{
223-
set_error_handler(function () { return false; });
224-
$e = error_reporting(0);
225-
trigger_error('', E_USER_NOTICE);
223+
$deprecations = array();
224+
set_error_handler(function ($type, $msg) use (&$deprecations) { $deprecations[] = $msg; });
225+
$e = error_reporting(E_USER_DEPRECATED);
226226

227227
class_exists(__NAMESPACE__.'\\Fixtures\\ExtendedFinalMethod', true);
228228

229229
error_reporting($e);
230230
restore_error_handler();
231231

232-
$lastError = error_get_last();
233-
unset($lastError['file'], $lastError['line']);
234-
235232
$xError = array(
236-
'type' => E_USER_DEPRECATED,
237-
'message' => 'The "Symfony\Component\Debug\Tests\Fixtures\FinalMethod::finalMethod()" method is considered final. It may change without further notice as of its next major version. You should not extend it from "Symfony\Component\Debug\Tests\Fixtures\ExtendedFinalMethod".',
233+
'The "Symfony\Component\Debug\Tests\Fixtures\FinalMethod::finalMethod()" method is considered final. It may change without further notice as of its next major version. You should not extend it from "Symfony\Component\Debug\Tests\Fixtures\ExtendedFinalMethod".',
234+
'The "Symfony\Component\Debug\Tests\Fixtures\FinalMethod::finalMethod2()" method is considered final. It may change without further notice as of its next major version. You should not extend it from "Symfony\Component\Debug\Tests\Fixtures\ExtendedFinalMethod".',
238235
);
239236

240-
$this->assertSame($xError, $lastError);
237+
$this->assertSame($xError, $deprecations);
241238
}
242239

243240
public function testExtendedDeprecatedMethodDoesntTriggerAnyNotice()

src/Symfony/Component/Debug/Tests/Fixtures/ExtendedFinalMethod.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
class ExtendedFinalMethod extends FinalMethod
66
{
7+
use FinalMethod2Trait;
8+
79
/**
810
* {@inheritdoc}
911
*/

src/Symfony/Component/Debug/Tests/Fixtures/FinalMethod.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,13 @@ public function finalMethod()
1111
{
1212
}
1313

14+
/**
15+
* @final
16+
*/
17+
public function finalMethod2()
18+
{
19+
}
20+
1421
public function anotherMethod()
1522
{
1623
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
3+
namespace Symfony\Component\Debug\Tests\Fixtures;
4+
5+
trait FinalMethod2Trait
6+
{
7+
public function finalMethod2()
8+
{
9+
}
10+
}

src/Symfony/Component/Debug/Tests/phpt/debug_class_loader.phpt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,4 @@ class_exists(ExtendedFinalMethod::class);
2424
?>
2525
--EXPECTF--
2626
The "Symfony\Component\Debug\Tests\Fixtures\FinalMethod::finalMethod()" method is considered final. It may change without further notice as of its next major version. You should not extend it from "Symfony\Component\Debug\Tests\Fixtures\ExtendedFinalMethod".
27+
The "Symfony\Component\Debug\Tests\Fixtures\FinalMethod::finalMethod2()" method is considered final. It may change without further notice as of its next major version. You should not extend it from "Symfony\Component\Debug\Tests\Fixtures\ExtendedFinalMethod".

src/Symfony/Component/HttpKernel/Controller/ArgumentResolver/ServiceValueResolver.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@ public function supports(Request $request, ArgumentMetadata $argument)
4848
$controller = ltrim($controller, '\\');
4949
}
5050

51+
if (!$this->container->has($controller) && false !== $i = strrpos($controller, ':')) {
52+
$controller = substr($controller, 0, $i).strtolower(substr($controller, $i));
53+
}
54+
5155
return $this->container->has($controller) && $this->container->get($controller)->has($argument->getName());
5256
}
5357

@@ -64,6 +68,11 @@ public function resolve(Request $request, ArgumentMetadata $argument)
6468
$controller = ltrim($controller, '\\');
6569
}
6670

71+
if (!$this->container->has($controller)) {
72+
$i = strrpos($controller, ':');
73+
$controller = substr($controller, 0, $i).strtolower(substr($controller, $i));
74+
}
75+
6776
try {
6877
yield $this->container->get($controller)->get($argument->getName());
6978
} catch (RuntimeException $e) {

src/Symfony/Component/HttpKernel/Tests/Controller/ArgumentResolver/ServiceValueResolverTest.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,24 @@ public function testExistingControllerWithATrailingBackSlash()
6868
$this->assertYieldEquals(array(new DummyService()), $resolver->resolve($request, $argument));
6969
}
7070

71+
public function testExistingControllerWithMethodNameStartUppercase()
72+
{
73+
$resolver = new ServiceValueResolver(new ServiceLocator(array(
74+
'App\\Controller\\Mine::method' => function () {
75+
return new ServiceLocator(array(
76+
'dummy' => function () {
77+
return new DummyService();
78+
},
79+
));
80+
},
81+
)));
82+
$request = $this->requestWithAttributes(array('_controller' => 'App\\Controller\\Mine::Method'));
83+
$argument = new ArgumentMetadata('dummy', DummyService::class, false, false, null);
84+
85+
$this->assertTrue($resolver->supports($request, $argument));
86+
$this->assertYieldEquals(array(new DummyService()), $resolver->resolve($request, $argument));
87+
}
88+
7189
public function testControllerNameIsAnArray()
7290
{
7391
$resolver = new ServiceValueResolver(new ServiceLocator(array(

0 commit comments

Comments
 (0)