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

Skip to content

Commit a86d4e3

Browse files
committed
feature #13164 [Debug] track and report deprecated classes and interfaces (nicolas-grekas)
This PR was merged into the 2.7 branch. Discussion ---------- [Debug] track and report deprecated classes and interfaces | Q | A | ------------- | --- | Bug fix? | no | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | - | License | MIT | Doc PR | - Commits ------- a541faf [Debug] track and report deprecated classes and interfaces
2 parents 08a7ba9 + a541faf commit a86d4e3

20 files changed

+96
-16
lines changed

src/Symfony/Component/Debug/DebugClassLoader.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ class DebugClassLoader
3030
private $isFinder;
3131
private $wasFinder;
3232
private static $caseCheck;
33+
private static $deprecated = array();
3334

3435
/**
3536
* Constructor.
@@ -175,6 +176,22 @@ public function loadClass($class)
175176
if ($name !== $class && 0 === strcasecmp($name, $class)) {
176177
throw new \RuntimeException(sprintf('Case mismatch between loaded and declared class names: %s vs %s', $class, $name));
177178
}
179+
180+
if (preg_match('#\n \* @deprecated (.*?)\r?\n \*(?: @|/$)#s', $refl->getDocComment(), $notice)) {
181+
self::$deprecated[$name] = preg_replace('#\s*\r?\n \* +#', ' ', $notice[1]);
182+
} elseif (0 !== strpos($name, 'Symfony\\')) {
183+
$parent = $refl->getParentClass();
184+
185+
if ($parent && isset(self::$deprecated[$parent->name])) {
186+
trigger_error(sprintf('The %s class extends %s that is deprecated %s', $name, $parent->name, self::$deprecated[$parent->name]), E_USER_DEPRECATED);
187+
}
188+
189+
foreach ($refl->getInterfaceNames() as $interface) {
190+
if (isset(self::$deprecated[$interface]) && !($parent && $parent->implementsInterface($interface))) {
191+
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);
192+
}
193+
}
194+
}
178195
}
179196

180197
if ($file) {

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

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,39 @@ public function testClassAlias()
156156
{
157157
$this->assertTrue(class_exists(__NAMESPACE__.'\Fixtures\ClassAlias', true));
158158
}
159+
160+
/**
161+
* @dataProvider provideDeprecatedSuper
162+
*/
163+
public function testDeprecatedSuper($class, $super, $type)
164+
{
165+
set_error_handler('var_dump', 0);
166+
$e = error_reporting(0);
167+
trigger_error('', E_USER_DEPRECATED);
168+
169+
class_exists('Test\\'.__NAMESPACE__.'\\'.$class, true);
170+
171+
error_reporting($e);
172+
restore_error_handler();
173+
174+
$lastError = error_get_last();
175+
unset($lastError['file'], $lastError['line']);
176+
177+
$xError = array(
178+
'type' => E_USER_DEPRECATED,
179+
'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.',
180+
);
181+
182+
$this->assertSame($xError, $lastError);
183+
}
184+
185+
public function provideDeprecatedSuper()
186+
{
187+
return array(
188+
array('DeprecatedInterfaceClass', 'DeprecatedInterface', 'implements'),
189+
array('DeprecatedParentClass', 'DeprecatedClass', 'extends'),
190+
);
191+
}
159192
}
160193

