为一个 Module 追加 一个 Model 的基础前端路由配置
@param $moduleName
@param ModelDefinition $model
326037
public static function appendFrontEndRoutes($moduleName, ModelDefinition $model)
    {
        $moduleName = camel_case($moduleName);
        $newRouteFilePath = dirname(config('scaffold.templates.frontend.routes')[1]) . DIRECTORY_SEPARATOR . $moduleName . '.js';

        $variables = [
            'MODEL' => $model
        ];

        $newRouteContent = Utils::renderTemplate('scaffold::frontend.routes-model', $variables);
        Utils::replaceFilePlaceholders($newRouteFilePath, [
            "}
  // Append More Routes. Don't remove me" =>
                "},\n  " . $newRouteContent . "\n  // Append More Routes. Don't remove me"
        ], null, null);
    }
1319314
public function useModel($modelName)
    {
        $this->_controller->loadModel($modelName);
        list(, $this->_modelName) = pluginSplit($modelName);
    }
481453
public function setModel(Model $model)
    {
        $this->model = $model;
        $this->fm = $this->model->loadFunctionMap();
    }
1223527
public static function createTagFromModel(Model $model)
    {
        return new Tag((string) $model->id, $model->name, $model->row());
    }
530363
protected function populateDataInModule(string $moduleName) : void
    {
        if ('' === $moduleName) {
            return;
        }

        if (in_array($moduleName, $this->skipModules)) {
            return;
        }

        $module = $this->getCSVModuleAttr($moduleName);

        if (empty($module)) {
            return;
        }

        $table = TableRegistry::get($moduleName);

        for ($count = 0; $count < $this->numberOfRecords; $count++) {
            $entity = $table->newEntity();

            $data = [];
            foreach ($module as $fieldName => $fieldData) {
                if (empty($fieldData['type'])) {
                    continue;
                }

                if ($this->isCombinedField($fieldData['type'])) {
                    $fields = $this->getCombinedFieldValueBasedOnType($fieldData['type'], '', (string)$fieldName);
                    foreach ($fields as $field => $value) {
                        $data[$field] = $value;
                    }
                    continue;
                }

                $fieldValue = $this->getFieldValueBasedOnType($fieldData['type']);
                if (empty($fieldValue)) {
                    continue;
                }
                $data[$fieldName] = $fieldValue;
            }
            $entity = $table->patchEntity($entity, $data);
            if ($table->save($entity)) {
                $id = $entity->id;
            }
        }
        $this->modulesPolpulatedWithData[] = $moduleName;
        $this->out($moduleName);
    }
888799
public static function registerMetaDescription(Component $model)
    {
    	$modelSeoAttributeName = self::behavior($model)->descriptionAttribute;
    	self::registerSeoMetaTag($model, $modelSeoAttributeName, 'description');
    }
120578
public static function import(Model $model)
    {
        Utils\Utils::arrayPathSet(self::$models, self::getPath($model), $model);
    }
688198
protected function updateRegisteredModule($moduleName)
    {
        $module = $this->findOrFalse('module_name', $moduleName);
        $module->module_version = $this->def($moduleName, 'version');
        $module->module_is_updated = 1;
        $module->save();
    }
280498
public function modelFactory($modelName) {
        $modelClass = "\\Modules\\" . RouteController::$currentRoute['module'] . "\\Models\\" . $modelName;

        if (class_exists($modelClass)) {
            return new $modelClass(RouteController::$currentRoute);
        } elseif (class_exists("\\Base\\models\\" . $modelName)) {
            $baseModelClass = "\\Base\\models\\" . $modelName;
            return new $baseModelClass(RouteController::$currentRoute);
        } else {
            HookManager::call("handleModel", $modelName);
        }
    }
595525
public function applyToModel(Model $model)
    {
        if (! $this->onlyScopeRelations && ! is_null($this->scope)) {
            $model->scope = $this->scope;
        }

        return $model;
    }
1327210
public function setModel(Model $model)
    {
        if (($content = $this->getContent()) instanceof WithModelInterface) {
            $content->setModel($model);
        }

        return $this;
    }
