Skip to content
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

Eliminate HelperSet usage in console-related code #743

Closed
Majkl578 opened this issue Jul 10, 2018 · 2 comments
Closed

Eliminate HelperSet usage in console-related code #743

Majkl578 opened this issue Jul 10, 2018 · 2 comments
Labels
Milestone

Comments

@Majkl578
Copy link
Contributor

Feature Request

Q A
RFC yes
BC Break yes

Summary

Depending on whether symfony/symfony#27647 gets merged into Symfony 4.2 or not, HelperSet may become deprecated.

This would affect all Migrations console commands as the HelperSet is used quite extensively:

  • public static function run(HelperSet $helperSet, array $commands = []) : void
  • private function hasConfigurationHelper() : bool
    {
    /** @var HelperSet|null $helperSet */
    $helperSet = $this->getHelperSet();
    if ($helperSet === null) {
    return false;
    }
    if (! $helperSet->has('configuration')) {
    return false;
    }
    return $helperSet->get('configuration') instanceof ConfigurationHelperInterface;
    }
    private function getConnection(InputInterface $input) : Connection
    {
    if ($this->connection === null) {
    $this->connection = (new ConnectionLoader($this->configuration))
    ->getConnection($input, $this->getHelperSet());
    }
    return $this->connection;
    }
  • /** @var HelperSet */
    private $helperSet;
    public function __construct(?HelperSet $helperSet = null, string $helperName)
    {
    $this->helperName = $helperName;
    if ($helperSet === null) {
    $helperSet = new HelperSet();
    }
    $this->helperSet = $helperSet;
    }
    /**
    * Read the input and return a Configuration, returns null if the config
    * is not supported.
    */
    public function chosen() : ?Connection
    {
    if ($this->helperSet->has($this->helperName)) {
    $connectionHelper = $this->helperSet->get($this->helperName);
    if ($connectionHelper instanceof ConnectionHelper) {
    return $connectionHelper->getConnection();
    }
    }
    return null;
    }
  • $helperSet = null;
    if ($configurationFile !== null) {
    if (! is_readable($configurationFile)) {
    trigger_error('Configuration file [' . $configurationFile . '] does not have read permission.', E_USER_ERROR);
    exit(1);
    }
    $helperSet = require $configurationFile;
    if (! $helperSet instanceof HelperSet) {
    foreach ($GLOBALS as $helperSetCandidate) {
    if (! $helperSetCandidate instanceof HelperSet) {
    continue;
    }
    $helperSet = $helperSetCandidate;
    break;
    }
    }
    }
    $helperSet = $helperSet ?? new HelperSet();
    $helperSet->set(new QuestionHelper(), 'question');
    $commands = [];
    ConsoleRunner::run($helperSet, $commands);

Even if the referenced deprecation doesn't make it into 4.2/4.x, it'd still be a good idea to do this change before 2.0 GA.

@goetas
Copy link
Member

goetas commented Dec 29, 2019

#898 should address this

@goetas
Copy link
Member

goetas commented Jan 14, 2020

done in #898

@goetas goetas closed this as completed Jan 14, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants