/**
  * Get old input by key
  * @param string $key 
  * @return mixed
  */
 public function getOldInput($key)
 {
     $this->input = $this->request->hasOldInput() !== false ? $this->request->oldInput() : array();
     // Input that is flashed to the flash can be easily retrieved by the
     // developer, making repopulating old forms and the like much more
     // convenient, since the request's previous input is available.
     return array_get($this->input, $this->transformKey($key), null);
 }
 public function register()
 {
     $this->app['app'] = $this->app;
     $this->app->shareDeferred('routes', function () {
         return new \Tiga\Framework\Router\Routes();
     });
     $this->app->shareDeferred('request', function () {
         return \Tiga\Framework\Request::createFromGlobals();
     });
     $this->app->shareDeferred('router', function () {
         return new \Tiga\Framework\Router\Router($this->app['routes'], $this->app['request'], $this->app, $this->app['view']);
     });
     $this->app->shareDeferred('view', function () {
         return new \Tiga\Framework\View\View($this->app['template']);
     });
     $this->app->shareDeferred('template', function () {
         $config['path'] = $this->app['config']->get('path.view');
         $config['storage'] = $this->app['config']->get('path.storage');
         return new \Tiga\Framework\Template\Template($config);
     });
     $this->app->shareDeferred('responseFactory', function () {
         return new \Tiga\Framework\Response\ResponseFactory();
     });
     $this->app->bind('db', function () {
         $connection = new \Tiga\Framework\Database\WPDBConnection();
         $queryCompiler = new \Tiga\Framework\Database\QueryCompiler($connection);
         return new \Tiga\Framework\Database\QueryBuilder($queryCompiler, $connection);
     });
     $this->app->shareDeferred('validator', function () {
         return new \Tiga\Framework\Validator();
     });
     $this->app->shareDeferred('pagination', function () {
         return new \Tiga\Framework\Pagination();
     });
 }
示例#3
0
 /**
  * Run the router, try to match current request path with registered route.
  */
 protected function dispatch()
 {
     $routeInfo = $this->dispatcher->dispatch($_SERVER['REQUEST_METHOD'], $this->currentURL);
     switch ($routeInfo[0]) {
         case Dispatcher::NOT_FOUND:
             // Continue to WordPress
             break;
         case Dispatcher::METHOD_NOT_ALLOWED:
             $allowedMethods = $routeInfo[1];
             // Sample : ... 405 Method Not Allowed
             break;
         case Dispatcher::FOUND:
             if ($this->app->get('whoops') !== null) {
                 $this->app->get('whoops')->init();
             }
             // Hook WordPress Template
             $this->view->hook();
             // Get route parameter
             $routeHandler = $routeInfo[1];
             $vars = $routeInfo[2];
             // Protected route, check the token
             if (in_array($this->request->getMethod(), $this->protectedRoute) || $this->request->isXmlHttpRequest()) {
                 $this->request->checkToken();
             }
             // Check if route is deffered
             if (!$routeHandler->isDeferred()) {
                 $this->sendResponse($routeHandler, $vars);
                 return;
             }
             // Share routeHandler and vars to App
             $this->app->share('routeHandler', $routeHandler);
             $this->app->share('routeHandlerVars', $vars);
             // Defered route callback
             add_action($routeHandler->getRunLevel(), function () {
                 $routeHandler = $this->app->get('routeHandler');
                 $vars = $this->app->get('routeHandlerVars');
                 $this->sendResponse($routeHandler, $vars);
             }, $routeHandler->getPriority());
             break;
     }
 }