/**
  * Constructor
  */
 public function __construct(HttpRequestInterface $request, HttpResponseInterface $response)
 {
     $this->request = $request;
     $this->response = $response;
     $this->pre_filter_manager = new \Koch\Filter\FilterManager();
     $this->post_filter_manager = new \Koch\Filter\FilterManager();
     $this->event_dispatcher = \Koch\Event\Dispatcher::instantiate();
     $this->router = new \Koch\Router\Router($this->request);
 }
Beispiel #2
0
 public function executeFilter(HttpRequestInterface $request, HttpResponseInterface $response)
 {
     // webdebug must be enabled in configuration
     if (isset($this->config['error']['webdebug']) and $this->config['error']['webdebug'] === 1) {
         return;
     }
     // DEBUG mode must be on
     if (defined('DEBUG') and DEBUG === true) {
         return;
     }
     /*
      * ================================================
      *  Initialize PHP_Debug Web-Debugging Console
      * ================================================
      */
     // Additional ini path for PHPDEBUG
     define('ADD_PHPDEBUG_ROOT', ROOT_LIBRARIES . 'phpdebug');
     set_include_path(ADD_PHPDEBUG_APPLICATION_PATH . PATH_SEPARATOR . get_include_path());
     // Load Library
     if (false === class_exists('PHP_Debug', false)) {
         include ROOT_LIBRARIES . 'phpdebug/PHP/Debug.php';
     }
     // Setup Options for the PHPDebug Object
     $options = ['render_type' => 'HTML', 'render_mode' => 'div', 'restrict_access' => false, 'allow_url_access' => true, 'url_key' => 'key', 'url_pass' => 'nounou', 'enable_watch' => true, 'replace_errorhandler' => true, 'lang' => 'EN', 'HTML_DIV_view_source_script_name' => APPLICATION_PATH . 'libraries/phpdebug/PHP_Debug_ShowSource.php', 'HTML_DIV_images_path' => WWW_ROOT . 'libraries/phpdebug/images', 'HTML_DIV_css_path' => WWW_ROOT . 'libraries/phpdebug/css', 'HTML_DIV_js_path' => WWW_ROOT . 'libraries/phpdebug/js', 'HTML_DIV_remove_templates_pattern' => true];
     // Initialiaze Object
     $debug = new PHP_Debug($options);
     // Set Title to Debug Console
     $debug->add('Koch Framework DEBUG INFO');
     /*
      *  Load JS / CSS for PHP Debug Console into the Output Buffer
      */
     $html = '<script type="text/javascript" src="' . $options['HTML_DIV_js_path'] . '/html_div.js"></script>';
     $html .= '<link rel="stylesheet" type="text/css"';
     $html .= ' media="screen" href="' . $options['HTML_DIV_css_path'] . '/html_div.css" />';
     unset($options);
     // combine the html output
     $debugbarHTML = $html . $debug->getOutput();
     // push output into event object
     $event = new DebugConsoleResponse_Event($debugbarHTML);
     // and output the debugging console at the end of the application runtime
     \Koch\Event\Dispatcher::instantiate()->addEventHandler('onApplicationShutdown', $event);
 }
Beispiel #3
0
/**
 * Name:    triggerevent
 * Type:    function
 * Purpose: This TAG is acts a trigger to an possibly registered event for the eventname $name.
 *
 * @example
 *  {triggerEvent name="onRenderXY"}
 *
 * @param $params mixed $params['name'] the eventname
 * @param Smarty $smarty
 *
 * @return string
 */
function Smarty_function_triggerevent($params, $smarty)
{
    // we need an valid eventname to trigger it
    if (empty($params['name'])) {
        trigger_error('name: Please add an event name.');
        return;
    }
    // @todo consider passing smarty or more template infos as context to the event
    $context = [];
    $context['params'] = $params;
    // pass the modulename as info
    //$info = array();
    //$info['modulename'] = getModuleName();
    /*
     * direct return to the template
     * this implies that events should generate HTML output
     * or just transform the $context for the later occuring rendering process
     * @see todo at context above
     */
    return \Koch\Event\Dispatcher::instantiate()->triggerEvent($params['name'], $context, $info);
}
Beispiel #4
0
 /**
  * Registers multiple Events by Name.
  */
 public static function loadEventHandlers($events)
 {
     if (empty($events) or is_array($events) === false) {
         return;
     } else {
         // ok, we got an array with some event names
         foreach ($events as $event) {
             // array[0] filename
             $filename = $array[0];
             // array[1] classname
             $classname = \Koch\Functions\Functions::ensurePrefixedWith($array[1], '\\Koch\\Event\\Event');
             // load eventhandler
             \Koch\Autoload\Loader::requireFile($filename, $classname);
             // instantiate eventhandler
             $event_object = new $classname();
             // add the eventhandler to the dispatcher
             $eventdispatcher = \Koch\Event\Dispatcher::instantiate();
             $eventdispatcher->addEventHandler($event, $event_object);
         }
     }
 }
Beispiel #5
0
 /**
  * triggerEvent is shortcut/convenience method for Eventdispatcher->triggerEvent
  *
  * @param mixed (string|object) $event   Name of Event or Event object to trigger.
  * @param object                $context Context of the event triggering, often the object from where we are calling ($this). Default Null.
  * @param string                $info    Some pieces of information. Default Null.
  */
 public function triggerEvent($event, $context = null, $info = null)
 {
     \Koch\Event\Dispatcher::instantiate()->triggerEvent($event, $context = null, $info = null);
 }
Beispiel #6
0
 /**
  * triggerEvent
  * Is an convenience/proxy method for easier registration of Events.
  * The method parameters are passed to / forwarded to
  * Clansuite_Eventdispatcher::instantiate()->triggerEvent().
  *
  * @param string|object $event   Name of Event or Event object to trigger.
  * @param string        $context The context of the event triggering, the object from where we are calling. Defaults to null.
  * @param string        $info    Some pieces of information. Defaults to null.
  */
 public static function triggerEvent($event, $context = null, $info = null)
 {
     if (class_exists('Koch\\Event\\Dispatcher', false) === true) {
         \Koch\Event\Dispatcher::instantiate()->triggerEvent($event, $context, $info);
     }
 }