51 public function __construct(Zend_CodeGenerator_Php_Class $class = null)
54 $class =
new Zend_CodeGenerator_Php_Class();
56 $class->setExtendedClass(
'ZendDbSchema_Db_Migration_Change');
58 $this->_class = $class;
68 $up =
new Zend_CodeGenerator_Php_Method();
69 $up->setName(
'up')->setBody($body);
71 $this->_class->setMethod($up);
81 $down =
new Zend_CodeGenerator_Php_Method();
82 $down->setName(
'down')->setBody($body);
84 $this->_class->setMethod($down);
93 public function addSchema(array $tablesList = array(), array $databasesList = array())
95 if (empty($databasesList)) {
97 $databasesList[] = $config[
'dbname'];
99 $databasesConfig = array();
100 foreach ($databasesList as $database) {
102 $databasesConfig[$database] = $schema->toArray();
105 $databases =
new Zend_CodeGenerator_Php_Property();
106 $databases->setName(
'_databasesConfig')
107 ->setVisibility(Zend_CodeGenerator_Php_Property::VISIBILITY_PROTECTED)
108 ->setDefaultValue($databasesConfig)
109 ->setDocBlock(
"Databases configuration \n@var array");
111 $this->_class->setProperty($databases);
113 if (!empty($tablesList)) {
114 $tablesList = array_intersect(
119 $tablesList = $this->
getAdapter()->listTables();
122 $tablesConfig = array();
123 foreach ($tablesList as $table) {
125 $tablesConfig[$table] = $schema->toArray();
127 $tables =
new Zend_CodeGenerator_Php_Property();
128 $tables->setName(
'_tablesConfig')
129 ->setVisibility(Zend_CodeGenerator_Php_Property::VISIBILITY_PROTECTED)
130 ->setDefaultValue($tablesConfig)
131 ->setDocBlock(
"Tables configuration \n@var array");
133 $this->_class->setProperty($tables);
144 $this->_version = rtrim($version,
'.php');
146 $this->
getClass()->setName(self::getClassName($version));
158 if (!$this->_version) {
161 return $this->_version;
171 $file =
new Zend_CodeGenerator_Php_File();
173 $file->setFilename(self::getFilename($this->
getVersion()));
197 return $this->_class;
208 if (!$this->_adapter) {
212 return $this->_adapter;
223 $this->_adapter = $adapter;
235 return 'Migration_' . basename($version,
'.php');
245 list($sec, $msec) = explode(
".", microtime(
true));
246 return date(
'Ymd_His_') . substr($msec, 0, 2);
256 return $version .
'.php';