示例#1
0
文件: SlimTest.php 项目: rs3d/Slimplr
 /**
  * Test hook invocation if hook does not exist
  *
  * Pre-conditions:
  * Slim app instantiated;
  * Hook name does not exist;
  *
  * Post-conditions:
  * Hook is created;
  * Hook initialized with empty array;
  */
 public function testHookInvocationIfNotExists()
 {
     $app = new Slim();
     $app->applyHook('test.hook.one');
     $this->assertEquals(array(array()), $app->getHooks('test.hook.one'));
 }
示例#2
0
 /**
  * Test hook filter behavior
  */
 public function testHookFilterBehavior()
 {
     $app = new Slim();
     $app->hook('test.hook', function ($arg) {
         return $arg . 'foo';
     });
     $this->assertEquals('barfoo', $app->applyHook('test.hook', 'bar'));
 }
示例#3
0
 /**
  * Run the Slim application
  *
  * This method is the "meat and potatoes" of Slim and should be the last
  * method called. This fires up Slim, invokes the Route that matches
  * the current request, and returns the response to the client.
  *
  * This method will invoke the Not Found handler if no matching
  * routes are found.
  *
  * @return void
  */
 public static function run()
 {
     try {
         self::applyHook('slim.before');
         ob_start();
         self::applyHook('slim.before.router');
         $dispatched = false;
         foreach (self::router()->getMatchedRoutes() as $route) {
             try {
                 Slim::applyHook('slim.before.dispatch');
                 $dispatched = $route->dispatch();
                 Slim::applyHook('slim.after.dispatch');
                 if ($dispatched) {
                     break;
                 }
             } catch (Slim_Exception_Pass $e) {
                 continue;
             }
         }
         if (!$dispatched) {
             self::notFound();
         }
         self::response()->write(ob_get_clean());
         self::applyHook('slim.after.router');
         self::$app->flash->save();
         session_write_close();
         self::response()->send();
         self::applyHook('slim.after');
     } catch (Slim_Exception_RequestSlash $e) {
         self::redirect(self::request()->getRootUri() . self::request()->getResourceUri() . '/', 301);
     }
 }
示例#4
0
 /**
  * Test hook filter behavior
  *
  */
 public function testHookFilterBehavior()
 {
     Slim::init();
     Slim::hook('test.hook', function ($arg) {
         return $arg . 'foo';
     });
     $this->assertEquals('barfoo', Slim::applyHook('test.hook', 'bar'));
 }