FOF30\Factory\Magic\ModelFactory::make PHP Method

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
    public function make($name = null, array $config = array())
    {
        if (empty($name)) {
            throw new ModelNotFound($name);
        }
        $appConfig = $this->container->appConfig;
        $name = ucfirst($name);
        $defaultConfig = array('name' => $name, 'use_populate' => $appConfig->get("models.{$name}.config.use_populate"), 'ignore_request' => $appConfig->get("models.{$name}.config.ignore_request"), 'tableName' => $appConfig->get("models.{$name}.config.tbl"), 'idFieldName' => $appConfig->get("models.{$name}.config.tbl_key"), 'knownFields' => $appConfig->get("models.{$name}.config.knownFields", null), 'autoChecks' => $appConfig->get("models.{$name}.config.autoChecks"), 'contentType' => $appConfig->get("models.{$name}.config.contentType"), 'fieldsSkipChecks' => $appConfig->get("models.{$name}.config.fieldsSkipChecks", array()), 'aliasFields' => $appConfig->get("models.{$name}.field", array()), 'behaviours' => $appConfig->get("models.{$name}.behaviors", array()), 'fillable_fields' => $appConfig->get("models.{$name}.config.fillable_fields", array()), 'guarded_fields' => $appConfig->get("models.{$name}.config.guarded_fields", array()), 'relations' => $appConfig->get("models.{$name}.relations", array()));
        $config = array_merge($defaultConfig, $config);
        // Get the default class names
        $dataModelClassName = $this->container->getNamespacePrefix($this->getSection()) . 'Model\\DefaultDataModel';
        if (!class_exists($dataModelClassName, true)) {
            $dataModelClassName = '\\FOF30\\Model\\DataModel';
        }
        $treeModelClassName = $this->container->getNamespacePrefix($this->getSection()) . 'Model\\DefaultTreeModel';
        if (!class_exists($treeModelClassName, true)) {
            $treeModelClassName = '\\FOF30\\Model\\TreeModel';
        }
        try {
            // First try creating a TreeModel
            $model = new $treeModelClassName($this->container, $config);
        } catch (DataModel\Exception\TreeIncompatibleTable $e) {
            // If the table isn't a nested set, create a regular DataModel
            $model = new $dataModelClassName($this->container, $config);
        }
        return $model;
    }

Usage Example

Beispiel #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);
     }
 }
All Usage Examples Of FOF30\Factory\Magic\ModelFactory::make
ModelFactory