Skip to content
● Meet Grav Guard: keep every Grav site you run secure and up to date, all from one place. Free for up to 3 sites. Read more →

Calling plugin from CLI

Started by Muut Archive 10 years ago · 1 replies · 577 views
10 years ago

I have a CLI-extension used in a plugin, but need to call a method in the plugin's main .php-file to avoid recreating a method in the CLI. I declared the namespace of the plugin, use Grav\Plugin\TwigFeedsPlugin;, and call it as such:

PHP
$call = new TwigFeedsPlugin;
$call = $call->call();
$this->output->writeln($call);

But this returns an error:

PHP
PHP Warning:  Missing argument 1 for Grav\Common\Plugin::__construct(), called in C:\Caddy\grav\user\plugins  wigfeeds\cli\BuildTwigFeedsCacheCommand.ph p on line 37 and defined in C:\Caddy\grav\system\src\Grav\Common\Plugin.php on line 70
PHP Fatal error:  Uncaught TypeError: Argument 2 passed to Grav\Common\Plugin::__construct() must be an instance of Grav\Common\Grav, none given, called in C:\Caddy\grav\user\plugins  wigfeeds\cli\BuildTwigFeedsCacheCommand.ph p on line 37 and defined in C:\Caddy\grav\system\src\Grav\Common\Plugin.php:70

How can I call a method from the plugin's class from a CLI-file? It would reduce quite a lot of overhead as they share some methods.

10 years ago

Frankly the best way is to create a class that both the plugin and the CLI command share. Then just include it from both.

Suggested topics

Topic Participants Replies Views Activity
Archive · by Muut Archive, 10 years ago
1 673 1 week ago
Archive · by Deleted User, 9 years ago
0 3043 9 years ago
Archive · by Muut Archive, 9 years ago
2 1983 9 years ago
Archive · by Muut Archive, 9 years ago
2 5336 9 years ago
Archive · by Muut Archive, 9 years ago
1 4134 9 years ago