Example #1
0
 public function __construct(Table $table, Cluster $cluster, $outputFilename = null, array $options = array())
 {
     if (!empty($options)) {
         $this->setOptions($options);
     }
     Log::info('Generate part mode ' . $table->getName());
     $this->_table = $table;
     $file = new FileGenerator();
     $this->setFile($file);
     $file->setNamespace('Model');
     $class = new ClassGenerator();
     $file->setClass($class);
     $file->addUse('Model\\Result\\Result');
     $file->addUse('Model\\Entity\\' . $table->getNameAsCamelCase() . 'Entity');
     $file->addUse('Model\\Cond\\' . $table->getNameAsCamelCase() . 'Cond', 'Cond');
     $file->addUse('Model\\Cond\\AbstractCond');
     $file->addUse('Model\\Collection\\' . $table->getNameAsCamelCase() . 'Collection');
     $this->_runPlugins(self::PART_MODEL, self::RUNTIME_PRE);
     $class->setName('Abstract' . $table->getNameAsCamelCase() . 'Model');
     if ($table->isTree() && $this->hasPlugin('Tree', AbstractPart::PART_MODEL)) {
         $class->setExtendedClass('\\Model\\Mysql\\TreeModel');
     } else {
         $class->setExtendedClass('\\Model\\Mysql\\AbstractModel');
     }
     $class->setAbstract(true);
     $this->_runPlugins(self::PART_MODEL, self::RUNTIME_POST);
     if ($outputFilename) {
         file_put_contents($outputFilename, $file->generate());
     }
 }
Example #2
0
 public function __construct(Table $table, Schema $cluster, $outputFilename = null)
 {
     Log::info('Generate part entity ' . $table->getName());
     $this->_table = $table;
     $file = new \Model\Code\Generator\FileGenerator();
     $class = new \Zend\Code\Generator\ClassGenerator();
     $file->setClass($class);
     $this->setFile($file);
     $this->_runPlugins(self::PART_ENTITY_ABSTRACT, self::RUNTIME_PRE);
     $class->setName($table->getNameAsCamelCase() . 'EntityAbstract');
     $class->setExtendedClass('\\Model\\Entity');
     $this->_runPlugins(self::PART_ENTITY_ABSTRACT, self::RUNTIME_POST);
     if ($outputFilename) {
         file_put_contents($outputFilename, $file->generate());
     }
 }
Example #3
0
 public function __construct(Table $table, Cluster $cluster, $outputFilename = null)
 {
     Log::info('Generate part front collection ' . $table->getName());
     $this->_table = $table;
     $file = new \Model\Code\Generator\FileGenerator();
     $this->setFile($file);
     $class = new \Zend\Code\Generator\ClassGenerator();
     $file->setClass($class);
     $this->_runPlugins(self::PART_FRONT_COLLECTION, self::RUNTIME_PRE);
     $class->setNamespaceName('Model\\Collection');
     $class->setName($table->getNameAsCamelCase() . 'Collection');
     $class->setExtendedClass('Abstract' . $table->getNameAsCamelCase() . 'Collection');
     $this->_runPlugins(self::PART_FRONT_COLLECTION, self::RUNTIME_POST);
     if ($outputFilename) {
         file_put_contents($outputFilename, $file->generate());
     }
 }
Example #4
0
 public function __construct(Table $table, Cluster $cluster, $outputFilename = null)
 {
     Log::debug('Generate part list ' . $table->getName());
     $this->_table = $table;
     $file = new FileGenerator();
     $this->setFile($file);
     $class = new ClassGenerator();
     $file->setClass($class);
     $file->setNamespace('Model\\Collection');
     //$file->setUse('Model\ResultList');
     $this->_runPlugins(self::PART_COLLECTION, self::RUNTIME_PRE);
     $class->setName('Abstract' . $table->getNameAsCamelCase() . 'Collection');
     $class->setExtendedClass('AbstractCollection');
     $class->setAbstract(true);
     $this->_runPlugins(self::PART_COLLECTION, self::RUNTIME_POST);
     if ($outputFilename) {
         file_put_contents($outputFilename, $file->generate());
     }
 }
Example #5
0
 /**
  * @param Table|string $table
  * @return array
  */
 public function getForeignKeyArray($table)
 {
     $schemaName = $this->getName();
     $tableName = $table instanceof Table ? $table->getName() : (string) $table;
     $cacheId = 'generator_schema_getForeignKeyArray_' . $tableName;
     $cacheAdapter = $this->getCacheAdapter();
     $result = $cacheAdapter ? $cacheAdapter->getItem($cacheId) : null;
     if (!$cacheAdapter || is_null($result)) {
         $sql = "SELECT k.CONSTRAINT_NAME as key_name,\n                           k.TABLE_SCHEMA as table_schema,\n                           k.TABLE_NAME as table_name,\n                           k.COLUMN_NAME as column_name,\n                           k.REFERENCED_TABLE_SCHEMA as referenced_table_schema,\n                           k.REFERENCED_TABLE_NAME as referenced_table_name,\n                           k.REFERENCED_COLUMN_NAME as referenced_column_name,\n                           r.UPDATE_RULE as update_rule,\n                           r.DELETE_RULE as delete_rule\n                    FROM `information_schema`.`KEY_COLUMN_USAGE` as k\n                    JOIN `information_schema`.TABLE_CONSTRAINTS as c ON\n                        k.`CONSTRAINT_SCHEMA` = c.`CONSTRAINT_SCHEMA`\n                        AND k.`TABLE_NAME` = c.`TABLE_NAME`\n                        AND k.`CONSTRAINT_NAME` = c.`CONSTRAINT_NAME`\n                    JOIN `information_schema`.`REFERENTIAL_CONSTRAINTS` as r\n                        ON (k.`CONSTRAINT_SCHEMA` = r.`CONSTRAINT_SCHEMA`\n                            AND k.`TABLE_NAME` = r.`TABLE_NAME`\n                            AND k.`CONSTRAINT_NAME` = r.`CONSTRAINT_NAME`)\n                    WHERE ((k.`CONSTRAINT_SCHEMA` = '{$schemaName}'\n                        AND k.`TABLE_NAME` = '{$tableName}')\n                        OR  (k.`REFERENCED_TABLE_SCHEMA` = '{$schemaName}'\n                            AND k.`REFERENCED_TABLE_NAME` = '{$tableName}'))\n                        AND c.CONSTRAINT_TYPE = 'FOREIGN KEY'\n                    ORDER BY k.CONSTRAINT_NAME";
         $result = $this->getDb()->fetchAll($sql);
         if ($cacheAdapter) {
             $cacheAdapter->setItem($cacheId, $result);
         }
     }
     return $result;
 }
Example #6
0
 public function testGetName()
 {
     $this->assertEquals('product', $this->_table->getName());
 }