diff --git a/composer.json b/composer.json index 0fc7c9b..bc5e998 100644 --- a/composer.json +++ b/composer.json @@ -2,6 +2,9 @@ "name": "azuracast/example-plugin", "description": "An example AzuraCast plugin, demonstrating the capabilities and common use-cases of the plugin system.", "type": "azuracast-plugin", + "require": { + "php": ">=8.2" + }, "authors": [ { "name": "Buster Neece", @@ -12,6 +15,5 @@ "psr-4": { "Plugin\\ExamplePlugin\\": "src" } - }, - "require": {} + } } diff --git a/events.php b/events.php index 2380e03..21294c4 100644 --- a/events.php +++ b/events.php @@ -1,11 +1,16 @@ addListener( Event\BuildConsoleCommands::class, function (Event\BuildConsoleCommands $event) use ($dispatcher) { @@ -17,18 +22,19 @@ function (Event\BuildConsoleCommands $event) use ($dispatcher) { // Tell the view handler to look for templates in this directory too $dispatcher->addListener(Event\BuildView::class, function(Event\BuildView $event) { - $event->getView()->addFolder('example', __DIR__.'/templates'); + $event->getView()->addFolder('ExamplePlugin', __DIR__.'/templates'); }); // Add a new route handled exclusively by the plugin. $dispatcher->addListener(Event\BuildRoutes::class, function(Event\BuildRoutes $event) { $app = $event->getApp(); - $app->get('/example', \Plugin\ExamplePlugin\Controller\HelloWorld::class) - ->setName('example-plugin:index:index') + $app->get('/example', HelloWorld::class) + ->setName('example:index') ->add(\App\Middleware\EnableView::class); + }); // You can also add classes that implement the EventSubscriberInterface - $dispatcher->addSubscriber(new \Plugin\ExamplePlugin\EventHandler\AllTheListeners); + //$dispatcher->addSubscriber(new AllTheListeners); }; diff --git a/src/Controller/HelloWorld.php b/src/Controller/HelloWorld.php index 5528f79..6a94b07 100644 --- a/src/Controller/HelloWorld.php +++ b/src/Controller/HelloWorld.php @@ -5,15 +5,29 @@ namespace Plugin\ExamplePlugin\Controller; use App\Controller\SingleActionInterface; +use App\Exception\Http\InvalidRequestAttribute; +use App\View; +use DI\Container; use App\Http\Response; use App\Http\ServerRequest; use Psr\Http\Message\ResponseInterface; final class HelloWorld implements SingleActionInterface { + //use EnvironmentAwareTrait; + private Container $container; + private View $view; + + public function __construct(Container $container) + { + $this->container = $container; + $this->view = $container->get(View::class); + + } + public function __invoke(ServerRequest $request, Response $response, array $params): ResponseInterface { return $request->getView() - ->renderToResponse($response, 'example::hello_world'); + ->renderToResponse($response, 'ExamplePlugin::hello_world'); } } diff --git a/templates/hello_world.phtml b/templates/hello_world.phtml index 2124f9e..066f063 100644 --- a/templates/hello_world.phtml +++ b/templates/hello_world.phtml @@ -1,4 +1,4 @@ -layout('minimal', ['title' => __('Hello World!'), 'page_class' => 'example-content']) ?> +layout('panel'); //$this->layout('minimal', ['title' => __('Hello World!'), 'page_class' => 'example-content']) ?>