Skip to content

Commit

Permalink
Añadido gestor de eventos.
Browse files Browse the repository at this point in the history
  • Loading branch information
NeoRazorX committed Jun 11, 2017
1 parent 859a2dc commit fbe8675
Show file tree
Hide file tree
Showing 9 changed files with 106 additions and 7 deletions.
15 changes: 15 additions & 0 deletions base/fs_controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

namespace FacturaScripts\Base;

use Symfony\Component\EventDispatcher\EventDispatcher;
use Symfony\Component\HttpFoundation\Request;

/**
Expand Down Expand Up @@ -53,6 +54,12 @@ class fs_controller {
*/
protected $className;

/**
* Gestor de eventos.
* @var EventDispatcher
*/
protected $dispatcher;

/**
* Traductor multi-idioma.
* @var fs_i18n
Expand Down Expand Up @@ -82,12 +89,20 @@ public function __construct($folder = '', $className = __CLASS__) {
}

$this->className = $className;
$this->dispatcher = new EventDispatcher();
$this->i18n = new fs_i18n();
$this->messages = [];
$this->request = Request::createFromGlobals();
$this->template = $className . '.html';
$this->title = $className;
}

/**
* Ejecuta la lógica del controlador.
*/
public function run() {
$this->dispatcher->dispatch('pre-run');
}

/**
* Devuelve la url del controlador actual.
Expand Down
4 changes: 3 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@
}
],
"require": {
"php": ">=5.5.9",
"symfony/http-foundation": "v3.3.2",
"symfony/translation": "v3.3.2",
"twig/twig": "v1.34.3",
"components/jquery": "dev-master",
"twbs/bootstrap": "dev-master",
"components/font-awesome": "dev-master",
"maximebf/debugbar": "dev-master"
"maximebf/debugbar": "dev-master",
"symfony/event-dispatcher": "v3.3.2"
},
"autoload": {
"psr-4": {
Expand Down
67 changes: 65 additions & 2 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion controller/admin_home.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,11 @@ class admin_home extends fs_controller {

public function __construct($folder = '', $className = __CLASS__) {
parent::__construct($folder, $className);

}

public function run() {
parent::run();

if ($this->request->get('enable', '') != '') {
$pluginManager = new fs_plugin_manager();
$pluginManager->enable($this->request->get('enable'));
Expand Down
2 changes: 1 addition & 1 deletion i18n/es_ES.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@
"plugin-enabled": "Plugin activado correctamente.",
"plugin-disabled": "Plugin desactivado correctamente.",
"template-not-found": "Template no encontrado",
"to-do-list": "Proponer sistema de hooks para los controladores. Un sistema que permita a los plugins añadir funciones a ejecutar antes o después de determinada acción en un controlador."
"to-do-list": ""
}
1 change: 1 addition & 0 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
if ($controller) {
try {
$fsc = new $controller(__DIR__, $controllerName);
$fsc->run();
$template = $fsc->template;
} catch (Exception $ex) {
$fscException = $ex;
Expand Down
4 changes: 4 additions & 0 deletions plugins/test/controller/admin_home.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ class admin_home extends fs_controller {
public function __construct($folder = '', $className = __CLASS__) {
parent::__construct($folder, $className);
$this->title = 'TEST';
}

public function run() {
parent::run();

if ($this->request->get('disable', '') != '') {
$pluginManager = new fs_plugin_manager();
Expand Down
7 changes: 6 additions & 1 deletion plugins/test/view/admin_home.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@
<div class="row">
<div class="col-sm-12">
<div class="page-header">
<h1>{{ i18n.trans('hello-world') }}</h1>
<h1>
{{ i18n.trans('hello-world') }}
<a href="{{ fsc.url() }}" class="btn btn-xs btn-default">
<i class="fa fa-refresh" aria-hidden="true"></i>
</a>
</h1>
</div>
<h2>{{ i18n.trans('hello-world-2') }}</h2>
<p class="help-block">{{ i18n.trans('hello-world-text') }}</p>
Expand Down
7 changes: 6 additions & 1 deletion view/admin_home.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@
<div class="row">
<div class="col-sm-12">
<div class="page-header">
<h1>{{ i18n.trans('hello-world') }}</h1>
<h1>
{{ i18n.trans('hello-world') }}
<a href="{{ fsc.url() }}" class="btn btn-xs btn-default">
<i class="fa fa-refresh" aria-hidden="true"></i>
</a>
</h1>
<p class="help-block">{{ i18n.trans('hello-world-text') }}</p>
</div>
<div class="embed-responsive embed-responsive-16by9">
Expand Down

0 comments on commit fbe8675

Please sign in to comment.