当前位置: 首页>>代码示例>>PHP>>正文


PHP Slim::hook方法代码示例

本文整理汇总了PHP中Slim::hook方法的典型用法代码示例。如果您正苦于以下问题:PHP Slim::hook方法的具体用法?PHP Slim::hook怎么用?PHP Slim::hook使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Slim的用法示例。


在下文中一共展示了Slim::hook方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: testHookClear

 /**
  * Test clear hooks
  *
  * Pre-conditions:
  * Slim app initialized
  * Two hooks exist, each with one listener
  *
  * Post-conditions:
  * Case A: Listeners for 'test.hook.one' are cleared
  * Case B: Listeners for all hooks are cleared
  */
 public function testHookClear() {
     Slim::init();
     Slim::hook('test.hook.one', function () {});
     Slim::hook('test.hook.two', function () {});
     Slim::clearHooks('test.hook.two');
     $this->assertEquals(array(), Slim::getHooks('test.hook.two'));
     $this->assertTrue(count(Slim::getHooks('test.hook.one')) === 1);
     Slim::clearHooks();
     $this->assertEquals(array(), Slim::getHooks('test.hook.one'));
 }
开发者ID:ntdt,项目名称:Slim,代码行数:21,代码来源:SlimTest.php

示例2: recall_template

 *
 * ==============================================*/
// recall template
function recall_template()
{
    $template_path = $app->config('templates.path');
    //returns "../templates"
    return $template_path;
}
// End UTILS
/* == *
 *
 * HOOKS
 *
 * ==============================================*/
$app->hook('before.body', function () use($app) {
});
$app->hook('after.body', function () use($app) {
});
// End HOOKS
/* == *
 *
 * FILTERS
 *
 * ==============================================*/
$app->hook('test.filer', function ($argument) {
    return $argument;
});
// End FILTERS
/* == *
 *
 * ROUTES
开发者ID:nerdfiles,项目名称:slim_bp,代码行数:32,代码来源:index.php

示例3: foreach

            foreach (explode('\\n', file_get_contents(BASE_DIR . '/.gbemail')) as $email) {
                mail(trim($email), "GetchaBooks Error", get_error_message($e));
            }
        }
    });
});
$app->hook('slim.before', function () use($app) {
    global $referrers;
    $request = $app->request();
    define('BASE_URL', $request->getUrl() . $request->getRootUri() . '/');
    define('CURRENT_URL', $request->getUrl() . $request->getPath());
    define('MOBILE_DEVICE', strpos(strtolower($request->getUserAgent()), 'mobile') !== false);
    // remove extra slashes
    $path = $request->getPath();
    $newPath = preg_replace("#/{2,}#", '/', $path);
    if ($path != $newPath) {
        $app->redirect($request->getUrl() . $newPath, 301);
    }
    // process referrer tag
    if (isset($_GET['ref']) && isset($referrers[$_GET['ref']])) {
        $_SESSION['ref'] = $_GET['ref'];
        $_SESSION['tag'] = $referrers[$_GET['ref']];
    } else {
        $_SESSION['ref'] = null;
    }
});
$routes = (include 'routes.php');
// Use Slim with Class#method style routes
foreach ($routes as $name => $details) {
    $fn = function () use($details) {
        list($class, $method) = explode('.', $details[1]);
        $class = "{$class}Controller";
开发者ID:therealchiko,项目名称:getchabooks,代码行数:32,代码来源:index.php

示例4: testHookClear

 /**
  * Test clear hooks
  *
  * Pre-conditions:
  * Slim app instantiated;
  * Two hooks exist, each with one listener;
  *
  * Post-conditions:
  * Case A: Listeners for 'test.hook.one' are cleared;
  * Case B: Listeners for all hooks are cleared;
  */
 public function testHookClear()
 {
     $app = new Slim();
     $app->hook('test.hook.one', function () {
     });
     $app->hook('test.hook.two', function () {
     });
     $app->clearHooks('test.hook.two');
     $this->assertEquals(array(array()), $app->getHooks('test.hook.two'));
     $hookOne = $app->getHooks('test.hook.one');
     $this->assertTrue(count($hookOne[10]) === 1);
     $app->clearHooks();
     $this->assertEquals(array(array()), $app->getHooks('test.hook.one'));
 }
开发者ID:rs3d,项目名称:Slimplr,代码行数:25,代码来源:SlimTest.php

示例5: Autoloader

require "libs/Simplepie/autoloader.php";
//Autoload para as Classes do SimplePie, para leitura de RSS
require "libs/Slim/Slim.php";
//Micro-framework Slim, para gerenciamento de rotas e alguns Helpers
include "app/funcoes.php";
//Funções próprias, como CSS, Javascript e Meta
include "app/config.php";
//Configurações gerais do sistema, através de Constantes.
date_default_timezone_set('America/Sao_Paulo');
$autoloader = new Autoloader();
$app = new Slim();
$app->contentType('text/html; charset=utf-8');
$app->add(new Slim_Middleware_SessionCookie(array('secret' => '98897qwer65465qwe9r79qw9e354as68dh56k6lks6df8g', 'expires' => '60 minutes')));
$authenticate = function ($app) {
    return function () use($app) {
        if (!isset($_SESSION['dehbora']['user'])) {
            $_SESSION['dehbora']['urlRedirect'] = $app->request()->getPathInfo();
            $app->flash('error', 'Você precisa se logar.');
            $app->redirect(URL_BASE . '/inicial');
        }
    };
};
$app->hook('slim.before.dispatch', function () use($app) {
    $user = null;
    if (isset($_SESSION['dehbora']['user'])) {
        $user = $_SESSION['dehbora']['user'];
    }
    $app->view()->setData('user', $user);
});
require_once "app/routes.php";
$app->run();
开发者ID:romulo1984,项目名称:dehbora,代码行数:31,代码来源:index.php

示例6: Slim

<?php

define('AUTHCOOKIE', 'superblorg');
use Infrastructure\Persistence\Doctrine\UnitOfWork;
use Presentation\Services\SlimAuthenticationService;
use Infrastructure\Persistence\Doctrine\UserRepository;
use Domain\UserAuthenticator;
use Domain\PasswordHasher;
$app = new Slim(array('view' => 'TwigView', 'templates.path' => dirname(dirname(__FILE__)) . DS . 'Views'));
//common objects
$unitOfWork = new UnitOfWork();
$userRepo = new UserRepository();
$authService = new SlimAuthenticationService($app, $userRepo, new UserAuthenticator($userRepo, new PasswordHasher()));
$app->hook('slim.before', function () use($app, $authService, $unitOfWork) {
    if (!$authService->isAuthenticated(AUTHCOOKIE)) {
        $app->response()->redirect('/login', 303);
    }
    if ($user = $authService->getLoggedInUser(AUTHCOOKIE)) {
        $authService->regenerateUserCookie(AUTHCOOKIE, $user);
    }
    $unitOfWork->begin();
});
$app->hook('slim.after', function () use($app, $unitOfWork) {
    $unitOfWork->commit();
});
开发者ID:r3laXcode,项目名称:php-classic-blog,代码行数:25,代码来源:init.php

示例7: 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'));
 }
开发者ID:inscriptionweb,项目名称:lebonmail,代码行数:11,代码来源:SlimTest.php

示例8: 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'));
 }
开发者ID:alanvivona,项目名称:scawTP,代码行数:12,代码来源:SlimTest.php


注:本文中的Slim::hook方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。