8000 [Debug] Trigger a deprecation when using an internal class/trait/interface by GuilhemN · Pull Request #23807 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[Debug] Trigger a deprecation when using an internal class/trait/interface #23807

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fixes
  • Loading branch information
GuilhemN committed Aug 6, 2017
commit bfda8b5d63a58d45755925a99da03f84ac0d4f97
2 changes: 1 addition & 1 deletion src/Symfony/Bridge/Doctrine/Form/ChoiceList/IdReader.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
*
* @author Bernhard Schussek <bschussek@gmail.com>
*
* @internal This class is meant for internal use only.
* @internal
*/
class IdReader
{
Expand Down
26 changes: 5 additions & 21 deletions src/Symfony/Component/Debug/DebugClassLoader.php
foreach (call_user_func(function () use ($name, $parent) {
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,8 @@ public function loadClass($class)

$parent = get_parent_class($class);
$doc = $refl->getDocComment();
if (preg_match('#\n \* @internal(?: .+?)?\r?\n \*(?: @|/$)#s', $doc, $notice)) {
self::$internal[$name] = true;
if (preg_match('#\n \* @internal(?:( .+?)\.?)?\r?\n \*(?: @|/$)#s', $doc, $notice)) {
self::$internal[$name] = isset($notice[1]) ? preg_replace('#\s*\r?\n \* +#', ' ', $notice[1]) : '';
}

// Not an interface nor a trait
Expand Down Expand Up @@ -228,25 +228,9 @@ public function loadClass($class)
}
}

if (isset(self::$internal[$parent])) {
yield 'class' => $parent;
}

foreach (class_implements($name, false) as $interface) {
if (isset(self::$internal[$interface])) {
yield 'interface' => $interface;
}
}

foreach (class_uses($name, false) as $use) {
if (isset(self::$internal[$use])) {
yield 'trait' => $use;
}
}
}) as $type => $internalUse) {
if (strncmp($ns, $internalUse, $len)) {
@trigger_error(sprintf('The "%s" %s is considered internal. It may change without further notice. You should not use it from "%s".', $internalUse, $type, $name), E_USER_DEPRECATED);
foreach (array_merge(array($parent), class_implements($name, false), class_uses($name, false)) as $use) {
if (isset(self::$internal[$use]) && strncmp($ns, $use, $len)) {
@trigger_error(sprintf('The "%s" %s is considered internal%s. It may change without further notice. You should not use it from "%s".', $use, class_exists($use, false) ? 'class' : (interface_exists($use, false) ? 'interface' : 'trait'), self::$internal[$use], $name), E_USER_DEPRECATED);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/Debug/Tests/DebugClassLoaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ class_exists('Test\\'.__NAMESPACE__.'\\ExtendsInternals', true);
restore_error_handler();

$this->assertSame($deprecations, array(
'The "Symfony\Component\Debug\Tests\Fixtures\InternalClass" class is considered internal. It may change without further notice. You should not use it from "Test\Symfony\Component\Debug\Tests\ExtendsInternals".',
'The "Symfony\Component\Debug\Tests\Fixtures\InternalClass" class is considered internal since version 3.4. It may change without further notice. You should not use it from "Test\Symfony\Component\Debug\Tests\ExtendsInternals".',
'The "Symfony\Component\Debug\Tests\Fixtures\InternalInterface" interface is considered internal. It may change without further notice. You should not use it from "Test\Symfony\Component\Debug\Tests\ExtendsInternals".',
'The "Symfony\Component\Debug\Tests\Fixtures\InternalTrait" trait is considered internal. It may change without further notice. You should not use it from "Test\Symfony\Component\Debug\Tests\ExtendsInternals".',
));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace Symfony\Component\Debug\Tests\Fixtures;

/**
* @internal this class is internal.
* @internal since version 3.4.
*/
class InternalClass
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace Symfony\Component\Debug\Tests\Fixtures;

/**
* @internal this interface is internal.
* @internal
*/
interface InternalInterface
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace Symfony\Component\Debug\Tests\Fixtures;

/**
* @internal this trait is internal.
* @internal
*/
trait InternalTrait
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace Symfony\Component\Debug\Tests\Fixtures;

/**
* @internal this trait is internal but should not trigger a deprecation as it's used in the same vendor.
* @internal
*/
trait InternalTrait2
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
/**
* @author Alexandre GESLIN <alexandre@gesl.in>
*
* @internal This class should be removed in Symfony 4.0.
* @internal and will be removed in Symfony 4.0.
*/
class ParserCacheAdapter implements CacheItemPoolInterface
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ public function getValuesForChoices(array $choices)
* corresponding values
* @param array $structuredValues The values indexed by the original keys
*
* @internal Must not be used by user-land code
* @internal
*/
protected function flatten(array $choices, $value, &$choicesByValues, &$keysByValues, &$structuredValues)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class CachingFactoryDecorator implements ChoiceListFactoryInterface
*
* @return string The SHA-256 hash
*
* @internal Should not be used by user-land code.
* @internal
*/
public static function generateHash($value, $namespace = '')
{
Expand All @@ -71,7 +71,7 @@ public static function generateHash($value, $namespace = '')
* @param array $array The array to flatten
* @param array $output The flattened output
*
* @internal Should not be used by user-land code
* @internal
*/
private static function flatten(array $array, &$output)
{
Expand Down
3 changes: 1 addition & 2 deletions src/Symfony/Component/Validator/Context/ExecutionContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@
*
* @see ExecutionContextInterface
*
* @internal You should not instantiate or use this class. Code against
* {@link ExecutionContextInterface} instead.
* @internal since version 3.5. Code against ExecutionContextInterface instead.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2.5?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops, indeed

*/
class ExecutionContext implements ExecutionContextInterface
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@
*
* @author Bernhard Schussek <bschussek@gmail.com>
*
* @internal You should not instantiate or use this class. Code against
* {@link ExecutionContextFactoryInterface} instead.
* @internal version 2.5. Code against ExecutionContextFactoryInterface instead.
*/
class ExecutionContextFactory implements ExecutionContextFactoryInterface
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@
*
* @author Bernhard Schussek <bschussek@gmail.com>
*
* @internal You should not instantiate or use this class. Code against
* {@link ConstraintViolationBuilderInterface} instead.
* @internal since version 2.5. Code against ConstraintViolationBuilderInterface instead.
*/
class ConstraintViolationBuilder implements ConstraintViolationBuilderInterface
{
Expand Down
0