本文整理汇总了PHP中Slim::applyHook方法的典型用法代码示例。如果您正苦于以下问题:PHP Slim::applyHook方法的具体用法?PHP Slim::applyHook怎么用?PHP Slim::applyHook使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Slim
的用法示例。
在下文中一共展示了Slim::applyHook方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testHookInvocationIfNotExists
/**
* 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: testHookFilterBehavior
/**
* 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: run
/**
* 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: testHookFilterBehavior
/**
* 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'));
}