766721
public function add(AbstractModel $model)
    {
        if (! $this->has($model)) {
            $this->addShallow($model);

            $modelLinks = $model->getRepo()->getLinkMap()->get($model);

            foreach ($modelLinks->getModels() as $linkedModel) {
                $this->add($linkedModel);
            }
        }

        return $this;
    }
1009798
public function isOperational($moduleName) {
    	if(!array_key_exists($moduleName, $this->modules_list)) {
    		if($module = fw\Module::getModuleByName($moduleName)) {
    			if($module instanceof DependentInterface) {
    				if($module->validatePrerequisites()) {
    					$this->modules_list[$moduleName] = TRUE;
    					return true;
    				} else {
    					// Do not cache the result,
    					// as they could change by the next call to the method
    					return false;
    				}
    			}
    			else {
    				$this->modules_list[$moduleName] = TRUE;
    				return true;
    			}
    		}
    		else {
    			$this->modules_list[$moduleName] = FALSE;
    		}
    	}
    	return $this->modules_list[$moduleName];
    	
    }
262330
protected function getModelNamespace($modelName, $modelDirectory)
    {
        if (!empty($modelDirectory)) {
            $modelDirectory = str_finish($modelDirectory, '\\');
        }

        $namespace = Helpers::getAppNamespace() . ltrim(Config::getModelsPath($modelDirectory . $modelName), '\\');

        return rtrim(Helpers::convertSlashToBackslash($namespace), '\\');
    }
1201351
public function createModel($model)
    {
        $schema = new Schema();

        $tableDef = $schema->createTable($model->getMeta()->getDbTable());
        // this assumes fields set_from_name has been invoked
        $primaryKeyFields = [];
        $unique_fields = [];
        $indexes = [];
        /** @var $field Field */
        /** @var $field ForeignKey */
        foreach ($model->getMeta()->localFields as $fname => $field) {
            $colName = $field->getColumnName();
            $type = $field->dbType($this->connection);
            // if we don't have a type skip
            if (empty($type)) {
                continue;
            }
            if ($field->primaryKey) {
                $primaryKeyFields[] = $model->getMeta()->primaryKey->getColumnName();
            } elseif ($field->isUnique()) {
                $unique_fields[] = $colName;
            } elseif ($field->dbIndex) {
                $indexes[] = $colName;
            }
            $tableDef->addColumn($colName, $type, $this->getDoctrineColumnOptions($field));
            if ($field->isRelation && $field->relation && $field->dbConstraint) {
                $relField = $field->getRelatedField();
                $tableDef->addForeignKeyConstraint(
                    $relField->scopeModel->getMeta()->getDbTable(),
                    [$field->getColumnName()],
                    [$relField->getColumnName()]
                );
            }
        }
        // create the primary key
        $tableDef->setPrimaryKey($primaryKeyFields);
        // add index constraint
        if (!empty($indexes)) {
            $tableDef->addIndex($indexes);
        }
        // add unique constraint
        if (!empty($unique_fields)) {
            $tableDef->addUniqueIndex($unique_fields);
        }
        $this->createTable($tableDef);
        // many to many
        /** @var $relationField ManyToManyField */
        foreach ($model->getMeta()->localManyToMany as $name => $relationField) {
            if ($relationField->manyToMany && $relationField->relation->through->getMeta()->autoCreated) {
                $this->createModel($relationField->relation->through);
            }
        }
    }
1110158
public static function moduleClass($moduleName = 'Module')
    {
        $result = false;

        $className = get_called_class();
        $refClass = new ReflectionClass($className);
        $ns = $refClass->getNamespaceName();

        $len = strlen($ns) - strlen(UniModule::$modelsSubdir);
        if (strrpos($ns, UniModule::$modelsSubdir) == $len) {
           $ns = substr($ns, 0, $len);
           $result = $ns . $moduleName;
        }

        return $result;
    }
1297930
public function getModuleModel()
    {
        if ($this->_moduleModel === null) {
            // 默认根据缓存的模块数据生成模块model
            $class = $this->module->moduleModelClass;
            $model = new $class;
            $class::populateRecord($model, ModuleModel::models()[$this->id]);
            $this->setModuleModel($model);
        }
        return $this->_moduleModel;
    }