Exemplo n.º 1
0
 public function testConstructFromFactory()
 {
     $controller = ControllerFactory::create($this->app, 'Home', 'index', array('param1' => 'value'));
     $this->assertEquals('value', $controller->getParam('param1'));
     $this->assertEquals('index', $controller->getCurrentAction());
     $this->assertTrue(in_array(get_class($controller), array('Skully\\App\\Controllers\\HomeController', 'App\\Controllers\\HomeController')));
     //        $this->assertEquals('Skully\App\Controllers\HomeController', get_class($controller));
 }
Exemplo n.º 2
0
 /**
  * @param $controllerStr
  * @param null $actionStr
  * @param array $additionalParams
  * @return mixed|null|ControllerInterface
  */
 public function getController($controllerStr, $actionStr = null, $additionalParams = array())
 {
     $controller = null;
     if (!empty($this->controllers[$controllerStr])) {
         /* @var $controller ControllerInterface */
         $controller = $this->controllers[$controllerStr];
     } else {
         if (!$this->configIsEmpty('namespace')) {
             ControllerFactory::setConfig('namespace', $this->config('namespace'));
         }
         $controller = ControllerFactory::create($this, $controllerStr, $actionStr, $additionalParams);
         $this->controllers[$controllerStr] = $controller;
     }
     if (!empty($controller)) {
         $controller->resetParams();
         if (!empty($additionalParams)) {
             $controller->setParams($additionalParams);
         }
         if (!is_null($actionStr)) {
             $controller->setCurrentAction($actionStr);
         }
     }
     return $controller;
 }