ZendDbSchema
Schema management for Zend Framework
 All Classes Namespaces Functions Pages
Change.php
1 <?php
30 {
34  protected $_downgradable = true;
35 
39  protected $_databasesConfig = array();
40 
44  protected $_tablesConfig = array();
45 
46 
50  protected $_description = '';
51 
55  abstract function up();
56 
60  abstract function down();
61 
65  public function __toString()
66  {
67  return $this->getVersion();
68  }
69 
75  public function getName()
76  {
77  return get_class($this);
78  }
79 
85  public function getDescription()
86  {
87  return $this->_description;
88  }
89 
95  public function isDowngradable()
96  {
97  return (bool) $this->_downgradable;
98  }
99 
105  public function getTablesConfig()
106  {
107  return $this->_tablesConfig;
108  }
109 
115  public function getDatabasesConfig()
116  {
117  return $this->_databasesConfig;
118  }
119 
125  public function getVersion()
126  {
127  return substr(get_class($this), 10);
128  }
129 
138  public function compareVersion($version, $operator = null)
139  {
140  if ($version instanceof ZendDbSchema_Db_Migration_Change) {
141  $version = $version->getVersion();
142  }
143  $version = strtolower($version);
144  $current = strtolower($this->getVersion());
145 
146  return version_compare($version, $current, $operator);
147  }
148 
156  public static function fromFile($file)
157  {
158  if ($file instanceof SplFileInfo) {
159  $file = $file->getPathname();
160  }
161  if (!realpath($file) || !is_file($file)) {
162  throw new ZendDbSchema_Db_Migration_Exception("{$file} not exists");
163  }
164  include_once $file;
166  return new $class;
167  }
168 }