[Debug] track and report deprecated classes and interfaces
This commit is contained in:
parent
a1744234a2
commit
a541fafe9a
@ -30,6 +30,7 @@ class DebugClassLoader
|
||||
private $isFinder;
|
||||
private $wasFinder;
|
||||
private static $caseCheck;
|
||||
private static $deprecated = array();
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
@ -175,6 +176,22 @@ class DebugClassLoader
|
||||
if ($name !== $class && 0 === strcasecmp($name, $class)) {
|
||||
throw new \RuntimeException(sprintf('Case mismatch between loaded and declared class names: %s vs %s', $class, $name));
|
||||
}
|
||||
|
||||
if (preg_match('#\n \* @deprecated (.*?)\r?\n \*(?: @|/$)#s', $refl->getDocComment(), $notice)) {
|
||||
self::$deprecated[$name] = preg_replace('#\s*\r?\n \* +#', ' ', $notice[1]);
|
||||
} elseif (0 !== strpos($name, 'Symfony\\')) {
|
||||
$parent = $refl->getParentClass();
|
||||
|
||||
if ($parent && isset(self::$deprecated[$parent->name])) {
|
||||
trigger_error(sprintf('The %s class extends %s that is deprecated %s', $name, $parent->name, self::$deprecated[$parent->name]), E_USER_DEPRECATED);
|
||||
}
|
||||
|
||||
foreach ($refl->getInterfaceNames() as $interface) {
|
||||
if (isset(self::$deprecated[$interface]) && !($parent && $parent->implementsInterface($interface))) {
|
||||
trigger_error(sprintf('The %s %s %s that is deprecated %s', $name, $refl->isInterface() ? 'interface extends' : 'class implements', $interface, self::$deprecated[$interface]), E_USER_DEPRECATED);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($file) {
|
||||
|
@ -156,6 +156,39 @@ class DebugClassLoaderTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
$this->assertTrue(class_exists(__NAMESPACE__.'\Fixtures\ClassAlias', true));
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider provideDeprecatedSuper
|
||||
*/
|
||||
public function testDeprecatedSuper($class, $super, $type)
|
||||
{
|
||||
set_error_handler('var_dump', 0);
|
||||
$e = error_reporting(0);
|
||||
trigger_error('', E_USER_DEPRECATED);
|
||||
|
||||
class_exists('Test\\'.__NAMESPACE__.'\\'.$class, true);
|
||||
|
||||
error_reporting($e);
|
||||
restore_error_handler();
|
||||
|
||||
$lastError = error_get_last();
|
||||
unset($lastError['file'], $lastError['line']);
|
||||
|
||||
$xError = array(
|
||||
'type' => E_USER_DEPRECATED,
|
||||
'message' => 'The Test\Symfony\Component\Debug\Tests\\'.$class.' class '.$type.' Symfony\Component\Debug\Tests\Fixtures\\'.$super.' that is deprecated but this is a test deprecation notice.',
|
||||
);
|
||||
|
||||
$this->assertSame($xError, $lastError);
|
||||
}
|
||||
|
||||
public function provideDeprecatedSuper()
|
||||
{
|
||||
return array(
|
||||
array('DeprecatedInterfaceClass', 'DeprecatedInterface', 'implements'),
|
||||
array('DeprecatedParentClass', 'DeprecatedClass', 'extends'),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class ClassLoader
|
||||
@ -185,6 +218,12 @@ class ClassLoader
|
||||
return __DIR__.'/Fixtures/reallyNotPsr0.php';
|
||||
} elseif (__NAMESPACE__.'\Fixtures\NotPSR0bis' === $class) {
|
||||
return __DIR__.'/Fixtures/notPsr0Bis.php';
|
||||
} elseif (__NAMESPACE__.'\Fixtures\DeprecatedInterface' === $class) {
|
||||
return __DIR__.'/Fixtures/DeprecatedInterface.php';
|
||||
} elseif ('Test\\'.__NAMESPACE__.'\DeprecatedParentClass' === $class) {
|
||||
eval('namespace Test\\'.__NAMESPACE__.'; class DeprecatedParentClass extends \\'.__NAMESPACE__.'\Fixtures\DeprecatedClass {}');
|
||||
} elseif ('Test\\'.__NAMESPACE__.'\DeprecatedInterfaceClass' === $class) {
|
||||
eval('namespace Test\\'.__NAMESPACE__.'; class DeprecatedInterfaceClass implements \\'.__NAMESPACE__.'\Fixtures\DeprecatedInterface {}');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
namespace Symfony\Component\Debug\Tests\Fixtures;
|
||||
|
||||
/**
|
||||
* @deprecated but this is a test
|
||||
* deprecation notice.
|
||||
* @foobar
|
||||
*/
|
||||
class DeprecatedClass
|
||||
{
|
||||
}
|
@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
namespace Symfony\Component\Debug\Tests\Fixtures;
|
||||
|
||||
/**
|
||||
* @deprecated but this is a test
|
||||
* deprecation notice.
|
||||
* @foobar
|
||||
*/
|
||||
interface DeprecatedInterface
|
||||
{
|
||||
}
|
@ -29,7 +29,7 @@ trigger_error('Symfony\Component\Form\Extension\Csrf\CsrfProvider\CsrfProviderIn
|
||||
*
|
||||
* @author Bernhard Schussek <bschussek@gmail.com>
|
||||
*
|
||||
* @deprecated Deprecated since version 2.4, to be removed in Symfony 3.0. Use
|
||||
* @deprecated since version 2.4, to be removed in Symfony 3.0. Use
|
||||
* {@link \Symfony\Component\Security\Csrf\CsrfTokenManagerInterface}
|
||||
* instead.
|
||||
*/
|
||||
|
@ -21,7 +21,7 @@ namespace Symfony\Component\HttpKernel\HttpCache;
|
||||
*
|
||||
* @author Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* @deprecated Deprecated since version 2.6, to be removed in 3.0. Use ResponseCacheStrategyInterface instead
|
||||
* @deprecated since version 2.6, to be removed in 3.0. Use ResponseCacheStrategyInterface instead.
|
||||
*/
|
||||
interface EsiResponseCacheStrategyInterface extends ResponseCacheStrategyInterface
|
||||
{
|
||||
|
@ -18,7 +18,7 @@ use Psr\Log\LoggerInterface as PsrLogger;
|
||||
*
|
||||
* @author Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* @deprecated since 2.2, to be removed in 3.0. Type-hint \Psr\Log\LoggerInterface instead.
|
||||
* @deprecated since version 2.2, to be removed in 3.0. Type-hint \Psr\Log\LoggerInterface instead.
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
|
@ -20,7 +20,7 @@ use Symfony\Component\OptionsResolver\Exception\OptionDefinitionException;
|
||||
/**
|
||||
* @author Bernhard Schussek <bschussek@gmail.com>
|
||||
*
|
||||
* @deprecated Deprecated since Symfony 2.6, to be removed in Symfony 3.0.
|
||||
* @deprecated since version 2.6, to be removed in Symfony 3.0.
|
||||
* Use {@link OptionsResolver} instead.
|
||||
*/
|
||||
interface OptionsResolverInterface
|
||||
|
@ -18,7 +18,7 @@ use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface;
|
||||
* The SecurityContextInterface.
|
||||
*
|
||||
* @author Johannes M. Schmitt <schmittjoh@gmail.com>
|
||||
* @deprecated Deprecated since version 2.6, to be removed in 3.0.
|
||||
* @deprecated since version 2.6, to be removed in 3.0.
|
||||
*/
|
||||
interface SecurityContextInterface extends TokenStorageInterface, AuthorizationCheckerInterface
|
||||
{
|
||||
|
@ -19,7 +19,7 @@ class SecurityContextInterfaceTest extends \PHPUnit_Framework_TestCase
|
||||
/**
|
||||
* Test if the BC Layer is working as intended
|
||||
*
|
||||
* @deprecated Deprecated since version 2.6, to be removed in 3.0.
|
||||
* @deprecated since version 2.6, to be removed in 3.0.
|
||||
*/
|
||||
public function testConstantSync()
|
||||
{
|
||||
|
@ -17,7 +17,7 @@ namespace Symfony\Component\Templating;
|
||||
*
|
||||
* @author Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* @deprecated Deprecated in 2.4, to be removed in 3.0. Use Psr\Log\LoggerInterface instead.
|
||||
* @deprecated since version 2.4, to be removed in 3.0. Use Psr\Log\LoggerInterface instead.
|
||||
*/
|
||||
interface DebuggerInterface
|
||||
{
|
||||
|
@ -18,7 +18,7 @@ trigger_error('The Symfony\Component\Validator\ClassBasedInterface interface was
|
||||
*
|
||||
* @author Bernhard Schussek <bschussek@gmail.com>
|
||||
*
|
||||
* @deprecated Deprecated since version 2.5, to be removed in Symfony 3.0.
|
||||
* @deprecated since version 2.5, to be removed in Symfony 3.0.
|
||||
* Use {@link Mapping\ClassMetadataInterface} instead.
|
||||
*/
|
||||
interface ClassBasedInterface
|
||||
|
@ -85,7 +85,7 @@ trigger_error('The "Symfony\Component\Validator\ExecutionContextInterface" inter
|
||||
*
|
||||
* @api
|
||||
*
|
||||
* @deprecated Deprecated since version 2.5, to be removed in Symfony 3.0.
|
||||
* @deprecated since version 2.5, to be removed in Symfony 3.0.
|
||||
* Use {@link Context\ExecutionContextInterface} instead.
|
||||
*/
|
||||
interface ExecutionContextInterface
|
||||
|
@ -29,7 +29,7 @@ trigger_error('Symfony\Component\Validator\GlobalExecutionContextInterface was d
|
||||
*
|
||||
* @author Bernhard Schussek <bschussek@gmail.com>
|
||||
*
|
||||
* @deprecated Deprecated since version 2.5, to be removed in Symfony 3.0.
|
||||
* @deprecated since version 2.5, to be removed in Symfony 3.0.
|
||||
* Use {@link Context\ExecutionContextInterface} instead.
|
||||
*/
|
||||
interface GlobalExecutionContextInterface
|
||||
|
@ -18,7 +18,7 @@ trigger_error('The "Symfony\Component\Validator\MetadataFactoryInterface" interf
|
||||
*
|
||||
* @author Bernhard Schussek <bschussek@gmail.com>
|
||||
*
|
||||
* @deprecated Deprecated since version 2.5, to be removed in Symfony 3.0.
|
||||
* @deprecated since version 2.5, to be removed in Symfony 3.0.
|
||||
* Use {@link Mapping\Factory\MetadataFactoryInterface} instead.
|
||||
*/
|
||||
interface MetadataFactoryInterface
|
||||
|
@ -44,7 +44,7 @@ trigger_error('Symfony\Component\Validator\MetadataInterface was deprecated in v
|
||||
*
|
||||
* @author Bernhard Schussek <bschussek@gmail.com>
|
||||
*
|
||||
* @deprecated Deprecated since version 2.5, to be removed in Symfony 3.0.
|
||||
* @deprecated since version 2.5, to be removed in Symfony 3.0.
|
||||
* Use {@link Mapping\MetadataInterface} instead.
|
||||
*/
|
||||
interface MetadataInterface
|
||||
|
@ -18,7 +18,7 @@ trigger_error('Symfony\Component\Validator\PropertyMetadataContainerInterface is
|
||||
*
|
||||
* @author Bernhard Schussek <bschussek@gmail.com>
|
||||
*
|
||||
* @deprecated Deprecated since version 2.5, to be removed in Symfony 3.0.
|
||||
* @deprecated since version 2.5, to be removed in Symfony 3.0.
|
||||
* Use {@link Mapping\ClassMetadataInterface} instead.
|
||||
*/
|
||||
interface PropertyMetadataContainerInterface
|
||||
|
@ -26,7 +26,7 @@ trigger_error('Symfony\Component\Validator\PropertyMetadataInterface was depreca
|
||||
*
|
||||
* @see MetadataInterface
|
||||
*
|
||||
* @deprecated Deprecated since version 2.5, to be removed in Symfony 3.0.
|
||||
* @deprecated since version 2.5, to be removed in Symfony 3.0.
|
||||
* Use {@link Mapping\PropertyMetadataInterface} instead.
|
||||
*/
|
||||
interface PropertyMetadataInterface extends MetadataInterface
|
||||
|
@ -36,7 +36,7 @@ trigger_error('Symfony\Component\Validator\ValidationVisitorInterface was deprec
|
||||
*
|
||||
* @author Bernhard Schussek <bschussek@gmail.com>
|
||||
*
|
||||
* @deprecated Deprecated since version 2.5, to be removed in Symfony 3.0.
|
||||
* @deprecated since version 2.5, to be removed in Symfony 3.0.
|
||||
*/
|
||||
interface ValidationVisitorInterface
|
||||
{
|
||||
|
@ -20,7 +20,7 @@ trigger_error('ValidatorInterface was deprecated in version 2.5 and will be remo
|
||||
*
|
||||
* @api
|
||||
*
|
||||
* @deprecated Deprecated since version 2.5, to be removed in Symfony 3.0.
|
||||
* @deprecated since version 2.5, to be removed in Symfony 3.0.
|
||||
* Use {@link Validator\ValidatorInterface} instead.
|
||||
*/
|
||||
interface ValidatorInterface
|
||||
|
Reference in New Issue
Block a user