Ejemplo n.º 1
0
 /**
  * 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'));
 }
Ejemplo n.º 2
0
 *
 * ==============================================*/
// 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
Ejemplo n.º 3
0
            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";
Ejemplo n.º 4
0
 /**
  * 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'));
 }
Ejemplo n.º 5
0
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();
Ejemplo n.º 6
0
<?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();
});
Ejemplo n.º 7
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'));
 }
Ejemplo n.º 8
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'));
 }