8000 [Console] improve deprecation warning triggers by xabbuh · Pull Request #12796 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[Console] improve deprecation warning triggers #12796

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

Merged
merged 1 commit into from
Dec 4, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
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
6 changes: 3 additions & 3 deletions src/Symfony/Component/Console/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -950,9 +950,9 @@ protected function getDefaultHelperSet()
{
return new HelperSet(array(
new FormatterHelper(),
new DialogHelper(),
new ProgressHelper(),
new TableHelper(),
new DialogHelper(false),
new ProgressHelper(false),
new TableHelper(false),
new DebugFormatterHelper(),
new ProcessHelper(),
new QuestionHelper(),
Expand Down
9 changes: 7 additions & 2 deletions src/Symfony/Component/Console/Helper/DialogHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@

namespace Symfony\Component\Console\Helper;

trigger_error('\Symfony\Component\Console\Helper\DialogHelper is deprecated since version 2.5 and will be removed in 3.0. Use QuestionHelper instead.', E_USER_DEPRECATED);

use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Formatter\OutputFormatterStyle;

Expand All @@ -30,6 +28,13 @@ class DialogHelper extends InputAwareHelper
private static $shell;
private static $stty;

public function __construct($triggerDeprecationError = true)
{
if ($triggerDeprecationError) {
trigger_error('"Symfony\Component\Console\Helper\DialogHelper" is deprecated since version 2.5 and will be removed in 3.0. Use "Symfony\Component\Console\Helper\QuestionHelper" instead.', E_USER_DEPRECATED);
}
}

/**
* Asks the user to select a value.
*
Expand Down
8 changes: 8 additions & 0 deletions src/Symfony/Component/Console/Helper/HelperSet.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,14 @@ public function get($name)
throw new \InvalidArgumentException(sprintf('The helper "%s" is not defined.', $name));
}

if ('dialog' === $name && $this->helpers[$name] instanceof DialogHelper) {
Copy link
Member Author

Choose a reason for hiding this comment

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

We could also remove the 'dialog' === $name check if you agree that checking for the object type is sufficient. I just decided to stick with the keys used by the default helper set (the same applies to the two checks below).

Choose a reason for hiding this comment

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

this looks very weird, couldn't we trigger this when the instance is created, not in this class?

Copy link
Member Author

Choose a reason for hiding this comment

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

No, the real issue is that all three helper instances are created when the default helper set is built in the application (see https://github.com/symfony/symfony/blob/2.7/src/Symfony/Component/Console/Application.php#L949-960). Triggering there results in warnings for every user using the Application whether or not they are using the deprecated helpers (this is why #12771 and #12791 have been opened).

Choose a reason for hiding this comment

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

i would love using HelperSet as Factory, consider

return new HelperSet(array(
        new FormatterHelper(),
        function() { trigger_error('...'); new DialogHelper(); },
        new ProgressHelper(),
        new TableHelper(),
        new DebugFormatterHelper(),
        new ProcessHelper(),
        new QuestionHelper(),
    ));

Copy link
Member Author

Choose a reason for hiding this comment

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

We could do that. But then we make this "feature" available to everyone even if it isn't documented. Let's see what the core team thinks about this.

Copy link
Member

Choose a reason for hiding this comment

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

The current way seems pragmatic to me (keep in mind that this is temporary code) 👍

Copy link
Member

Choose a reason for hiding this comment

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

I agree with @fabpot here. The suggestion of @timglabisch requires to add a new feature to be able to trigger the deprecation notices, and I'm not sure we want such feature in the HelperSet (and adding a deprecated feature to be able to trigger deprecation notices is even worse)

trigger_error('"Symfony\Component\Console\Helper\DialogHelper" is deprecated since version 2.5 and will be removed in 3.0. Use "Symfony\Component\Console\Helper\QuestionHelper" instead.', E_USER_DEPRECATED);
} elseif ('progress' === $name && $this->helpers[$name] instanceof ProgressHelper) {
trigger_error('"Symfony\Component\Console\Helper\ProgressHelper" is deprecated since version 2.5 and will be removed in 3.0. Use "Symfony\Component\Console\Helper\ProgressBar" instead.', E_USER_DEPRECATED);
} elseif ('table' === $name && $this->helpers[$name] instanceof TableHelper) {
trigger_error('"Symfony\Component\Console\Helper\TableHelper" is deprecated since version 2.5 and will be removed in 3.0. Use "Symfony\Component\Console\Helper\Table" instead.', E_USER_DEPRECATED);
}

return $this->helpers[$name];
}

Expand Down
9 changes: 7 additions & 2 deletions src/Symfony/Component/Console/Helper/ProgressHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@
use Symfony\Component\Console\Output\NullOutput;
use Symfony\Component\Console\Output\OutputInterface;

trigger_error('The "ProgressHelper" class is deprecated since version 2.5 and will be removed in 3.0. Use "ProgressBar" class instead.', E_USER_DEPRECATED);

/**
* The Progress class provides helpers to display progress output.
*
Expand Down Expand Up @@ -119,6 +117,13 @@ class ProgressHelper extends Helper
array(604800, 'days', 86400),
);

public function __construct($triggerDeprecationError = true)
{
if ($triggerDeprecationError) {
trigger_error('"Symfony\Component\Console\Helper\ProgressHelper" is deprecated since version 2.5 and will be removed in 3.0. Use "Symfony\Component\Console\Helper\ProgressBar" instead.', E_USER_DEPRECATED);
}
}

/**
* Sets the progress bar width.
*
Expand Down
6 changes: 4 additions & 2 deletions src/Symfony/Component/Console/Helper/TableHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,11 @@ class TableHelper extends Helper
*/
private $table;

public function __construct()
public function __construct($triggerDeprecationError = true)
{
trigger_error('The TableHelper class was deprecated in version 2.5 and will be removed in 3.0. Use Symfony\Component\Console\Helper\Table instead.', E_USER_DEPRECATED);
if ($triggerDeprecationError) {
trigger_error('"Symfony\Component\Console\Helper\TableHelper" is deprecated since version 2.5 and will be removed in 3.0. Use "Symfony\Component\Console\Helper\Table" instead.', E_USER_DEPRECATED);
}

$this->table = new Table(new NullOutput());
}
Expand Down
0