make() public method

Create a new object instance
public make ( string $name = null, array $config = [] ) : DataController
$name string The name of the class we're making
$config array The config parameters which override the fof.xml information
return FOF30\Controller\DataController A new DataController object
Esempio n. 1
0
 /**
  * Create a new Controller object
  *
  * @param   string  $viewName  The name of the view we're getting a Controller for.
  * @param   array   $config    Optional MVC configuration values for the Controller object.
  *
  * @return  Controller
  */
 public function controller($viewName, array $config = array())
 {
     try {
         return parent::controller($viewName, $config);
     } catch (ControllerNotFound $e) {
         $magic = new Magic\ControllerFactory($this->container);
         return $magic->make($viewName, $config);
     }
 }
Esempio n. 2
0
 /**
  * Create a new Controller object
  *
  * @param   string  $viewName  The name of the view we're getting a Controller for.
  * @param   array   $config    Optional MVC configuration values for the Controller object.
  *
  * @return  Controller
  */
 public function controller($viewName, array $config = array())
 {
     try {
         return parent::controller($viewName, $config);
     } catch (ControllerNotFound $e) {
         $magic = new Magic\ControllerFactory($this->container);
         // Let's pass the section override (if any)
         $magic->setSection($this->getSection());
         return $magic->make($viewName, $config);
     }
 }
Esempio n. 3
0
 /**
  * Make a new scaffolding document
  *
  * @param   string  $requestedClass     The requested class, with full qualifier ie Myapp\Site\Controller\Foobar
  * @param   string  $viewName           The name of the view linked to this controller
  *
  * @return  bool    True on success, false otherwise
  */
 public function make($requestedClass, $viewName)
 {
     // Class already exists? Stop here
     if (class_exists($requestedClass)) {
         return true;
     }
     // I have to magically create the controller class
     $magic = new ControllerFactory($this->container);
     $magic->setSection($this->getSection());
     $fofController = $magic->make($viewName);
     /** @var ErectorInterface $erector */
     $erector = new ControllerErector($this, $fofController, $viewName);
     $erector->setSection($this->getSection());
     $erector->build();
     if (!class_exists($requestedClass)) {
         return false;
     }
     return true;
 }
Esempio n. 4
0
 /**
  * @covers          FOF30\Factory\Magic\ControllerFactory::make
  * @dataProvider    ControllerFactoryDataprovider::getTestMake
  */
 public function testMake($test, $check)
 {
     $msg = 'ControllerFactory::make %s - Case: ' . $check['case'];
     $config['componentName'] = $test['component'];
     if ($test['backend_path']) {
         $config['backEndPath'] = $test['backend_path'];
     }
     $container = new TestContainer($config);
     // Required so we force FOF to read the fof.xml file
     $dummy = $container->appConfig;
     $factory = new ControllerFactory($container);
     if ($check['exception']) {
         $this->setExpectedException('FOF30\\Factory\\Exception\\ControllerNotFound');
     }
     $result = $factory->make($test['name'], $test['config']);
     $this->assertEquals($check['result'], get_class($result), sprintf($msg, 'Returned the wrong result'));
     $this->assertEquals($check['autoRouting'], ReflectionHelper::getValue($result, 'autoRouting'), sprintf($msg, 'Failed to set the autorouting'));
     $this->assertEquals($check['csrf'], ReflectionHelper::getValue($result, 'csrfProtection'), sprintf($msg, 'Failed to set the csrfProtection'));
     $this->assertEquals($check['view'], ReflectionHelper::getValue($result, 'viewName'), sprintf($msg, 'Failed to set the viewName'));
     $this->assertEquals($check['model'], ReflectionHelper::getValue($result, 'modelName'), sprintf($msg, 'Failed to set the modelName'));
     $this->assertEquals($check['priv'], ReflectionHelper::getValue($result, 'taskPrivileges'), sprintf($msg, 'Failed to set the taskPrivileges'));
     $this->assertEquals($check['cache'], ReflectionHelper::getValue($result, 'cacheableTasks'), sprintf($msg, 'Failed to set the cacheableTasks'));
     $this->assertEquals($check['taskMap'], ReflectionHelper::getValue($result, 'taskMap'), sprintf($msg, 'Failed to set the taskMap'));
 }