Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Event Dispatcher * Event Disptacher * Event Dispatcher * Event Dispatcher
- Loading branch information
Showing
18 changed files
with
2,079 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
vendor |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# Redirect request to www folder | ||
<IfModule mod_rewrite.c> | ||
RewriteEngine On | ||
RewriteRule ^(.*)$ www/$1 [ns,L,QSA] | ||
</IfModule> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# Event Dispatcher + Event Dispatcher Extra | ||
|
||
This is example of symfony/event-dispatcher for Nette Framework. | ||
|
||
## Installation | ||
|
||
``` | ||
git pull git@github.com:contributte/playground.git | ||
cd event-dispatcher | ||
composer install | ||
``` | ||
|
||
## See | ||
|
||
- app/Presenters/HomepagePresenter - dispatching events | ||
- app/Events/ExampleSubscriber - subscribing events | ||
- app/Events/ExampleEvent - creating events |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?php declare(strict_types = 1); | ||
|
||
namespace App\Events; | ||
|
||
use Symfony\Component\EventDispatcher\Event; | ||
|
||
class ExampleEvent extends Event | ||
{ | ||
|
||
public const NAME = 'app.events.exampleEvent'; | ||
|
||
/** @var string */ | ||
private $example; | ||
|
||
public function __construct(string $example) | ||
{ | ||
$this->example = $example; | ||
} | ||
|
||
public function getExample(): string | ||
{ | ||
return $this->example; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
<?php declare(strict_types = 1); | ||
|
||
namespace App\Events; | ||
|
||
use Contributte\Events\Extra\Event\Application\ApplicationEvents; | ||
use Contributte\Events\Extra\Event\Application\PresenterEvent; | ||
use Contributte\Events\Extra\Event\Application\PresenterShutdownEvent; | ||
use Contributte\Events\Extra\Event\Application\PresenterStartupEvent; | ||
use Contributte\Events\Extra\Event\Application\RequestEvent; | ||
use Contributte\Events\Extra\Event\Application\ResponseEvent; | ||
use Symfony\Component\EventDispatcher\EventSubscriberInterface; | ||
|
||
class ExampleSubscriber implements EventSubscriberInterface | ||
{ | ||
|
||
public static function getSubscribedEvents(): array | ||
{ | ||
return [ | ||
ExampleEvent::NAME => 'example', | ||
ApplicationEvents::ON_PRESENTER => 'presenter', | ||
ApplicationEvents::ON_PRESENTER_STARTUP => 'presenterStartup', | ||
ApplicationEvents::ON_PRESENTER_SHUTDOWN => 'presenterShutdown', | ||
ApplicationEvents::ON_REQUEST => 'request', | ||
ApplicationEvents::ON_RESPONSE => 'response', | ||
]; | ||
} | ||
|
||
public function example(ExampleEvent $event): void | ||
{ | ||
bdump($event->getExample(), 'Example'); | ||
} | ||
|
||
public function presenter(PresenterEvent $event): void | ||
{ | ||
bdump($event->getPresenter(), 'Presenter'); | ||
} | ||
|
||
public function presenterStartup(PresenterStartupEvent $event): void | ||
{ | ||
bdump($event->getPresenter(), 'Presenter startup'); | ||
} | ||
|
||
public function presenterShutdown(PresenterShutdownEvent $event): void | ||
{ | ||
bdump($event->getPresenter(), 'Presenter shutdown'); | ||
} | ||
|
||
public function request(RequestEvent $event): void | ||
{ | ||
bdump($event->getRequest(), 'Request'); | ||
} | ||
|
||
public function response(ResponseEvent $event): void | ||
{ | ||
bdump($event->getResponse(), 'Response'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php declare(strict_types = 1); | ||
|
||
namespace App\Presenters; | ||
|
||
use App\Events\ExampleEvent; | ||
use Nette\Application\UI\Presenter; | ||
use Symfony\Component\EventDispatcher\EventDispatcher; | ||
|
||
class HomepagePresenter extends Presenter | ||
{ | ||
|
||
/** @var EventDispatcher */ | ||
private $dispatcher; | ||
|
||
public function __construct(EventDispatcher $dispatcher) | ||
{ | ||
parent::__construct(); | ||
$this->dispatcher = $dispatcher; | ||
} | ||
|
||
public function actionDefault(): void | ||
{ | ||
$this->dispatcher->dispatch(ExampleEvent::NAME, new ExampleEvent('example')); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="utf-8"> | ||
<meta name="viewport" content="width=device-width"> | ||
|
||
<title>{ifset title}{include title|stripHtml} | {/ifset}Nette Web</title> | ||
</head> | ||
|
||
<body> | ||
<div n:foreach="$flashes as $flash" n:class="flash, $flash->type">{$flash->message}</div> | ||
|
||
{include content} | ||
|
||
{block scripts} | ||
<script src="https://nette.github.io/resources/js/netteForms.min.js"></script> | ||
{/block} | ||
</body> | ||
</html> |
38 changes: 38 additions & 0 deletions
38
event-dispatcher/app/Presenters/templates/Homepage/default.latte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
{* This is the welcome page, you can delete it *} | ||
|
||
{block content} | ||
<div id="banner"> | ||
<h1 n:block=title>Congratulations!</h1> | ||
</div> | ||
|
||
<div id="content"> | ||
<h2>You have successfully created your <a href="https://nette.org">Nette</a> Web project.</h2> | ||
|
||
<p><img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEYAAABVCAYAAAD0bJKxAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAACudJREFUeNrMXG1sFMcZfvfu7ECw7+xDaQL+AApE1B+EJLapSNs4QIhtVWpSVTJNVIkqatX+II1apf8SoTZSq/KHiv5oqRolVaUS5UfgD04qtRAcUGipSrDdjxjHxDa0xOIcDBiMOU9nZj9udndmZ2Y/zjen0d7uzs7u+8z7Pu87H7sGCFLvrqfWGABbwMyBqfW5C5BrvhFYBkFFpiMvP3HlQ94JgwPI43izD+du1dpbn8XArLlRmaLLW+Qiznte3n7lPS4wPU/uyuHN6zg/rXpPwzAvb+kfhSzWGJTMg0fHBfGe3ZQ+hbORonIQcN5wAdOz80kCygnWbOrzeWhsbITabBZyuSz/ptYNjU3HwaidXhIBw6SF4i2YW5iGIlownz+FAUpTKLpfsTQnYwqI9tmgVFVVwUMPb4F8fqWjTsW7RQtiDio43WMsg3S6puwChtXE6lQNrKi6D67dnoC5uzOAiqY8qTS1mHWkTGrXjp1rcB0v2hdtfHAj1pAcLBaLUFxkcvEuzkUr33WdIxipZm1QUMiskHLLmiFtVNHyWAzyfGt/8ufPfc3WmD0swCMj/6RZyCucYy35Mcimb8bCJShZog1MBBysNcRyjmawGW1RIdige4vMAy2RgNIqRfUv4mwCgzUGoTo/XbNUgpTuiipJwGg3qHPIV0Sqij47FHckLqBi/Uiwn1F9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4nDXNqhIZdVmOQXUvZzTsNK3T3TvVAkCRqlMqDFh3z5BlSSgAvhIiWOSfIYyxDdJfGxDbzlrXBpTRgGDL0UcOQxPgGcEX6TzgOV+Qx/F9aYqf31MtI4dqiQBwzZgrO5a0IlEib1mwq8vjne1E3DX4SfqkhAwDkeR2MuiSypgyLpcqzbB/ARTLIGRaC5ae80/BC+g1lotHmT63nrMkxft3vU5jRGGeEwigdgmjirTGVoRxSP129d+dxTDdU4CrPJy+KitqL0EHsSv8OlOy6bMrzIdoRrzhZYWst2DzxKTqqukFox1BkFSoGo5+fSb8frP+sc/sTkG3j/zAfl6YDfOn4WOY2JuQV2uCfM2iq0p1RiUTJVBrMb5iJlxbba0EulLW79IFrQdAOuDXqpp01cLULv6TqjWLstcEacqEpUQTslU0xCFgNL982+O08nw6xgTB5izj9bBjtFF+r9106a1YH5B8XHcZ6rDLNwddLPN35iBXOMCVFySjgFRD/TLX3+vcMA+dnJwEO7Mz4PhcT6Gwtb5v/P5mrpVGzMPkclMywwMS63dW0CGrba0bMnFSx0fHR803P/NGNRA1mchzW4f2Zrn7DKIBqvc4wCv/XDmhAc+15bUmeYJzcmi4ynBcVkdPOB57Y04HY8wr1UtKlzvnDOs6FcmUCrgWNgt+98LDvuQixwBFz3nZFtRPUIgw4ASJHBKsB+UvfcAjvCybH/gxGD2Fz3gpphjwNn3BbcZibmkJMdk/1MKZhekMSigpXn/FxXKiupzmVIqwP5l/KLDRTJiB0WegSBuAL33TET7XI+k6p1AAigEAGAodM2C3mlBgmMywlbZAjjrqtSTobEvKwsaGgMhQFPd56b/CzAArAe2YDJd4I4AAAAASUVORK5CYII=" alt=""> | ||
If you are exploring Nette for the first time, you should read the | ||
<a href="https://doc.nette.org/quickstart">Quick Start</a>, <a href="https://doc.nette.org">documentation</a>, | ||
<a href="https://pla.nette.org">tutorials</a> and <a href="https://forum.nette.org">forum</a>.</p> | ||
|
||
<h2>We hope you enjoy Nette!</h2> | ||
</div> | ||
|
||
<style> | ||
html { font: normal 18px/1.3 Georgia, "New York CE", utopia, serif; color: #666; -webkit-text-stroke: 1px rgba(0,0,0,0); overflow-y: scroll; } | ||
body { background: #3484d2; color: #333; margin: 2em auto; padding: 0 .5em; max-width: 600px; min-width: 320px; } | ||
a { color: #006aeb; padding: 3px 1px; } | ||
a:hover, a:active, a:focus { background-color: #006aeb; text-decoration: none; color: white; } | ||
#banner { border-radius: 12px 12px 0 0; background-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAB5CAMAAADPursXAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAGBQTFRFD1CRDkqFDTlmDkF1D06NDT1tDTNZDk2KEFWaDTZgDkiCDTtpDT5wDkZ/DTBVEFacEFOWD1KUDTRcDTFWDkV9DkR7DkN4DkByDTVeDC9TDThjDTxrDkeADkuIDTRbDC9SbsUaggAAAEdJREFUeNqkwYURgAAQA7DH3d3335LSKyxAYpf9vWCpnYbf01qcOdFVXc14w4BznNTjkQfsscAdU3b4wIh9fDVYc4zV8xZgAAYaCMI6vPgLAAAAAElFTkSuQmCC); } | ||
h1 { font: inherit; color: white; font-size: 50px; line-height: 121px; margin: 0; padding-left: 4%; background: url(https://files.nette.org/images/logo-nette@2.png) no-repeat 95%; background-size: 130px auto; text-shadow: 1px 1px 0 rgba(0, 0, 0, .9); } | ||
@media (max-width: 600px) { | ||
h1 { background: none; font-size: 40px; } | ||
} | ||
#content { background: white; border: 1px solid #eff4f7; border-radius: 0 0 12px 12px; padding: 10px 4%; overflow: hidden; } | ||
h2 { font: inherit; padding: 1.2em 0; margin: 0; } | ||
img { border: none; float: right; margin: 0 0 1em 3em; } | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?php declare(strict_types = 1); | ||
|
||
namespace App\Router; | ||
|
||
use Nette\Application\IRouter; | ||
use Nette\Application\Routers\Route; | ||
use Nette\Application\Routers\RouteList; | ||
use Nette\StaticClass; | ||
|
||
class RouterFactory | ||
{ | ||
use StaticClass; | ||
|
||
public static function createRouter(): IRouter | ||
{ | ||
$router = new RouteList; | ||
$router[] = new Route('<presenter>/<action>[/<id>]', 'Homepage:default'); | ||
return $router; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?php declare(strict_types = 1); | ||
|
||
use Contributte\Bootstrap\ExtraConfigurator; | ||
|
||
require __DIR__ . '/../vendor/autoload.php'; | ||
|
||
$configurator = new ExtraConfigurator(); | ||
|
||
//$configurator->setDebugMode('23.75.345.200'); // enable for your remote IP | ||
$configurator->enableTracy(__DIR__ . '/../log'); | ||
|
||
$configurator->setTimeZone('Europe/Prague'); | ||
$configurator->setTempDirectory(__DIR__ . '/../temp'); | ||
|
||
$configurator->addConfig(__DIR__ . '/config/config.neon'); | ||
|
||
$container = $configurator->createContainer(); | ||
|
||
return $container; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
application: | ||
mapping: | ||
*: App\*Module\Presenters\*Presenter | ||
|
||
services: | ||
router: App\Router\RouterFactory::createRouter | ||
- App\Events\ExampleSubscriber | ||
|
||
extensions: | ||
events: Contributte\EventDispatcher\DI\EventDispatcherExtension | ||
events.application: Contributte\Events\Extra\DI\EventApplicationBridgeExtension | ||
events.security: Contributte\Events\Extra\DI\EventSecurityBridgeExtension |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
{ | ||
"require": { | ||
"php": ">= 7.1", | ||
"contributte/application": "^0.3.1", | ||
"contributte/bootstrap": "^0.3.1", | ||
"contributte/cache": "^0.2.0", | ||
"contributte/di": "^0.3.0", | ||
"contributte/event-dispatcher": "^0.4", | ||
"contributte/event-dispatcher-extra": "^0.4.1", | ||
"contributte/http": "^0.2.0", | ||
"contributte/security": "^0.2.0", | ||
"contributte/utils": "^0.2.0", | ||
"contributte/latte": "^0.3.0", | ||
"contributte/tracy": "^0.3.1", | ||
"nette/robot-loader": "^3.0.4" | ||
}, | ||
"autoload": { | ||
"psr-4": { | ||
"App\\": "app" | ||
} | ||
} | ||
} |
Oops, something went wrong.