I scaffolded a plugin with devtools. The plugin’s main php file contains a line to autoload vendor classes, but I’m unsure how to call these classes in my plugin, resulting in a Class not found
error.
I’m trying to use the Mollie API client like this:
<?php
namespace Grav\Plugin;
use Composer\Autoload\ClassLoader;
use Grav\Common\Plugin;
use Mollie\Api\MollieApiClient;
class MolliePlugin extends Plugin
{
public static function getSubscribedEvents()
{
return [
['autoload', 100000],
'onPluginsInitialized' => ['onPluginsInitialized', 0]
];
}
public function autoload(): ClassLoader
{
return require __DIR__ . '/vendor/autoload.php';
}
public function onPluginsInitialized()
{
if ($this->isAdmin()) {
return;
}
$this->enable([
'onFormProcessed' => ['onFormProcessed', 0]
]);
}
public function onFormProcessed($event)
{
$form = $event['form'];
$action = $event['action'];
switch ($action) {
case 'mollie':
$mollie = new MollieApiClient();
// And so on
}
}
}
Class MollieApiClient
cannot be found.