Skip to content

Pass additional arguments to a Command #158

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
BoShurik opened this issue Apr 22, 2016 · 4 comments
Closed

Pass additional arguments to a Command #158

BoShurik opened this issue Apr 22, 2016 · 4 comments

Comments

@BoShurik
Copy link

Hello!

I am planing to use this package as a part of Symfony project. Is it possible to inject commands as an objects (e.g. symfony services), but not as a path to a dir with command classes?

@MBoretto
Copy link
Collaborator

Hello,
I don't have experience with Symfony, maybe you can trigger your service calling it inside a command.
Let me know is works or if you find another soultion

@BoShurik
Copy link
Author

BoShurik commented Apr 25, 2016

Unfortunately, to call service inside a command I need to pass a service container to it :)

Solution, IMO, is to create CommandInterface, something like this:

interface CommandInterface
{
    /**
     * Command name
     *
     * @return string
     */
    public function getName();

    /**
     * Execute command
     *
     * @param Telegram $telegram
     * @param Update $update
     *
     * @return Entities\ServerResponse
     */
    public function execute(Telegram $telegram, Update $update = null);

    /**
     * If this is a system command
     *
     * @return bool
     */
    public function isSystemCommand();

    /**
     * If this is an admin command
     *
     * @return bool
     */
    public function isAdminCommand();

    /**
     * If this is a user command
     *
     * @return bool
     */
    public function isUserCommand();
}

and a method addCommand(CommandInterface $command) for Telegram object
but it will be a BC breake

@MBoretto
Copy link
Collaborator

MBoretto commented May 1, 2016

#106
Did you seen this issue? we would like to separate the commands logic from the telegram one.
Maybe in this refactoring we can implement this feature, let me know

@BoShurik
Copy link
Author

BoShurik commented May 1, 2016

Yea, it may be helpful. Thank you

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

No branches or pull requests

3 participants