Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -12,6 +15,5 @@
"psr-4": {
"Plugin\\ExamplePlugin\\": "src"
}
},
"require": {}
}
}
18 changes: 12 additions & 6 deletions events.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
<?php

declare(strict_types=1);
//declare(strict_types=1);

use App\CallableEventDispatcherInterface;
use App\Event;
use App\Event\BuildRoutes;
use App\Event\BuildView;
use DI\Container;
use Plugin\ExamplePlugin\Controller\HelloWorld;
//use Plugin\ExamplePlugin\EventHandler\AllTheListeners;

return static function (CallableEventDispatcherInterface $dispatcher) {
return static function (\App\CallableEventDispatcherInterface $dispatcher) {
$dispatcher->addListener(
Event\BuildConsoleCommands::class,
function (Event\BuildConsoleCommands $event) use ($dispatcher) {
Expand All @@ -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);
};
16 changes: 15 additions & 1 deletion src/Controller/HelloWorld.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
}
2 changes: 1 addition & 1 deletion templates/hello_world.phtml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php $this->layout('minimal', ['title' => __('Hello World!'), 'page_class' => 'example-content']) ?>
<?php $this->layout('panel'); //$this->layout('minimal', ['title' => __('Hello World!'), 'page_class' => 'example-content']) ?>

<section id="main">
<div class="container">
Expand Down