/** * Instantiate a controller from the component scope * * @final * @access public * @param string $ControllerName * @param string $Method * @param array $Context * @uses Component::GetDirectory * @uses ObjectBuilder::CreateController * @return mixed */ public final function Controller(string $ControllerName, string $Method, array $Context = []) { /* ------------------------------------------------------------------------------------------------------ EXECUTE ------------------------------------------------------------------------------------------------------ */ $Controller = $this->ObjectBuilder->CreateController($this->GetDirectory(), $ControllerName, ['Method' => $Method]); /* ------------------------------------------------------------------------------------------------------ TEST CONTROLLER ------------------------------------------------------------------------------------------------------ */ // We need to make sure the controller has the requested method if (!method_exists($Controller, $Method)) { throw new ComponentException(sprintf('Method %s not found in controller %s', $Method, $ControllerName)); } /* ------------------------------------------------------------------------------------------------------ CREATE ------------------------------------------------------------------------------------------------------ */ return $Controller->{$Method}((new \Bytes\GlobalScope())->SetRoute(isset($Context['Route']) ? (string) $Context['Route'] : ''), isset($Context['ErrorHandler']) ? $Context['Exception'] : Null, isset($Context['ErrorHandler']) ? $this->__InjectionContainer->Retrieve('Environment') : Null, isset($Context['ErrorHandler']) ? $this->__InjectionContainer->Retrieve('Header') : Null); }