Overview

Namespaces

  • GLFramework
    • Cache
    • Controller
    • DaMa
      • Manipulators
    • Database
    • HTTP
    • Mail
    • Middleware
    • Model
    • Module
    • Tests
    • Upload
    • Utils
  • None

Classes

  • GLFramework\Bootstrap
  • GLFramework\Cache\Cache
  • GLFramework\Cache\MemcachedCache
  • GLFramework\Cache\MemoryCache
  • GLFramework\Controller
  • GLFramework\Controller\AdminController
  • GLFramework\Controller\APIController
  • GLFramework\Controller\AuthController
  • GLFramework\Controller\ErrorController
  • GLFramework\Controller\ExceptionController
  • GLFramework\DaMa\Association
  • GLFramework\DaMa\DataManipulation
  • GLFramework\DaMa\Manipulator
  • GLFramework\DaMa\Manipulators\CSVManipulator
  • GLFramework\DaMa\Manipulators\ManipulatorCore
  • GLFramework\DaMa\Manipulators\XLSManipulator
  • GLFramework\DaMa\Manipulators\XLSXManipulator
  • GLFramework\Database\Connection
  • GLFramework\Database\MySQLConnection
  • GLFramework\DatabaseManager
  • GLFramework\DBStructure
  • GLFramework\Events
  • GLFramework\Filesystem
  • GLFramework\HTTP\API
  • GLFramework\Log
  • GLFramework\Mail
  • GLFramework\Mail\Mail
  • GLFramework\Mail\MailSystem
  • GLFramework\Mail\PHPMailer
  • GLFramework\MailView
  • GLFramework\Middleware\APIAuthorizationMiddleware
  • GLFramework\Middleware\ControllerMiddleware
  • GLFramework\Model
  • GLFramework\Model\Page
  • GLFramework\Model\User
  • GLFramework\Model\UserPage
  • GLFramework\ModelResult
  • GLFramework\Module\Module
  • GLFramework\Module\ModuleManager
  • GLFramework\Request
  • GLFramework\Response
  • GLFramework\Tests\DatabaseTestCase
  • GLFramework\Tests\TestCase
  • GLFramework\Upload\Upload
  • GLFramework\Upload\Uploads
  • GLFramework\Utils\DataTablesManager
  • GLFramework\Versions
  • GLFramework\View

Interfaces

  • GLFramework\Middleware

Functions

  • array_merge_recursive_ex
  • e
  • file_get_php_classes
  • fix_date
  • fix_date_format
  • fix_decimal
  • fix_url
  • get
  • get_php_classes
  • http_response_code
  • instance_method
  • is_module_enabled
  • now
  • post
  • print_array
  • print_brief_debug
  • print_debug
  • random_str
  • reArrayFiles
  • reArrayPost
  • today
  • Overview
  • Namespace
  • Class
  1: <?php
  2: /**
  3:  * Created by PhpStorm.
  4:  * User: manus
  5:  * Date: 2/03/16
  6:  * Time: 9:57
  7:  */
  8: 
  9: namespace GLFramework;
 10: 
 11: 
 12: use GLFramework\Module\Module;
 13: 
 14: class Events
 15: {
 16:     private static $instance;
 17:     private $handlers = array();
 18: 
 19:     /**
 20:      * Events constructor.
 21:      */
 22:     public function __construct()
 23:     {
 24:         self::$instance = $this;
 25:     }
 26: 
 27:     /**
 28:      * @return Events
 29:      */
 30:     public static function getInstance()
 31:     {
 32:         return self::$instance;
 33:     }
 34: 
 35:     /**
 36:      * Se pone a la escucha de un evento, se puede añadir en la configuración del módulo
 37:      *  dentro de *app:listeners*
 38:      * @param $event
 39:      * @param $fn
 40:      * @param array $context
 41:      */
 42:     public function listen($event, $fn, $context = array())
 43:     {
 44:         if(!isset($this->handlers[$event]))
 45:         {
 46:             $this->handlers[$event] = array();
 47:         }
 48:         $this->handlers[$event][] = array('fn' => $fn, 'context' => $context);
 49: 
 50:     }
 51: 
 52:     /**
 53:      *
 54:      * Publica un evento al sistema, devuelve
 55:      *      0 si no hay nadie que lo procese,
 56:      *      true si almenos alguien devuelve true
 57:      *      false si todos devuelven false
 58:      * @param $event
 59:      * @param array $args
 60:      * @return bool|int|string
 61:      */
 62:     public static function fire($event, $args = array())
 63:     {
 64:         return self::getInstance()->_fire($event, $args);
 65:     }
 66: 
 67:     public function _fire($event, $args = array())
 68:     {
 69:         global $context;
 70:         $buffer = array();
 71:         if(!is_array($args)) $args = array($args);
 72:         if(isset($this->handlers[$event]) && count(($this->handlers[$event])) > 0)
 73:         {
 74:             $handlers = $this->handlers[$event];
 75:             foreach($handlers as $item)
 76:             {
 77:                 $fn = $item['fn'];
 78:                 $context = $item['context'];
 79:                 if(is_callable($fn))
 80:                 {
 81:                     $result = call_user_func_array($fn, $args);
 82:                     if($result === true)
 83:                     {
 84:                         return true;
 85:                     }
 86:                     else
 87:                     {
 88:                         $buffer[] = $result;
 89:                     }
 90:                 }
 91:                 else
 92:                 {
 93:                     Log::getInstance()->error("Can not call event: " . $event . " function: " . print_r($fn, true), array('events'));
 94:                 }
 95:             }
 96:             return $buffer;
 97:         }
 98:         return 0;
 99:     }
100: 
101:     public static function anyFalse($result)
102:     {
103:         foreach ($result as $item)
104:             if($item === false) return true;
105:         return false;
106:     }
107: 
108:     /**
109:      * @return Module
110:      */
111:     public static function getContext()
112:     {
113:         global $context;
114:         return $context;
115:     }
116: }
API documentation generated by ApiGen