Example #1
0
 /**
  * Invoke control action
  *
  * @return $this
  * @throws \ErrorException
  */
 protected function invokeControl()
 {
     if ($this->route === null) {
         throw new \ErrorException("Control cannot be created until route is not dispatched.");
     }
     $parts = explode('/', $this->route->getControl());
     foreach ($parts as $key => $part) {
         $parts[$key] = ucfirst($part);
     }
     $control = implode('\\', $parts);
     $class = ucfirst($this->route->getModule()) . '\\Control\\' . $control . 'Control';
     if (!class_exists($class)) {
         throw new \ErrorException(sprintf("Control '%s' could not be loaded. Check paths and autoloader configuration", $class));
     }
     $control = new $class($this->app);
     $this->addData($this->invokeMethod($control, static::BEFORE, false));
     $this->addData($this->invokeMethod($control, $this->getControlMethod(), true));
     $this->addData($this->invokeMethod($control, static::AFTER, false));
     $this->control = $control;
     return $this;
 }