/** * 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!"); } }
/** * 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); } }
/** * 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); }
/** * 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); } }