Skip to content

Mess with custom command loading #323

Closed
@VoDmAl

Description

@VoDmAl

Great library. Thank you!

I faced with one issue. Custom commands loading is not very clear. To create my custom command i should put it in a my custom folder. It must be named xxxCommand.php it is ok.
Of course it must extends Longman\TelegramBot\Commands\Command class. It is ok.
But it also must be in Longman\TelegramBot\Commands\ namespace. It is bad.

$command_namespace = __NAMESPACE__ . '\\Commands\\' . $auth . 'Commands\\' . $this->ucfirstUnicode($command) . 'Command'; if (class_exists($command_namespace)) { return new $command_namespace($this, $this->update); }

You put one bit of information into three different places (folder structure, classes hierarchy and classes names). And they are not synchronized.

But you already have methods to check type of command like that:
public function isSystemCommand() { return ($this instanceof SystemCommand); }
So my proposal is to replace namespace check block code to function "class_parents" or "class_implements" check.

I could prepare this patch.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions