Merge branch '4.1'
* 4.1: [Debug] fix detecting overriden final/internal methods implemented using traits [Controller][ServiceValueResolver] Making method access case insensitive
This commit is contained in:
commit
d4e1cd9869
@ -246,25 +246,23 @@ class DebugClassLoader
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Method from a trait
|
|
||||||
if ($method->getFilename() !== $refl->getFileName()) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($isClass && $parent && isset(self::$finalMethods[$parent][$method->name])) {
|
if ($isClass && $parent && isset(self::$finalMethods[$parent][$method->name])) {
|
||||||
list($declaringClass, $message) = self::$finalMethods[$parent][$method->name];
|
list($declaringClass, $message) = self::$finalMethods[$parent][$method->name];
|
||||||
@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);
|
@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);
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ($parentAndTraits as $use) {
|
if (isset(self::$internalMethods[$name][$method->name])) {
|
||||||
if (isset(self::$internalMethods[$use][$method->name])) {
|
list($declaringClass, $message) = self::$internalMethods[$name][$method->name];
|
||||||
list($declaringClass, $message) = self::$internalMethods[$use][$method->name];
|
if (\strncmp($ns, $declaringClass, $len)) {
|
||||||
if (\strncmp($ns, $declaringClass, $len)) {
|
@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);
|
||||||
@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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Method from a trait
|
||||||
|
if ($method->getFilename() !== $refl->getFileName()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
// Detect method annotations
|
// Detect method annotations
|
||||||
if (false === $doc = $method->getDocComment()) {
|
if (false === $doc = $method->getDocComment()) {
|
||||||
continue;
|
continue;
|
||||||
|
@ -220,24 +220,21 @@ class DebugClassLoaderTest extends TestCase
|
|||||||
|
|
||||||
public function testExtendedFinalMethod()
|
public function testExtendedFinalMethod()
|
||||||
{
|
{
|
||||||
set_error_handler(function () { return false; });
|
$deprecations = array();
|
||||||
$e = error_reporting(0);
|
set_error_handler(function ($type, $msg) use (&$deprecations) { $deprecations[] = $msg; });
|
||||||
trigger_error('', E_USER_NOTICE);
|
$e = error_reporting(E_USER_DEPRECATED);
|
||||||
|
|
||||||
class_exists(__NAMESPACE__.'\\Fixtures\\ExtendedFinalMethod', true);
|
class_exists(__NAMESPACE__.'\\Fixtures\\ExtendedFinalMethod', true);
|
||||||
|
|
||||||
error_reporting($e);
|
error_reporting($e);
|
||||||
restore_error_handler();
|
restore_error_handler();
|
||||||
|
|
||||||
$lastError = error_get_last();
|
|
||||||
unset($lastError['file'], $lastError['line']);
|
|
||||||
|
|
||||||
$xError = array(
|
$xError = array(
|
||||||
'type' => E_USER_DEPRECATED,
|
'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".',
|
||||||
'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".',
|
'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".',
|
||||||
);
|
);
|
||||||
|
|
||||||
$this->assertSame($xError, $lastError);
|
$this->assertSame($xError, $deprecations);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testExtendedDeprecatedMethodDoesntTriggerAnyNotice()
|
public function testExtendedDeprecatedMethodDoesntTriggerAnyNotice()
|
||||||
|
@ -4,6 +4,8 @@ namespace Symfony\Component\Debug\Tests\Fixtures;
|
|||||||
|
|
||||||
class ExtendedFinalMethod extends FinalMethod
|
class ExtendedFinalMethod extends FinalMethod
|
||||||
{
|
{
|
||||||
|
use FinalMethod2Trait;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
|
@ -11,6 +11,13 @@ class FinalMethod
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @final
|
||||||
|
*/
|
||||||
|
public function finalMethod2()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
public function anotherMethod()
|
public function anotherMethod()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,10 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Symfony\Component\Debug\Tests\Fixtures;
|
||||||
|
|
||||||
|
trait FinalMethod2Trait
|
||||||
|
{
|
||||||
|
public function finalMethod2()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
@ -24,3 +24,4 @@ class_exists(ExtendedFinalMethod::class);
|
|||||||
?>
|
?>
|
||||||
--EXPECTF--
|
--EXPECTF--
|
||||||
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".
|
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".
|
||||||
|
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".
|
||||||
|
@ -48,6 +48,10 @@ final class ServiceValueResolver implements ArgumentValueResolverInterface
|
|||||||
$controller = ltrim($controller, '\\');
|
$controller = ltrim($controller, '\\');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!$this->container->has($controller) && false !== $i = strrpos($controller, ':')) {
|
||||||
|
$controller = substr($controller, 0, $i).strtolower(substr($controller, $i));
|
||||||
|
}
|
||||||
|
|
||||||
return $this->container->has($controller) && $this->container->get($controller)->has($argument->getName());
|
return $this->container->has($controller) && $this->container->get($controller)->has($argument->getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -64,6 +68,11 @@ final class ServiceValueResolver implements ArgumentValueResolverInterface
|
|||||||
$controller = ltrim($controller, '\\');
|
$controller = ltrim($controller, '\\');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!$this->container->has($controller)) {
|
||||||
|
$i = strrpos($controller, ':');
|
||||||
|
$controller = substr($controller, 0, $i).strtolower(substr($controller, $i));
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
yield $this->container->get($controller)->get($argument->getName());
|
yield $this->container->get($controller)->get($argument->getName());
|
||||||
} catch (RuntimeException $e) {
|
} catch (RuntimeException $e) {
|
||||||
|
@ -68,6 +68,24 @@ class ServiceValueResolverTest extends TestCase
|
|||||||
$this->assertYieldEquals(array(new DummyService()), $resolver->resolve($request, $argument));
|
$this->assertYieldEquals(array(new DummyService()), $resolver->resolve($request, $argument));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testExistingControllerWithMethodNameStartUppercase()
|
||||||
|
{
|
||||||
|
$resolver = new ServiceValueResolver(new ServiceLocator(array(
|
||||||
|
'App\\Controller\\Mine::method' => function () {
|
||||||
|
return new ServiceLocator(array(
|
||||||
|
'dummy' => function () {
|
||||||
|
return new DummyService();
|
||||||
|
},
|
||||||
|
));
|
||||||
|
},
|
||||||
|
)));
|
||||||
|
$request = $this->requestWithAttributes(array('_controller' => 'App\\Controller\\Mine::Method'));
|
||||||
|
$argument = new ArgumentMetadata('dummy', DummyService::class, false, false, null);
|
||||||
|
|
||||||
|
$this->assertTrue($resolver->supports($request, $argument));
|
||||||
|
$this->assertYieldEquals(array(new DummyService()), $resolver->resolve($request, $argument));
|
||||||
|
}
|
||||||
|
|
||||||
public function testControllerNameIsAnArray()
|
public function testControllerNameIsAnArray()
|
||||||
{
|
{
|
||||||
$resolver = new ServiceValueResolver(new ServiceLocator(array(
|
$resolver = new ServiceValueResolver(new ServiceLocator(array(
|
||||||
|
Reference in New Issue
Block a user