make() public method

Create a new object instance
public make ( string $name = null, array $config = [] ) : TreeModel | DataModel
$name string The name of the class we're making
$config array The config parameters which override the fof.xml information
return FOF30\Model\TreeModel | FOF30\Model\DataModel A new TreeModel or DataModel object
Example #1
0
 /**
  * Create a new Model object
  *
  * @param   string  $viewName  The name of the view we're getting a Model for.
  * @param   array   $config    Optional MVC configuration values for the Model object.
  *
  * @return  Model
  */
 public function model($viewName, array $config = array())
 {
     try {
         return parent::model($viewName, $config);
     } catch (ModelNotFound $e) {
         $magic = new Magic\ModelFactory($this->container);
         return $magic->make($viewName, $config);
     }
 }
Example #2
0
 /**
  * Create a new Model object
  *
  * @param   string  $viewName  The name of the view we're getting a Model for.
  * @param   array   $config    Optional MVC configuration values for the Model object.
  *
  * @return  Model
  */
 public function model($viewName, array $config = array())
 {
     try {
         return parent::model($viewName, $config);
     } catch (ModelNotFound $e) {
         $magic = new Magic\ModelFactory($this->container);
         // Let's pass the section override (if any)
         $magic->setSection($this->getSection());
         return $magic->make($viewName, $config);
     }
 }
Example #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 model class
     $magic = new ModelFactory($this->container);
     $magic->setSection($this->getSection());
     $fofModel = $magic->make($viewName);
     /** @var ErectorInterface $erector */
     $erector = new ModelErector($this, $fofModel, $viewName);
     $erector->setSection($this->getSection());
     $erector->build();
     if (!class_exists($requestedClass)) {
         return false;
     }
     return true;
 }