39 protected $_changes = array();
41 protected $_currentVersion;
49 public function __construct($version, array $files = array(), array $options = array())
51 $this->_currentVersion = (string) $version;
53 foreach ($files as $file) {
57 if (empty($options[
'directory'])) {
58 foreach (
new DirectoryIterator($options[
'directory']) as $file) {
59 if ($file->isFile() && substr($file->getBasename(), -4) ==
'.php') {
65 if ($this->_currentVersion && !array_key_exists($this->_currentVersion, $this->_changes)) {
67 "Current change '{$this->_currentVersion}' in not exists"
72 foreach ($this->_changes as $version => $instance) {
73 $this->_changes[$version][
'previous'] = $prev;
75 $this->_changes[$prev][
'next'] = $version;
94 $this->_changes[$change->getVersion()] = array(
'instance' => $change);
96 foreach ($this->_changes as $change) {
97 if ($change->compareVersion($change,
'=')) {
101 $next = next($this->_changes);
102 $this->_changes[$change->getVersion()][
'next'] = key($next);
104 $prev = prev(prev($this->_changes));
106 $this->_changes[$prev][
'next'] = $change->getVersion();
125 ksort($this->_changes);
127 return $this->_changes;
147 return $this->_currentVersion;
163 return $this->_changes[$version][
'instance'];
180 return $this->_changes[$version][
'next'];
193 return array_key_exists((
string) $change, $this->_changes);
208 return $this->_changes[$version][
'prev'];
225 foreach ($change->getTablesConfig() as $name => $config) {
227 $schema->setFromArray($config);
232 $this->_currentVersion = $next;
249 if (!$this->
getChange()->isDowngradable()) {
254 foreach ($change->getTablesConfig() as $name => $config) {
256 $schema->setFromArray($config);
261 $this->_currentVersion = $prev;
270 public function up($version = null)
321 $result = $change->compareVersion($this->
getVersion(), $operator);
323 return is_bool($result) ? !$result : -$result;
335 foreach ($change->getTablesConfig() as $name => $config) {
337 $schema->setFromArray($config);
338 if ($schema->isDirty()) {
343 foreach ($change->getDatabasesConfig() as $name => $config) {
345 $schema->setFromArray($config);
346 if ($schema->isDirty()) {