161194
class ClassLoader
@@ -185,6 +218,12 @@ public function findFile($class)
185218
return __DIR__.'/Fixtures/reallyNotPsr0.php';
186219
} elseif (__NAMESPACE__.'\Fixtures\NotPSR0bis' === $class) {
187220
return __DIR__.'/Fixtures/notPsr0Bis.php';
221+
} elseif (__NAMESPACE__.'\Fixtures\DeprecatedInterface' === $class) {
222+
return __DIR__.'/Fixtures/DeprecatedInterface.php';
223+
} elseif ('Test\\'.__NAMESPACE__.'\DeprecatedParentClass' === $class) {
224+
eval('namespace Test\\'.__NAMESPACE__.'; class DeprecatedParentClass extends \\'.__NAMESPACE__.'\Fixtures\DeprecatedClass {}');
225+
} elseif ('Test\\'.__NAMESPACE__.'\DeprecatedInterfaceClass' === $class) {
226+
eval('namespace Test\\'.__NAMESPACE__.'; class DeprecatedInterfaceClass implements \\'.__NAMESPACE__.'\Fixtures\DeprecatedInterface {}');
188227
}
189228
}
190229
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
3+
namespace Symfony\Component\Debug\Tests\Fixtures;
4+
5+
/**
6+
* @deprecated but this is a test
7+
* deprecation notice.
8+
* @foobar
9+
*/
10+
class DeprecatedClass
11+
{
12+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
3+
namespace Symfony\Component\Debug\Tests\Fixtures;
4+
5+
/**
6+
* @deprecated but this is a test
7+
* deprecation notice.
8+
* @foobar
9+
*/
10+
interface DeprecatedInterface
11+
{
12+
}

src/Symfony/Component/Form/Extension/Csrf/CsrfProvider/CsrfProviderInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
*
3030
* @author Bernhard Schussek <[email protected]>
3131
*
32-
* @deprecated Deprecated since version 2.4, to be removed in Symfony 3.0. Use
32+
* @deprecated since version 2.4, to be removed in Symfony 3.0. Use
3333
* {@link \Symfony\Component\Security\Csrf\CsrfTokenManagerInterface}
3434
* instead.
3535
*/

src/Symfony/Component/HttpKernel/HttpCache/EsiResponseCacheStrategyInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
*
2222
* @author Fabien Potencier <[email protected]>
2323
*
24-
* @deprecated Deprecated since version 2.6, to be removed in 3.0. Use ResponseCacheStrategyInterface instead
24+
* @deprecated since version 2.6, to be removed in 3.0. Use ResponseCacheStrategyInterface instead.
2525
*/
2626
interface EsiResponseCacheStrategyInterface extends ResponseCacheStrategyInterface
2727
{

src/Symfony/Component/HttpKernel/Log/LoggerInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
*
1919
* @author Fabien Potencier <[email protected]>
2020
*
21-
* @deprecated since 2.2, to be removed in 3.0. Type-hint \Psr\Log\LoggerInterface instead.
21+
* @deprecated since version 2.2, to be removed in 3.0. Type-hint \Psr\Log\LoggerInterface instead.
2222
*
2323
* @api
2424
*/

src/Symfony/Component/OptionsResolver/OptionsResolverInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
/**
2121
* @author Bernhard Schussek <[email protected]>
2222
*
23-
* @deprecated Deprecated since Symfony 2.6, to be removed in Symfony 3.0.
23+
* @deprecated since version 2.6, to be removed in Symfony 3.0.
2424
* Use {@link OptionsResolver} instead.
2525
*/
2626
interface OptionsResolverInterface

src/Symfony/Component/Security/Core/SecurityContextInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
* The SecurityContextInterface.
1919
*
2020
* @author Johannes M. Schmitt <[email protected]>
21-
* @deprecated Deprecated since version 2.6, to be removed in 3.0.
21+
* @deprecated since version 2.6, to be removed in 3.0.
2222
*/
2323
interface SecurityContextInterface extends TokenStorageInterface, AuthorizationCheckerInterface
2424
{

src/Symfony/Component/Security/Tests/Core/SecurityContextInterfaceTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class SecurityContextInterfaceTest extends \PHPUnit_Framework_TestCase
1919
/**
2020
* Test if the BC Layer is working as intended
2121
*
22-
* @deprecated Deprecated since version 2.6, to be removed in 3.0.
22+
* @deprecated since version 2.6, to be removed in 3.0.
2323
*/
2424
public function testConstantSync()
2525
{

src/Symfony/Component/Templating/DebuggerInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
*
1818
* @author Fabien Potencier <[email protected]>
1919
*
20-
* @deprecated Deprecated in 2.4, to be removed in 3.0. Use Psr\Log\LoggerInterface instead.
20+
* @deprecated since version 2.4, to be removed in 3.0. Use Psr\Log\LoggerInterface instead.
2121
*/
2222
interface DebuggerInterface
2323
{

src/Symfony/Component/Validator/ClassBasedInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
*
1919
* @author Bernhard Schussek <[email protected]>
2020
*
21-
* @deprecated Deprecated since version 2.5, to be removed in Symfony 3.0.
21+
* @deprecated since version 2.5, to be removed in Symfony 3.0.
2222
* Use {@link Mapping\ClassMetadataInterface} instead.
2323
*/
2424
interface ClassBasedInterface

src/Symfony/Component/Validator/ExecutionContextInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@
8585
*
8686
* @api
8787
*
88-
* @deprecated Deprecated since version 2.5, to be removed in Symfony 3.0.
88+
* @deprecated since version 2.5, to be removed in Symfony 3.0.
8989
* Use {@link Context\ExecutionContextInterface} instead.
9090
*/
9191
interface ExecutionContextInterface

src/Symfony/Component/Validator/GlobalExecutionContextInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
*
3030
* @author Bernhard Schussek <[email protected]>
3131
*
32-
* @deprecated Deprecated since version 2.5, to be removed in Symfony 3.0.
32+
* @deprecated since version 2.5, to be removed in Symfony 3.0.
3333
* Use {@link Context\ExecutionContextInterface} instead.
3434
*/
3535
interface GlobalExecutionContextInterface

src/Symfony/Component/Validator/MetadataFactoryInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
*
1919
* @author Bernhard Schussek <[email protected]>
2020
*
21-
* @deprecated Deprecated since version 2.5, to be removed in Symfony 3.0.
21+
* @deprecated since version 2.5, to be removed in Symfony 3.0.
2222
* Use {@link Mapping\Factory\MetadataFactoryInterface} instead.
2323
*/
2424
interface MetadataFactoryInterface

src/Symfony/Component/Validator/MetadataInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
*
4545
* @author Bernhard Schussek <[email protected]>
4646
*
47-
* @deprecated Deprecated since version 2.5, to be removed in Symfony 3.0.
47+
* @deprecated since version 2.5, to be removed in Symfony 3.0.
4848
* Use {@link Mapping\MetadataInterface} instead.
4949
*/
5050
interface MetadataInterface

src/Symfony/Component/Validator/PropertyMetadataContainerInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
*
1919
* @author Bernhard Schussek <[email protected]>
2020
*
21-
* @deprecated Deprecated since version 2.5, to be removed in Symfony 3.0.
21+
* @deprecated since version 2.5, to be removed in Symfony 3.0.
2222
* Use {@link Mapping\ClassMetadataInterface} instead.
2323
*/
2424
interface PropertyMetadataContainerInterface

src/Symfony/Component/Validator/PropertyMetadataInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
*
2727
* @see MetadataInterface
2828
*
29-
* @deprecated Deprecated since version 2.5, to be removed in Symfony 3.0.
29+
* @deprecated since version 2.5, to be removed in Symfony 3.0.
3030
* Use {@link Mapping\PropertyMetadataInterface} instead.
3131
*/
3232
interface PropertyMetadataInterface extends MetadataInterface

src/Symfony/Component/Validator/ValidationVisitorInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
*
3737
* @author Bernhard Schussek <[email protected]>
3838
*
39-
* @deprecated Deprecated since version 2.5, to be removed in Symfony 3.0.
39+
* @deprecated since version 2.5, to be removed in Symfony 3.0.
4040
*/
4141
interface ValidationVisitorInterface
4242
{

src/Symfony/Component/Validator/ValidatorInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
*
2121
* @api
2222
*
23-
* @deprecated Deprecated since version 2.5, to be removed in Symfony 3.0.
23+
* @deprecated since version 2.5, to be removed in Symfony 3.0.
2424
* Use {@link Validator\ValidatorInterface} instead.
2525
*/
2626
interface ValidatorInterface

0 commit comments

Comments
 (0)