/**
  * Test hooks accept multiple arguments
  *
  * Pre-conditions:
  * Slim app instantiated;
  * Hook name does not exist;
  * Listener is a callable object;
  *
  * Post-conditions:
  * Callable invoked with 2 arguments
  */
 public function testHooksMultipleArguments()
 {
     $testArgA = 'argumentA';
     $testArgB = 'argumentB';
     $this->expectOutputString($testArgA . $testArgB);
     $app = new \Slim\Slim();
     $app->hook('test.hook.one', function ($argA, $argB) {
         echo $argA . $argB;
     });
     $app->applyHook('test.hook.one', $testArgA, $testArgB);
 }
        file_put_contents($logfile, '');
    }
    umask($old);
    $log = new \Monolog\Logger(strtoupper($app->request->getHost()));
    $log->pushHandler(new \Monolog\Handler\StreamHandler($logfile, \Monolog\Logger::DEBUG, true, 0777));
    return $log;
});
/**
 * Register handlers
 */
\Monolog\ErrorHandler::register($app->log);
/**
 * Error handle
 */
$app->error(function (\Exception $e) use($app) {
    $app->applyHook('log.request.info', $e->getMessage());
    $app->log->error($e);
    $app->render('error.php');
});
$app->notFound(function () use($app) {
    $app->applyHook('log.request.info', 'Page not found');
    $app->render('404.php');
});
// throw new \Exception('test error');
/**
 * Define hooks
 */
if (file_exists(APPPATH . 'hooks.php')) {
    require APPPATH . 'hooks.php';
}
/**
Example #3
0
File: index.php Project: guhya/Slim
        $twig->addGlobal("userSession", $_SESSION["user"]);
    } else {
        $twig->addGlobal("userSession", "");
    }
    //Define the page/router that begins with these segment to not initialize all gnb menu list
    $rawPages = array("ajax", "user", "social");
    //Determine whether the request is an ajax request or the normal one
    $isXHR = $app->request->isAjax();
    //If the request is an ajax type request, or the request does not need to initialize gnb (like processor page)
    //then no need to initialize gnb
    if (!$isXHR && !in_array($menu, $rawPages)) {
    } else {
        //Ajax request, do nothing
    }
}, 1);
$app->applyHook("slim.before.router");
/************************************ THE ROUTES / CONTROLLERS *************************************************/
//#################################################### HOME ####################################################
$app->get("/", function () use($app, $util) {
    $data = array("pageTitle" => "Home Page");
    $app->render("front/index.twig", $data);
});
$app->get("/social/facebook-share", function () use($app, $util) {
    $data = array("pageTitle" => "Social Page - Facebook");
    $app->render("front/social/facebookShare.twig", $data);
});
//#################################################### FORM ####################################################
$app->get("/form", function () use($app, $util) {
    $app->render("front/form/form.twig");
});
$app->post("/form", function () use($app, $util) {
Example #4
0
 /**
  * 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\Slim();
     $app->applyHook('test.hook.one');
     $this->assertEquals(array(array()), $app->getHooks('test.hook.one'));
 }
Example #5
0
$state_calculator = new StateTaxCalculatorModel();
$federal_calculator = new FederalTaxCalculatorModel();
$app = new \Slim\Slim();
// Parse the response and display it.
$app->hook('respond', function ($response) use($app) {
    $app->response->header('Access-Control-Allow-Origin', '*');
    $app->response->headers->set('Content-Type', 'application/json');
    if ($response['success'] === false) {
        $app->halt(400, "{\"success\": false, \"reason\": \"" . $response['reason'] . "\"}");
    } else {
        echo json_encode($response['data']);
    }
});
$app->get('/v1/federal/:year/', function ($year) use($app, $federal_calculator) {
    $response = $federal_calculator->get_federal_data($year);
    $app->applyHook('respond', $response);
});
$app->get('/v1/state/:state/:year/', function ($year, $state) use($app, $state_calculator) {
    $response = $state_calculator->get_state_data($year, $state);
    $app->applyHook('respond', $response);
});
$app->post('/v1/calculate/:year/', function ($year) use($app, $state_calculator, $federal_calculator) {
    $pay_rate = $app->request->post('pay_rate');
    $pay_periods = $app->request->post('pay_periods') == false ? 1 : $app->request->post('pay_periods');
    $filing_status = $app->request->post('filing_status');
    $state = $app->request->post('state');
    if (!isset($pay_rate) || !isset($filing_status)) {
        $response['success'] = false;
        $response['reason'] = "Missing required parameters";
    } else {
        $federal_response = $federal_calculator->calculate($year, $pay_rate, $pay_periods, $filing_status, $state);