Skip to content

Commit

Permalink
Upgraded to minimal v0.2.1, events and logger, updated demo and docs
Browse files Browse the repository at this point in the history
  • Loading branch information
judus committed Apr 10, 2018
1 parent f085550 commit 97e70f3
Show file tree
Hide file tree
Showing 13 changed files with 225 additions and 2 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -812,9 +812,15 @@ Minimal requires at least these packages:
- [![Build Status](https://travis-ci.org/judus/minimal-controllers.svg?branch=master)](https://travis-ci.org/judus/minimal-controllers)
[![Latest Version](http://img.shields.io/packagist/v/minimal/controllers.svg)](https://packagist.org/packages/minimal/controllers)
[judus/minimal-controllers](https://github.com/judus/minimal-controllers) - the frontcontroller
- [![Build Status](https://travis-ci.org/judus/minimal-event.svg?branch=master)](https://travis-ci.org/judus/minimal-event)
[![Latest Version](http://img.shields.io/packagist/v/minimal/event.svg)](https://packagist.org/packages/minimal/event)
[judus/minimal-event](https://github.com/judus/minimal-event) - a simple event dispatcher
- [![Build Status](https://travis-ci.org/judus/minimal-http.svg?branch=master)](https://travis-ci.org/judus/minimal-http)
[![Latest Version](http://img.shields.io/packagist/v/minimal/http.svg)](https://packagist.org/packages/minimal/http)
[judus/minimal-http](https://github.com/judus/minimal-http) - request and response objects
- [![Build Status](https://travis-ci.org/judus/minimal-log.svg?branch=master)](https://travis-ci.org/judus/minimal-log)
[![Latest Version](http://img.shields.io/packagist/v/minimal/log.svg)](https://packagist.org/packages/minimal/log)
[judus/minimal-event](https://github.com/judus/minimal-event) - a simple logger
- [![Build Status](https://travis-ci.org/judus/minimal-middlewares.svg?branch=master)](https://travis-ci.org/judus/minimal-middlewares)
[![Latest Version](http://img.shields.io/packagist/v/minimal/middlewares.svg)](https://packagist.org/packages/minimal/middlewares)
[judus/minimal-middlewares](https://github.com/judus/minimal-middlewares) - a unconventional middleware implementation
Expand Down
34 changes: 34 additions & 0 deletions app/Demo/Base/Models/Info.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace App\Demo\Base\Models;

use Maduser\Minimal\Event\Subscriber;
use Maduser\Minimal\Framework\Facades\Event;
use Maduser\Minimal\Framework\Minimal;
use Maduser\Minimal\Cli\Console;
use Maduser\Minimal\Framework\Facades\IOC;
Expand Down Expand Up @@ -158,6 +160,37 @@ public function bindings()
return $content;
}

public function events()
{
$thead = [['Events', 'Actions']];
$tbody = [];

foreach (Event::events() as $event => $subscribers)
{
$array = [];
foreach ($subscribers as $subscriber)
{
/** @var $subscriber Subscriber */
$actions = $subscriber->getEventActions($event);

foreach ($actions as $action)
{
$array[] = get_class($subscriber) . '::' . $action;
}

}

$tbody[] = [$event, implode(', ', $array)];
}

ob_start();
$this->console->table($tbody, $thead);
$content = ob_get_contents();
ob_end_clean();

return $content;
}

public function array_flat($array, $prefix = '')
{
$result = array();
Expand All @@ -184,6 +217,7 @@ public function __toString()
$contents.= '</br><pre style="display: table; width: auto; margin: 0 auto;">MODULES' . $this->modules() .'</pre>';
$contents.= '</br><pre style="display: table; width: auto; margin: 0 auto;">PROVIDERS' . $this->providers() .'</pre>';
$contents.= '</br><pre style="display: table; width: auto; margin: 0 auto;">BINDINGS' . $this->bindings() .'</pre>';
$contents.= '</br><pre style="display: table; width: auto; margin: 0 auto;">EVENTS' . $this->events() .'</pre>';

return $contents;
}
Expand Down
19 changes: 19 additions & 0 deletions app/Demo/Events/Config/routes.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

/** @var \Maduser\Minimal\Routing\Router $router */

use App\Demo\Events\SubscriberA;
use App\Demo\Events\SubscriberB;
use Maduser\Minimal\Framework\Facades\Event;

$router->group([
'middlewares' => []
], function() use ($router) {

$router->get('events', function() {
Event::dispatch('event.a', 'Some message');
Event::dispatch('event.b', ['some' => 'data']);
Event::dispatch('event.c');
});

});
6 changes: 6 additions & 0 deletions app/Demo/Events/Config/subscribers.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?php

return [
\App\Demo\Events\SubscriberA::class,
\App\Demo\Events\SubscriberB::class,
];
24 changes: 24 additions & 0 deletions app/Demo/Events/SubscriberA.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php namespace App\Demo\Events;

use Maduser\Minimal\Event;
use Maduser\Minimal\Event\Subscriber;

class SubscriberA extends Subscriber
{
protected $events = [
'event.a' => 'respondToEventA',
'event.b' => 'respondToEventB'
];

public function respondToEventA($data)
{
show('SubscriberA responding to event.a');
show($data);
}

public function respondToEventB($data)
{
show('SubscriberA responding to event.b');
show($data);
}
}
34 changes: 34 additions & 0 deletions app/Demo/Events/SubscriberB.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

namespace App\Demo\Events;

use Maduser\Minimal\Event\Subscriber;

class SubscriberB extends Subscriber
{
protected $events = [
'event.b' => [
'respondToEventB1',
'respondToEventB2',
],
'event.c' => [
'respondToEventC',
]
];

public function respondToEventB1()
{
show('SubscriberB responding to event.b (B1)');
}

public function respondToEventB2()
{
show('SubscriberB responding to event.b (B2)');
}

public function respondToEventC()
{
show('SubscriberB responding to event.c');
}

}
64 changes: 64 additions & 0 deletions app/Demo/Events/SystemSubscriber.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?php

namespace App\Demo\Events;

use Maduser\Minimal\Event\Subscriber;

class SystemSubscriber extends Subscriber
{
protected $events = [
'app.ready' => 'onAppReady',
'app.routed' => 'onAppRouted',
'app.frontController.dispatch' => 'onFrontControllerDispatch',
'app.frontController.dispatched' => 'onFrontControllerDispatched',
'app.respond' => 'onAppRespond',
'app.responded' => 'onAppResponded',
'app.terminate' => 'onAppTerminate',
'app.terminated' => 'onAppTerminated',
];

public function onAppReady()
{
show($this->interval() . ' - App is ready');
}

public function onAppRouted()
{
show($this->interval() . ' - App is routed');
}

public function onFrontControllerDispatch()
{
show($this->interval() . ' - App is about to dispatch the FrontController');
}

public function onFrontControllerDispatched()
{
show($this->interval() . ' - App has dispatched the FrontController');
}

public function onAppRespond()
{
show($this->interval() . ' - App is about to respond');
}

public function onAppResponded()
{
show($this->interval() . ' - App has responded');
}

public function onAppTerminate()
{
show($this->interval() . ' - App is about to terminate');
}

public function onAppTerminated()
{
show($this->interval() . ' - App is terminating');
}

protected function interval()
{
return microtime(true) - $_SERVER["REQUEST_TIME_FLOAT"];
}
}
17 changes: 17 additions & 0 deletions app/Demo/Logger/Config/routes.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

/** @var \Maduser\Minimal\Routing\Router $router */

use Maduser\Minimal\Framework\Events\Subscribers\SystemLog;
use Maduser\Minimal\Framework\Facades\Event;
use Maduser\Minimal\Framework\Facades\Log;

$router->group([
'middlewares' => []
], function() use ($router) {

$router->get('logger', function() {
Log::info('Hello');
});

});
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
"minimal/cli": "v0.1.1",
"minimal/database": "v0.1.4",
"minimal/html": "v0.1.2",
"minimal/minimal": "v0.1.14",
"minimal/paths": "v0.1.4",
"minimal/minimal": "v0.2.1",
"minimal/paths": "v0.1.5",
"minimal/presenters": "v0.1.1",
"minimal/translation": "v0.1.2",
"minimal/views": "v0.1.3"
Expand Down
10 changes: 10 additions & 0 deletions config/minimal.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
'public' => 'public',
'resources' => 'resources',
'storage' => 'storage',
'logs' => 'storage/logs',
'system' => realpath(__DIR__ . '/../'),
'translations' => 'storage/lang/lang.json',
'views' => 'resources/views/my-theme'
Expand All @@ -36,6 +37,7 @@
'bindingsFile' => 'Config/bindings.php',
'configFile' => 'Config/config.php',
'providersFile' => 'Config/providers.php',
'subscribersFile' => 'Config/subscribers.php',
'routesFile' => 'Config/routes.php',
],

Expand Down Expand Up @@ -67,6 +69,14 @@
'display_errors' => 0
],

// ----------------------------------------------------------------------------
// LOGGING

'log' => [
'level' => 5,
'benchmarks' => false
],

// ----------------------------------------------------------------------------
// STORAGE FOLDERS

Expand Down
2 changes: 2 additions & 0 deletions config/providers.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@
'CollectionFactory' => CollectionFactoryProvider::class,
'Config' => ConfigProvider::class,
'ControllerFactory' => ControllerFactoryProvider::class,
'Event' => EventProvider::class,
'Factory' => FactoryProvider::class,
'FrontController' => FrontControllerProvider::class,
'FormBuilder' => FormProvider::class,
'HtmlBuilder' => HtmlProvider::class,
'Log' => LoggerProvider::class,
'Middleware' => MiddlewareProvider::class,
'Module' => ModuleProvider::class,
'ModuleFactory' => ModuleFactoryProvider::class,
Expand Down
7 changes: 7 additions & 0 deletions config/subscribers.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php

use Maduser\Minimal\Framework\Events\Subscribers\SystemLog;

return [
SystemLog::class
];
File renamed without changes.

0 comments on commit 97e70f3

Please sign in to comment.