Example #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;
 }
Example #2
0
 /**
  * Builds recipient header array
  *
  * @param Message $message
  *
  * @return []
  *
  * @since 2.0
  */
 protected function buildRecipients(Message $message)
 {
     $headers = [];
     foreach (array('to', 'cc', 'bcc') as $type) {
         $list = $this->buildAddressList($message->getRecipientsOfType($type));
         $header = ucfirst($type);
         // Default recipient headers
         // There should be a general way instead of this
         if ($default = $this->config->get('email.header.' . $header, false)) {
             $list .= ', ' . $default;
         }
         if (empty($list) === false) {
             $headers[$header] = $list;
         }
     }
     return $headers;
 }
Example #3
0
 /**
  * @expectedException \Exception
  */
 public function testInvalidSavePath()
 {
     $c = new Container();
     $c->set('data.data', true);
     $c->save('data');
 }