Example #1
0
 /**
  * Checks each route against the request and on match 
  */
 public static function proccess(Request $request = null)
 {
     static::init();
     if (is_null($request)) {
         $request = Request::real();
     }
     foreach (static::$routes as $name => $route) {
         if ($route["route"]->match($request)) {
             if ($route["closure"]) {
                 call_user_func_array($route["closure"], array($route));
             } elseif (Event::hasListeners("sugi.route")) {
                 Event::fire("sugi.route", $route);
             } else {
                 $r = $route["route"];
                 App::execute("Controller_{$r->get('controller')}", "action_{$r->get('action')}", array($r->get('param'))) and exit;
             }
         }
     }
 }
Example #2
0
 public function testLazyCreation()
 {
     // register listener
     SugiEvent::listen("unit.test", function ($e) {
         $this->eventsDispatched++;
     });
     // firing event
     SugiEvent::fire("unit.test", array());
     $this->assertEquals(1, $this->eventsDispatched);
     // adding second listener
     SugiEvent::listen("unit.test", function ($e) {
         $this->eventsDispatched++;
     });
     // firing event with 2 listeners
     SugiEvent::fire("unit.test", array());
     $this->assertEquals(3, $this->eventsDispatched);
     // firing not listened event
     SugiEvent::fire("unit.test2", array());
     $this->assertEquals(3, $this->eventsDispatched);
 }
Example #3
0
 public static function getInstance()
 {
     if (!static::$db) {
         static::$db = static::factory(Config::get("database"));
         static::$registerEvents = Config::get("database.registerEvents", true);
         if (static::$registerEvents) {
             static::$db->hook("pre_open", function ($h) {
                 Event::fire("sugi.database.pre_open");
             });
             static::$db->hook("post_open", function ($h) {
                 Event::fire("sugi.database.post_open");
             });
             static::$db->hook("pre_query", function ($h, $query) {
                 Event::fire("sugi.database.pre_query", array("query" => $query));
             });
             static::$db->hook("post_query", function ($h, $query) {
                 Event::fire("sugi.database.post_query", array("query" => $query));
             });
         }
     }
     return static::$db;
 }