Exemplo n.º 1
0
 /**
  * Execute the request
  *
  * @return  Request
  * @throws  \Exception
  * @throws  \DomainException
  *
  * @since  1.0.0
  */
 public function execute()
 {
     $this->factory->setActiveRequest($this);
     // log the request
     $this->log->info('Executing request');
     // get a route object for this request
     $this->route = $this->translate($this->request, $this->input->getMethod());
     // log the request destination
     $this->log->info($this->route->method . ' request routed to ' . (is_callable($this->route->translation) ? 'Closure' : $this->route->translation));
     // store the request parameters
     $this->params = array_merge($this->params, $this->route->parameters);
     // push any remaining segments so they'll be available as action arguments
     if (!empty($this->route->segments)) {
         $this->route->parameters = array_merge($this->route->parameters, $this->route->segments);
     }
     if (empty($this->route->controller)) {
         throw new NotFound('No route match has been found for this request.');
     }
     if (is_callable($this->route->controller)) {
         $controller = $this->route->controller;
     } else {
         $controller = $this->factory->createControllerInstance($this->route->controller);
     }
     if (!is_callable($controller)) {
         throw new NotFound('The Task returned by routing is not callable. Does it extend a base task?');
     }
     // push the route so we have access to it in the task
     array_unshift($this->route->parameters, $this->route);
     // add the root path to the config, lang and view manager objects
     if (isset($this->route->path)) {
         $this->app->getViewManager()->getFinder()->addPath($this->route->path);
         $this->config->addPath($this->route->path . 'config' . DS);
         $this->app->getLanguage()->addPath($this->route->path . 'lang' . DS . $this->config->get('lang.fallback', 'en') . DS);
     }
     try {
         $this->response = call_user_func($controller, $this->route->parameters);
     } catch (Exception\Base $e) {
         $this->response = $this->errorResponse($e);
     } catch (\Exception $e) {
         // log the request termination
         $this->log->info('Request executed, but failed: ' . $e->getMessage());
         // rethrow
         throw $e;
     }
     // remove the root path to the config, lang and view manager objects
     if (isset($this->route->path)) {
         $this->app->getLanguage()->removePath($this->route->path . 'lang' . DS . $this->config->get('lang.fallback', 'en') . DS);
         $this->config->removePath($this->route->path . 'config' . DS);
         $this->app->getViewManager()->getFinder()->removePath($this->route->path);
     }
     // log the request termination
     $this->log->info('Request executed');
     $this->factory->resetActiveRequest();
     return $this;
 }
Exemplo n.º 2
0
 public function testYaml()
 {
     $data = array('some' => 'value', 'arr' => array(1, 2, 3));
     $c = new Container();
     $c->setConfigFolder('');
     $c->set('j', $data);
     $c->addPath($this->base);
     $c->save('j', 'data.yml');
     $this->assertTrue(file_exists($this->base . '/data.yml'));
     $c->load('data.yml', 'new');
     $this->assertEquals($data, $c->get('new'));
     unlink($this->base . '/data.yml');
 }