how i can pass a variable to an class #688
-
maybe sound ridiculous i don't know this and maybe this is not place for asking this , but can anyone answer me please ? for example i want to directly pass the $example variable to the __invoke method of the StartCommand class which is called like this : $bot->onCommand('start', StartCommand::class); . how to do this ? |
Beta Was this translation helpful? Give feedback.
Answered by
Lukasss93
Apr 8, 2024
Replies: 1 comment
-
Just do this: <?php
namespace App;
use SergiX44\Nutgram\Nutgram;
require_once '../vendor/autoload.php';
$bot = new Nutgram('YOUR-TOKEN');
$bot->onCommand('start', new StartCommand('my custom data'));
$bot->run(); <?php
namespace App;
use SergiX44\Nutgram\Nutgram;
class StartCommand
{
public function __construct(protected string $data = '')
{
}
public function __invoke(Nutgram $bot): void
{
$bot->sendMessage('Hello! My custom data is: ' . $this->data);
}
} |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
flakka2022
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Just do this: