public function __construct($data, $parent) { parent::__construct($data, $parent); // iterate on foreign key configuration foreach($this->data->value as $key => $node){ $attributes = $node->attributes(); // read attributes $key = (string) $attributes['key']; // assign key $this->config[$key] = (string) $node[0]; // assign value } // follow references to tables foreach($this->data->link as $key => $node){ $attributes = $node->attributes(); // read attributes $key = (string) $attributes['key']; // assign key if($key == 'referencedTable'){ $referencedTableId = (string) $node; $this->referencedTable = \MwbExporter\Core\Registry::get($referencedTableId); } if($key == 'owner'){ $owningTableId = (string) $node; $this->owningTable = \MwbExporter\Core\Registry::get($owningTableId); $this->owningTable->injectRelation($this); } } //print_r($this->debug()); //die(); \MwbExporter\Core\Registry::set($this->id, $this); }
public function __construct($data, $parent) { parent::__construct($data, $parent); // collect tables foreach($this->data->xpath("value") as $key => $node){ $tmp = \MwbExporter\Core\Registry::get('formatter')->createTable($node, $this); if($tmp->isTranslationTable()){ // skip translation tables continue; } $this->tables[] = $tmp; } usort($this->tables, function($a, $b) { return strcmp($a->getModelName(), $b->getModelName()); }); /* * before you can check for foreign keys * you have to store at first all tables in the * object registry */ foreach($this->tables as $table){ $table->checkForIndices(); $table->checkForForeignKeys(); } \MwbExporter\Core\Registry::set($this->id, $this); }
public function display() { $return = array(); $relation_name = (strpos($this->config['name'],'d:') === 0)?substr($this->config['name'],2):$this->referencedTable->getModelName(); $return[] = ' ' . $relation_name . ':'; $return[] = ' class: ' . $this->referencedTable->getModelName(); $ownerColumn = $this->data->xpath("value[@key='columns']"); $return[] = ' local: ' . \MwbExporter\Core\Registry::get((string) $ownerColumn[0]->link)->getColumnName(); $referencedColumn = $this->data->xpath("value[@key='referencedColumns']"); $return[] = ' foreign: ' . \MwbExporter\Core\Registry::get((string) $referencedColumn[0]->link)->getColumnName(); $foreignAlias = trim($this->getForeignAlias()); if (!empty($foreignAlias)) { $return[] = ' foreignAlias: ' . $foreignAlias; } else { if((int)$this->config['many'] === 1){ $return[] = ' foreignAlias: ' . \MwbExporter\Helper\Pluralizer::pluralize($this->owningTable->getModelName()); } else { $return[] = ' foreignAlias: ' . $this->owningTable->getModelName(); } } $return[] = ' onDelete: ' . strtolower($this->config['deleteRule']); $return[] = ' onUpdate: ' . strtolower($this->config['updateRule']); return implode("\n", $return); }
/** * Return the foreign key definition * Yaml format * * @return string */ public function display() { $return = array(); /** * sometimes the link between to tables is broken */ if($this->referencedTable == null){ return $this->indentation(2) . '# There is another foreign key declaration but it seems broken.'; } $return[] = $this->indentation(2) . $this->referencedTable->getModelName() . ':'; $return[] = $this->indentation(3) . 'class: ' . $this->referencedTable->getModelName(); $ownerColumn = $this->data->xpath("value[@key='columns']"); $return[] = $this->indentation(3) . 'local: ' . \MwbExporter\Core\Registry::get((string) $ownerColumn[0]->link)->getColumnName(); $referencedColumn = $this->data->xpath("value[@key='referencedColumns']"); $return[] = $this->indentation(3) . 'foreign: ' . \MwbExporter\Core\Registry::get((string) $referencedColumn[0]->link)->getColumnName(); if((int)$this->config['many'] === 1){ $return[] = $this->indentation(3) . 'foreignAlias: ' . \MwbExporter\Helper\Pluralizer::pluralize($this->owningTable->getModelName()); } else { $return[] = $this->indentation(3) . 'foreignAlias: ' . $this->owningTable->getModelName(); } $return[] = $this->indentation(3) . 'onDelete: ' . strtolower($this->config['deleteRule']); $return[] = $this->indentation(3) . 'onUpdate: ' . strtolower($this->config['updateRule']); return implode("\n", $return); }
public function display() { $return = array(); // add model name $return[] = $this->getModelName() . ':'; // add behaviours if($actAs = $this->checkActAsBehaviour()){ $return[] = ' ' . trim($actAs); } // check if schema name has to be included $config = \MwbExporter\Core\Registry::get('config'); if(isset($config['extendTableNameWithSchemaName']) && $config['extendTableNameWithSchemaName']){ // $schemaname = table->tables->schema->getName() $schemaName = $this->getParent()->getParent()->getName(); $return[] = ' tableName: ' . $schemaName . '.' . $this->getRawTableName(); } else { // add table name if necessary if($this->getModelName() !== ucfirst($this->getRawTableName())){ $return[] = ' tableName: ' . $this->getRawTableName(); } } $return[] = $this->columns->display(); // add relations if(count($this->relations) > 0 or $this->hasExternalRelations()){ $return[] = ' relations:'; foreach($this->relations as $relation){ $return[] = $relation->display(); } if ($this->hasExternalRelations()) { $return[] = ' ' . $this->getExternalRelations(); } } // add indices if(count($this->indexes) > 0){ $return[] = ' indexes:'; foreach($this->indexes as $index){ $return[] = $index->display(); } } $return[] = ' options:'; $return[] = ' charset: ' . (($this->config['defaultCharacterSetName'] == "") ? 'utf8' : $this->config['defaultCharacterSetName']); $return[] = ' type: ' . $this->config['tableEngine']; // add empty line behind table $return[] = ''; return implode("\n", $return); }
/** * * @param type $data * @param type $parent */ public function __construct($data, $parent) { parent::__construct($data, $parent); $tmp = $this->data->xpath("value[@key='schemata']"); $this->schemas = \MwbExporter\Core\Registry::get('formatter')->createSchemas($tmp[0], $this); \MwbExporter\Core\Registry::set($this->id, $this); }
public function __construct($data, $parent) { parent::__construct($data, $parent); foreach($data->value as $key => $node){ $this->foreignKeys[] = \MwbExporter\Core\Registry::get('formatter')->createForeignKey($node, $this); } \MwbExporter\Core\Registry::set($this->id, $this); }
public function __construct($data, $parent) { parent::__construct($data, $parent); foreach($this->data->xpath("value") as $key => $node){ $this->schemas[] = \MwbExporter\Core\Registry::get('formatter')->createSchema($node, $this); } \MwbExporter\Core\Registry::set($this->id, $this); }
public function __construct($data, $parent) { parent::__construct($data, $parent); foreach($this->data as $key => $node){ $this->columns[] = \MwbExporter\Core\Registry::get('formatter')->createColumn($node, $this); } \MwbExporter\Core\Registry::set($this->id, $this); }
public function __construct($data, $parent) { parent::__construct($data, $parent); // iterate on views foreach($data->value as $key => $node){ $this->views[] = \MwbExporter\Core\Registry::get('formatter')->createView($node, $this); } \MwbExporter\Core\Registry::set($this->id, $this); }
public function __construct($data, $parent) { parent::__construct($data, $parent); $tmp = $this->data->xpath("value[@key='name']"); $this->name = (string) $tmp[0]; $tmp = $this->data->xpath("value[@key='tables']"); $this->tables = \MwbExporter\Core\Registry::get('formatter')->createTables($tmp[0], $this); $tmp = $this->data->xpath("value[@key='views']"); $this->views = \MwbExporter\Core\Registry::get('formatter')->createViews($tmp[0], $this); \MwbExporter\Core\Registry::set($this->id, $this); }
public function __construct($savePath) { $this->config = \MwbExporter\Core\Registry::get('config'); $this->savePath = realpath($savePath); $this->fileName = date('Y-m-d_h-i-s') . '_' . sprintf('%03d', mt_rand(1,999)) . '.zip'; $this->filePath = $this->savePath . DIRECTORY_SEPARATOR . $this->fileName; $this->zip = new \ZipArchive(); $res = $this->zip->open($this->filePath, \ZipArchive::CREATE); if($res !== true){ throw new \Exception('error while creating zip in file ' . __FILE__ . ' on line ' . __LINE__); } }
public function __construct($data, $parent) { parent::__construct($data, $parent); $tmp = $this->data->xpath("value[@key='columns']"); $this->columns = \MwbExporter\Core\Registry::get('formatter')->createColumns($tmp[0], $this); // iterate on column configuration foreach($this->data->value as $key => $node){ $attributes = $node->attributes(); // read attributes $key = (string) $attributes['key']; // assign key $this->config[$key] = (string) $node[0]; // assign value } \MwbExporter\Core\Registry::set($this->id, $this); }
/** * * @return string */ public function display() { $config = \MwbExporter\Core\Registry::get('config'); $return = array(); $return[] = '<?php'; $return[] = ''; $return[] = '/**'; $return[] = ' * '; $return[] = ' */'; /* FIXME: [Zend] Table name is one time in singular form, one time in plural form. * All table occurence need to be at the original form. * * $this->getModelName() return singular form with correct camel case * $this->getRawTableName() return original form with no camel case */ $return[] = 'class ' . $this->tablePrefix . $this->getSchemaName() .'_'. $this->getModelName() . ' extends ' . $this->parentTable; $return[] = '{'; $return[] = $this->indentation(1) .'/* @var string $_schema */'; $return[] = $this->indentation(1) .'protected $_schema = \''. $this->getSchemaName() .'\';'; $return[] = ''; $return[] = $this->indentation(1) .'/* @var string $_name */'; $return[] = $this->indentation(1) .'protected $_name = \''. $this->getRawTableName() .'\';'; $return[] = ''; if (true === $config['generateDRI']) { $return[] = $this->displayDependencies(); } $return[] = $this->displayReferences(); $return[] = ''; $return[] = '}'; $return[] = '?>'; $return[] = ''; $return[] = ''; return implode("\n", $return); }
public function __construct($data, $parent) { parent::__construct($data, $parent); //iterate on column configuration foreach($this->data->value as $key => $node){ $attributes = $node->attributes(); // read attributes $key = (string) $attributes['key']; // assign key $this->config[$key] = (string) $node[0]; // assign value } // iterate on links to other wb objects foreach($this->data->link as $key => $node){ $attributes = $node->attributes(); $key = (string) $attributes['key']; } $isPrimary = false; // check for primary columns, to notify column $nodes = $this->data->xpath("value[@key='columns']/value/link[@key='referencedColumn']"); if(is_array($nodes)){ foreach($nodes as $node){ // for primary indexes ignore external index // definition and set column to primary instead if($this->config['name'] == 'PRIMARY'){ $isPrimary = true; \MwbExporter\Core\Registry::get((string) $node)->markAsPrimary(); } else { if($this->config['indexType'] == 'UNIQUE'){ \MwbExporter\Core\Registry::get((string) $node)->markAsUnique(); } $this->referencedColumn[] = \MwbExporter\Core\Registry::get((string) $node); } } } if($isPrimary) { return; } \MwbExporter\Core\Registry::get((string)$this->data->link)->injectIndex($this); \MwbExporter\Core\Registry::set($this->id, $this); }
/** * Return the column definition * Yaml format * * @return string */ public function display() { $return = array(); // set name of column $return[] = $this->indentation(2) . $this->config['name'] . ':'; // set datatype of column $return[] = $this->indentation(3) . 'type: ' . \MwbExporter\Core\Registry::get('formatter')->useDatatypeConverter((isset($this->link['simpleType']) ? $this->link['simpleType'] : $this->link['userType']), $this); // check if the column is a primary key if($this->isPrimary){ $return[] = $this->indentation(3) . 'primary: true'; } // check for not null column if(isset($this->config['isNotNull']) && $this->config['isNotNull'] == 1){ $return[] = $this->indentation(3) . 'notnull: true'; } // check for auto increment column if(isset($this->config['autoIncrement']) && $this->config['autoIncrement'] == 1){ $return[] = $this->indentation(3) . 'generator:'; $return[] = $this->indentation(4) . 'strategy: AUTO'; } // set default value if(isset($this->config['defaultValue']) && $this->config['defaultValue'] != '' && $this->config['defaultValue'] != 'NULL'){ $return[] = $this->indentation(3) . 'default: ' . $this->config['defaultValue']; } // iterate on column flags foreach($this->data->xpath("value[@key='flags']/value") as $flag){ $return[] = $this->indentation(3) . strtolower($flag) . ': true'; } // return yaml representation of column return implode("\n", $return); }
/** * * @param SimpleXMLElement $data * @param type $parent */ public function __construct($data, $parent) { parent::__construct($data, $parent); $referencedColumn = $this->data->xpath("value[@key='referencedColumns']"); $local = \MwbExporter\Core\Registry::get((string) $referencedColumn[0]->link); $ownerColumn = $this->data->xpath("value[@key='columns']"); $foreign = \MwbExporter\Core\Registry::get((string) $ownerColumn[0]->link); $this->local = $local; // local column object $this->foreign = $foreign; // foreign column object // for doctrine2 annotations switch the local and the foreign // reference for a proper output $local->markAsForeignReference($this); $foreign->markAsLocalReference($this); // many to many if($fk = $this->getOwningTable()->getForeignKeys()){ // only two or more foreign keys implicate an m2m relation // of the current table if(count($fk) > 1){ foreach($fk as $foreignKey1){ foreach($fk as $foreignKey2){ if($foreignKey1->getReferencedTable()->getId() != $foreignKey2->getReferencedTable()->getId()){ $foreignKey1->getReferencedTable()->setManyToManyRelation( array( 'reference' => $this, 'refTable' => $foreignKey2->getReferencedTable() ) ); } } } } } }
/** * Returns object by MySQL Workbench object ID * * @param string $id * @return object */ protected function getElementById($id) { return \MwbExporter\Core\Registry::get($id); }
/** * Return the table definition * Annotation format * * @return string */ public function display() { $config = \MwbExporter\Core\Registry::get('config'); $this->ormPrefix = '@' . ((isset($config['useAnnotationPrefix']) && $config['useAnnotationPrefix']) ? $config['useAnnotationPrefix'] : ''); // add relations if(count($this->relations) > 0){ foreach($this->relations as $relation){ $relation->display(); } } // add indices if(count($this->indexes) > 0){ foreach($this->indexes as $index){ $index->display(); } } $return = array(); $return[] = '<?php'; $return[] = ''; $namespace = ''; $repositoryNamespace = ''; if(isset($config['bundleNamespace']) && $config['bundleNamespace']){ $namespace = $config['bundleNamespace'] . '\\'; } if(isset($config['entityNamespace']) && $config['entityNamespace']){ $namespace .= $config['entityNamespace']; } else { $namespace .= 'Entity'; } if(isset($config['repositoryNamespace']) && $config['repositoryNamespace']){ $repositoryNamespace = $config['repositoryNamespace'] . '\\'; } $return[] = sprintf('namespace %s;', $namespace); $return[] = ''; // Dirty fix, only in one case we need a use statement if($this->ormPrefix == '@ORM\\'){ $return[] = 'use Doctrine\ORM\Mapping as ORM;'; $return[] = ''; } $return[] = '/**'; $entity = ' * ' . $this->ormPrefix . 'Entity'; if(isset($config['useAutomaticRepository']) && $config['useAutomaticRepository']){ $entity .= '(repositoryClass="' . $repositoryNamespace . $this->getModelName() . 'Repository")'; } $return[] = $entity; $tmp = ' * ' . $this->ormPrefix . 'Table(name="' . $this->getRawTableName() . '"'; if(count($this->indexes) > 0){ $tmp .= ',indexes={'; foreach($this->indexes as $index){ $tmp .= $this->ormPrefix . 'index(' . $index->display() . '),'; } $tmp = substr($tmp, 0, -1); $tmp .= '}'; } $return[] = $tmp . ')'; $return[] = ' */'; $return[] = 'class ' . $this->getModelName(); $return[] = '{'; $return[] = $this->columns->display(); $return[] = $this->displayManyToMany(); $return[] = $this->displayConstructor(); $return[] = ''; $return[] = $this->columns->displayGetterAndSetter(); $return[] = $this->displayManyToManyGetterAndSetter(); $return[] = '}'; $return[] = ''; return implode("\n", $return); }
/** * Return the column definition * Annotation format * * @return string */ public function display() { $return = array(); $config = \MwbExporter\Core\Registry::get('config'); /** * if needed, use a prefix (like @ORM\ or @orm: * for symfony2 * @ by default */ $this->ormPrefix = '@' . ((isset($config['useAnnotationPrefix']) && $config['useAnnotationPrefix']) ? $config['useAnnotationPrefix'] : ''); // do not include columns that reflect references if(is_null($this->local)) { // generate private $<column> class vars $return[] = $this->indentation() . '/** '; /** * checking if the current column is a primary key */ $tmp = $this->indentation() . ' * '; if($this->isPrimary){ $tmp .= $this->ormPrefix . 'Id '; } $return[] = $tmp; // set name of column $tmp = $this->indentation() . ' * '; $tmp .= $this->ormPrefix . 'Column(type=' . \MwbExporter\Core\Registry::get('formatter')->useDatatypeConverter((isset($this->link['simpleType']) ? $this->link['simpleType'] : $this->link['userType']), $this); if(!isset($this->config['isNotNull']) || $this->config['isNotNull'] != 1){ $tmp .= ',nullable=true'; } $tmp .= ')'; // column definition ending bracket $return[] = $tmp; /** * adding the auto increment statement */ if(isset($this->config['autoIncrement']) && $this->config['autoIncrement'] == 1){ $return[] = $this->indentation() . ' * ' . $this->ormPrefix . 'GeneratedValue(strategy="AUTO")'; } $return[] = $this->indentation() . ' */'; $return[] = $this->indentation() . 'private $' . $this->config['name'] . ';'; $return[] = ''; } // one to many references if(is_array($this->foreigns)){ foreach($this->foreigns as $foreign){ $return[] = $this->indentation() . '/**'; $return[] = $this->indentation() . ' * ' . $this->ormPrefix . 'OneToMany(targetEntity="' . $foreign->getOwningTable()->getModelName() . '", mappedBy="' . $foreign->getReferencedTable()->getModelName() . '")'; $return[] = $this->indentation() . ' */'; $return[] = $this->indentation() . 'private $' . lcfirst(\MwbExporter\Helper\Pluralizer::pluralize($foreign->getOwningTable()->getModelName())) . ';'; $return[] = ''; } } // many to references if(!is_null($this->local)){ $return[] = $this->indentation() . '/**'; $return[] = $this->indentation() . ' * ' . $this->ormPrefix . 'ManyToOne(targetEntity="' . $this->local->getReferencedTable()->getModelName() . '", inversedBy="' . $this->local->getOwningTable()->getModelName() . '")'; $return[] = $this->indentation() . ' */'; $return[] = $this->indentation() . 'private $' . lcfirst($this->local->getReferencedTable()->getModelName()) . ';'; $return[] = ''; } /* // set default value if(isset($this->config['defaultValue']) && $this->config['defaultValue'] != '' && $this->config['defaultValue'] != 'NULL'){ $return[] = $this->indentation() . ' default: ' . $this->config['defaultValue']; } // iterate on column flags foreach($this->data->xpath("value[@key='flags']/value") as $flag){ $return[] = $this->indentation() . ' ' . strtolower($flag) . ': true'; } */ // return yaml representation of column return implode("\n", $return); }
/** * */ public function checkForForeignKeys() { foreach($this->data->xpath("value[@key='foreignKeys']") as $key => $node){ $this->foreignKeys = \MwbExporter\Core\Registry::get('formatter')->createForeignKeys($node, $this); } }
/** * return the table definition * Yaml format * * @return string the table definition */ public function display() { $config = \MwbExporter\Core\Registry::get('config'); $return = array(); /** * formatting the entity's namespace */ $return[] = sprintf('%s\\%s\\%s:', (isset($config['bundleNamespace']) && $config['bundleNamespace']) ? $config['bundleNamespace'] : '', (isset($config['entityNamespace']) && $config['entityNamespace']) ? $config['entityNamespace'] : 'Entity', $this->getModelName() ); /** * formatting repository's Namespace */ $repositoryNamespace = ''; if(isset($config['repositoryNamespace']) && $config['repositoryNamespace']){ $repositoryNamespace = $config['repositoryNamespace'] . '\\'; } $return[] = $this->indentation() . 'type: entity'; /** * Adding the repository class if necessary */ if(isset($config['useAutomaticRepository']) && $config['useAutomaticRepository']){ $return[] = $this->indentation() . 'repositoryClass: '.$repositoryNamespace . $this->getModelName() . 'Repository'; } // check if schema name has to be included if(isset($config['extendTableNameWithSchemaName']) && $config['extendTableNameWithSchemaName']){ // $schemaname = table->tables->schema->getName() $schemaName = $this->getParent()->getParent()->getName(); $return[] = $this->indentation(1) . 'table: ' . $schemaName . '.' . $this->getRawTableName(); } else { // add table name if necessary if($this->getModelName() !== ucfirst($this->getRawTableName())){ $return[] = $this->indentation(1) . 'table: ' . $this->getRawTableName(); } } $return[] = $this->columns->display(); // add relations if(count($this->relations) > 0){ $return[] = $this->indentation() . 'relations:'; foreach($this->relations as $relation){ $return[] = $relation->display(); } } // add indices if(count($this->indexes) > 0){ $return[] = $this->indentation() . 'indexes:'; foreach($this->indexes as $index){ $return[] = $index->display(); } } $return[] = $this->indentation(1) . 'options:'; $return[] = $this->indentation(2) . 'charset: ' . $this->config['defaultCharacterSetName']; $return[] = $this->indentation(2) . 'type: ' . $this->config['tableEngine']; // add empty line behind table $return[] = ''; return implode("\n", $return); }