示例#1
0
 /**
  * Adds Relation to the list of relations in this Schema
  * @param Relation $relation
  * @throws InvalidSchemaException
  */
 public function addRelation(Relation $relation)
 {
     $name = $relation->getName();
     if (!isset($this->relations[$name])) {
         $this->relations[$name] = $relation;
     } else {
         throw new InvalidSchemaException("Relation {$name} already exists in {$this->getName()} schema!");
     }
 }
示例#2
0
 /**
  * Builds one or more classes based on the build definition
  * @param boolean $allowCustomize
  */
 public function build($allowCustomize)
 {
     $classes = $this->createBuildDefinition($allowCustomize);
     foreach ($classes as $def) {
         $targetFolder = $this->createTargetFolder($def);
         $targetFile = "{$targetFolder}/{$def['className']}.php";
         $def['appNamespace'] = $this->applicationNamespace;
         $def['classFQRN'] = $this->relation->getFQRN();
         render_php_template($this->template, $this->preparBuildDefinition($def), $targetFile, false);
     }
 }
示例#3
0
 /**
  * Check if the Relation needs to be customized later
  * @param Relation $relation
  * @return type
  */
 private function allowCustomize(Relation $relation)
 {
     $customizedModels = $this->config->getCustomizedRelationList();
     if (!is_array($customizedModels)) {
         $customizedModels = [];
     }
     return in_array($relation->getName(), $customizedModels) || in_array($relation->getFQRN(), $customizedModels);
 }
示例#4
0
 /**
  * Loads columns for a given relation
  * @param Relation $relation
  */
 protected function loadColumnsForRelation(Relation $relation)
 {
     $sql = new SelectStatement();
     $sql->from('information_schema.columns')->where(sqlstr('table_schema')->equalsTo(':table_schema'))->andWhere(sqlstr('table_name')->equalsTo(':table_name'));
     $params = [':table_schema' => $relation->getSchemaName(), ':table_name' => $relation->getName()];
     foreach ($this->database->executeQuery($sql, $params) as $record) {
         $column = new Column($record);
         $relation->addColumn($column);
     }
 }