Hi Flarumers,
I try to create an extension listening on a new route but I can not make it run. I've read the guides and some code on GitHub but I always face the same issue.
I've created this in the workbench subdir:
---- org-project/
---- ---- src/
---- ---- ---- Api/
---- ---- ---- ---- Controller/
---- ---- ---- ---- ---- ChoosePostController.php
---- ---- ---- Command/
---- ---- ---- ---- DoNothing.php
---- ---- ---- ---- DoNothingHandler.php
---- ---- ---- Listener/
---- ---- ---- ---- GetSelectedPost.php
---- ---- ---- bootstrap.php
---- ---- ---- composer.json
And that's files detail:
bootstrap.php
use Org\Project\Listener;
use Illuminate\Contracts\Events\Dispatcher;
return function (Dispatcher $events) {
$events->subscribe(Listener\GetSelectedPost::class);
};
GetSelectedPost.php
namespace Org\Project\Listener;
use Org\Project\Api\Controller\SelectPostController;
use Flarum\Event\ConfigureForumRoutes;
use Illuminate\Events\Dispatcher;
class GetSelectedPost
{
public function subscribe(Dispatcher $events)
{
$events->listen(ConfigureForumRoutes::class, [$this, 'ConfigureForumRoutes']);
}
public function ConfigureForumRoutes(ConfigureForumRoutes $event)
{
$event->get('/new-route', 'org.project.get', ChoosePostController::class);
}
}
ChoosePostController.php
namespace Org\Project\Api\Controller;
use Org\Project\Command\DoNothing;
use Flarum\Api\Controller\AbstractResourceController;
use Illuminate\Contracts\Bus\Dispatcher;
use Psr\Http\Message\ServerRequestInterface;
use Tobscure\JsonApi\Document;
class ChoosePostControllerextends AbstractResourceController
{
protected $bus;
public function __construct(Dispatcher $bus)
{
$this->bus = $bus;
}
protected function data(ServerRequestInterface $request, Document $document)
{
return $this->bus->dispatch(
new DoNothing()
);
}
}
DoNothing.php
namespace Org\Project\Command;
use Flarum\Core\User;
class DoNothing
{
public function __construct()
{
}
}
DoNothingHandler.php
namespace Org\Project\Command;
use Carbon\Carbon;
use Flarum\Core\Access\AssertPermissionTrait;
use Flarum\Core\Support\DispatchEventsTrait;
use Flarum\Foundation\Application;
use Illuminate\Events\Dispatcher;
use Illuminate\Support\Str;
class DoNothingHandler
{
use DispatchEventsTrait;
use AssertPermissionTrait;
public function __construct()
{
;
}
public function handle()
{
return true;
}
}
Just after I ran a composer update and the result was fine with a new "shortcut" created in the extension directory.
When I navigate into the "Administration Panel" I see the extension, I can Active and deactivate it, and when it's activated the route is understood by Flarum.
BUT I can not have any clean result. I've tested a lot of thing and NEVER had something good !!!
I always have a Laravel message ("Woops! There was an error") with a catched Exception and that are details:
ReflectionException (-1)
Class does not exist
in /home/flarum/vendor/illuminate/container/Container.php on line #741
Have searched on Google but nothing was helpful and above all in don't find exactly this message; on the answers I found there was always a className in the Exception message (like "Class Fool does not exist").
I there something I did wrong, is there a config to set in Composer, is there something else ?
Thank you.