Move getUpdates to Maintenance\Utils class

This commit is contained in:
Dmitriy Simushev 2014-11-28 11:02:55 +00:00
parent abdfa54f36
commit 80f5873d9a
2 changed files with 32 additions and 32 deletions

View File

@ -122,7 +122,7 @@ class Updater
} }
// Get list of all available updates // Get list of all available updates
$updates = $this->getUpdates(); $updates = Utils::getUpdates($this);
// Check if updates should be performed // Check if updates should be performed
$versions = array_keys($updates); $versions = array_keys($updates);
@ -258,35 +258,4 @@ class Updater
return false; return false;
} }
} }
/**
* Gets list of all available updates.
*
* @return array The keys of this array are version numbers and values are
* methods of the {@link \Mibew\Maintenance\Updater} class that should be
* performed.
*/
protected function getUpdates()
{
$updates = array();
$self_reflection = new \ReflectionClass($this);
foreach ($self_reflection->getMethods() as $method_reflection) {
// Filter update methods
$name = $method_reflection->getName();
if (preg_match("/^update([0-9]+)(?:Beta([0-9]+))?$/", $name, $matches)) {
$version = Utils::formatVersionId($matches[1]);
// Check if a beta version is defined.
if (!empty($matches[2])) {
$version .= '-beta.' . $matches[2];
}
$updates[$version] = $name;
}
}
uksort($updates, 'version_compare');
return $updates;
}
} }

View File

@ -49,6 +49,37 @@ class Utils
return implode('.', array_reverse($parts)); return implode('.', array_reverse($parts));
} }
/**
* Gets list of all available updates.
*
* @param object $container Instance of the class that keeps update methods.
* @return array The keys of this array are version numbers and values are
* methods of the $container class that should be performed.
*/
public static function getUpdates($container)
{
$updates = array();
$container_reflection = new \ReflectionClass($container);
foreach ($container_reflection->getMethods() as $method_reflection) {
// Filter update methods
$name = $method_reflection->getName();
if (preg_match("/^update([0-9]+)(?:Beta([0-9]+))?$/", $name, $matches)) {
$version = self::formatVersionId($matches[1]);
// Check if a beta version is defined.
if (!empty($matches[2])) {
$version .= '-beta.' . $matches[2];
}
$updates[$version] = $name;
}
}
uksort($updates, 'version_compare');
return $updates;
}
/** /**
* This class should not be instantiated * This class should not be instantiated
*/ */