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

Добавил возможность установить лоадер команд symfony #30

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

olegpro
Copy link
Contributor

@olegpro olegpro commented Mar 27, 2018

В версии 3.4 консоли появилась возможность устанавливать лоадер команд https://symfony.com/blog/new-in-symfony-3-4-lazy-commands

Я добавил эту возможность в джедая.

Пример:

в /.jedi.php:

<?php

use Symfony\Component\Console\CommandLoader\ContainerCommandLoader;

return [
    'web-dir' => __DIR__ . DIRECTORY_SEPARATOR . 'web',
    'env-dir' => 'environments',
    'useModules' => false,
    'commandLoader' => function () {
        return new ContainerCommandLoader(
            $container, // любой DI-контейнер, реализующий PSR-11
            [
                'app:some-command' => AppSomeCommand::class,
            ]
        );
    },
    'commands' => [
    ],
];

AppSomeCommand.php:

<?php

class AppSomeCommand extends BitrixCommand
{

    private $eventManager;
    
    private $someService;
    
    public function __construct(EventManager $eventManager, SomeService $someService)
    {
        parent::__construct();

        $this->eventManager = $eventManager;

        $this->someService = $someService;
    }

}

Это даёт нам ленивую загрузку команд и прокидывание зависимостей через конструктор у команд консоли

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

1 participant