My favorites | Sign in
Project Home Downloads Wiki Issues Source
Search
for

NlLib » System engine

  • MVC (Days_Model, Days_View, Days_Controller) - basisbegrippen die nodig zijn om te werken met framework
  • Days_Config - werken met de configuratie van de site
  • Days_Db - werk met database
  • Days_Db_Table - implementeren ORM vertegenwoordiging van de database tabellen
  • Days_Engine - uitgangspunt van binnenkomst
  • Days_Event - implementeren van observer design patroon
  • Days_Log fouten opslaan en debugging informatie-
  • Days_Request - user antwoordt in de browser
  • Days_Response - user reactie in de browser
  • Days_Url - werken met url addressen

In ontwikkeling

  • Days_Acl (Aceess Control List) - afbakening van de rechten van toegang tot delen van de site
  • Days_Filter - filteren van gegevens afkomstig van de gebruiker (ook bekend als validatie of verificatie van gegevens)
  • Days_Form - verwerking van gegevens uit HTML-formulieren
  • Days_User - werk met user (authorization, authentication, end of session)
NlLibDaysEvent  
Uitvoering van de Design Observer Pattern
Updated Jan 2, 2010 by janversl...@gmail.com

Overview

De Days_Event klasse implementeert een Observer ontwerp patroon. Het maakt het mogelijk om je te abonneren op een specifieke gebeurtenis en wordt aangemeld bij het plaatsvinden van het evenement. Een evenement kan verschillende luisteraars en elk van hen zal worden meegedeeld wanneer de gebeurtenis plaatsvindt.

Evenementen kunnen worden systeem of gebruiker gebeurtenissen.

System Events

engine.start - this event occurs immediately after reading the configuration file, prior to the framework core's start up.

controller.start - this event occurs immediately after a controller has been chosen but before the execution of the controller.

controller.post.init - this event occurs after a controller's init() method.

controller.end - this event occurs after receiving content from a controller, but before including it in the page's content.

engine.end - this event occurs when the framework core is finished.

response.send.headers - this event occurs before sending headers of a generated page.

response.send.content - this event occurs before sending the page's content.

You can subscribe to the earlier system events by creating a app/Controller/System/Autorun.php file with a App_Controller_System_Autorun class, where App is a prefix of your application.

class App_Controller_System_Autorun {
    / **
     * Defines a list of subscribers to the event
     */
    public static function run() {
        Days_Event::add('engine.start', 'session_start');
    }
}

In the static method run(), call Days_Event::add and the rest of the code that must be executed immediately after the framework's core initialization. The engine/autorun parameter in the application's configuration file must be equal to true.

An Example

Subscribing to the engine.end event

Days_Event:: add('engine.end', array('Days_Log', 'save'));

User Events

In your application, you can define your own custom events. In this case, your application is responsible for notifying subscribers when a custom event occurs. Start names of the custom events with your application's prefix.

Examples

1) Events from the framework's Days_User class

class Days_User {
  public function login($username, $password) {
    Days_Event::run('user.login.before');
    // Process logging
    if (/* logged well */) {
      Days_Event::run('user.login.success');
      ...
    }
    else {
      Days_Event::run('user.login.fail');
      ...
    }
    Days_Event::run('user.login.after');
  }
...

2) A custom event in the annex

class App_Model_Rss {
  public function import($path) {
    Days_Event::run('app.rss.import.before');
    // Process logging
    if (/* data loaded from RSS */) {
      Days_Event::run('app.rss.import.success');
      ...
    }
    else {
      Days_Event::run('app.rss.import.fail');
      ...
    }
    Days_Event::run('app.rss.import.after');
  }
}

3) Subscribing to user events in the annex

// Main Event Days
Days_Event::add('user.login.success','userSuccessLogged');
// Function called when the user logs on to a successful site
function userSuccessLogged() {
  echo 'You logged successfully on site!';


// Event of your application
Days_Event::add('myapp.rss.import.fail', 'rssNotLoaded');
// Callback function (callback)
function rssNotLoaded() {
  echo 'RSS not loaded. Enter correct URL adress';
}

Sign in to add a comment
Powered by Google Project Hosting