Exemple #1
0
 public function build()
 {
     $options = $this->_options;
     $path = '';
     if (isset($this->_options['directory'])) {
         if ($this->_options['directory']) {
             $path = $this->_options['directory'] . '/';
         }
     }
     $name = $options['name'];
     $config = $this->_getConfig($path);
     if (!isset($config->database->adapter)) {
         throw new BuilderException("Adapter was not found in the config. Please specify a config varaible [database][adapter]");
     }
     $adapter = ucfirst($config->database->adapter);
     $this->isSupportedAdapter($adapter);
     $di = new FactoryDefault();
     $di->set('db', function () use($adapter, $config) {
         if (isset($config->database->adapter)) {
             $adapter = $config->database->adapter;
         } else {
             $adapter = 'Mysql';
         }
         if (is_object($config->database)) {
             $configArray = $config->database->toArray();
         } else {
             $configArray = $config->database;
         }
         $adapterName = 'Phalcon\\Db\\Adapter\\Pdo\\' . $adapter;
         unset($configArray['adapter']);
         return new $adapterName($configArray);
     });
     if (isset($config->application->modelsDir)) {
         $options['modelsDir'] = $path . $config->application->modelsDir;
     } else {
         throw new BuilderException("The builder is unable to know where is the views directory");
     }
     if (isset($config->application->controllersDir)) {
         $options['controllersDir'] = $path . $config->application->controllersDir;
     } else {
         throw new BuilderException("The builder is unable to know where is the controllers directory");
     }
     if (isset($config->application->viewsDir)) {
         $options['viewsDir'] = $path . $config->application->viewsDir;
     } else {
         throw new BuilderException("The builder is unable to know where is the views directory");
     }
     if (isset($config->application->gridsDir)) {
         $options['gridsDir'] = $path . $config->application->gridsDir;
     } else {
         throw new BuilderException("The builder is unable to know where is the grids directory");
     }
     if (isset($config->application->formsDir)) {
         $options['formsDir'] = $path . $config->application->formsDir;
     } else {
         throw new BuilderException("The builder is unable to know where is the forms directory");
     }
     $options['manager'] = $di->getShared('modelsManager');
     $options['className'] = Text::camelize($options['name']);
     $options['fileName'] = Text::uncamelize($options['className']);
     $modelClass = Text::camelize($name);
     $modelPath = $config->application->modelsDir . '/' . $modelClass . '.php';
     if (!file_exists($modelPath)) {
         $modelBuilder = new ModelBuilder(array('name' => $name, 'schema' => $options['schema'], 'className' => $options['className'], 'fileName' => $options['fileName'], 'genSettersGetters' => $options['genSettersGetters'], 'directory' => $options['directory'], 'force' => $options['force']));
         $modelBuilder->build();
     }
     if (!class_exists($modelClass)) {
         require $modelPath;
     }
     $entity = new $modelClass();
     $metaData = $di['modelsMetadata'];
     $attributes = $metaData->getAttributes($entity);
     $dataTypes = $metaData->getDataTypes($entity);
     $identityField = $metaData->getIdentityField($entity);
     $primaryKeys = $metaData->getPrimaryKeyAttributes($entity);
     $setParams = [];
     $selectDefinition = [];
     $relationField = '';
     $single = $name;
     $options['name'] = strtolower(Text::camelize($single));
     $options['plural'] = $this->_getPossiblePlural($name);
     $options['singular'] = $this->_getPossibleSingular($name);
     $options['entity'] = $entity;
     $options['setParams'] = $setParams;
     $options['attributes'] = $attributes;
     $options['dataTypes'] = $dataTypes;
     $options['primaryKeys'] = $primaryKeys;
     $options['identityField'] = $identityField;
     $options['relationField'] = $relationField;
     $options['selectDefinition'] = $selectDefinition;
     $options['autocompleteFields'] = [];
     $options['belongsToDefinitions'] = [];
     //Build Controller
     $this->_makeController($path, $options);
     if (isset($options['templateEngine']) && $options['templateEngine'] == 'volt') {
         //View layouts
         $this->_makeLayoutsVolt($path, $options);
         //View index.phtml
         $this->_makeViewIndexVolt($path, $options);
         //View search.phtml
         $this->_makeViewSearchVolt($path, $options);
         //View new.phtml
         $this->_makeViewNewVolt($path, $options);
         //View edit.phtml
         $this->_makeViewEditVolt($path, $options);
     } else {
         //View layouts
         $this->_makeLayouts($path, $options);
         //View index.phtml
         $this->_makeViewIndex($path, $options);
         //View search.phtml
         $this->_makeViewSearch($path, $options);
         //View new.phtml
         $this->_makeViewNew($path, $options);
         //View edit.phtml
         $this->_makeViewEdit($path, $options);
     }
     return true;
 }
Exemple #2
0
<?php

require 'loader.php';
use Engine\Builder\Model as ModelBuilder;
use Engine\Builder\Script\Color;
print Color::head('Start creating models') . PHP_EOL;
$ModelBuilder = new ModelBuilder(['table_name' => 'front_category']);
$ModelBuilder->build();
$ModelBuilder = new ModelBuilder(['table_name' => 'front_product_type']);
$ModelBuilder->build();
$ModelBuilder = new ModelBuilder(['table_name' => 'front_product']);
$ModelBuilder->build();