Пример #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
 /**
  * Here we create a build definition (what to generate) based on the 
  * $allowCustomize flag. If a class needs to be able to customized then
  * we create a bass class and generate the code in the base class, 
  * and create derived class from the base class. Otherwise we create just 
  * one class and generate the code in that class.
  * @param type $allowCustomize
  * @return array
  */
 protected function createBuildDefinition($allowCustomize)
 {
     $className = $this->relation->getName(true) . $this->classNamePostfix;
     if ($allowCustomize) {
         $classes = array(array('className' => $className, 'classNamespace' => $this->rootNamespace, 'classBaseClass' => $className . 'Base', 'uses' => [$this->applicationNamespace . '\\' . $this->rootNamespace . '\\Base\\' . $className . ' as ' . $className . 'Base']), array('classModifier' => 'abstract', 'className' => $className, 'classNamespace' => $this->rootNamespace . '\\Base', 'classBaseClass' => $this->defaultBaseClassName, 'uses' => [$this->defaultBaseClassFQN], 'generate' => true));
     } else {
         $classes = array(array('className' => $className, 'classNamespace' => $this->rootNamespace, 'classBaseClass' => $this->defaultBaseClassName, 'uses' => [$this->defaultBaseClassFQN], 'generate' => true));
     }
     return $classes;
 }
Пример #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);
     }
 }