[ticket/14434] Remove recursion to simplify is_migration method

PHPBB3-14434
This commit is contained in:
Matt Friedman 2016-01-27 11:46:04 -08:00
parent 47d8aeebde
commit 3bd8a2ba19
3 changed files with 17 additions and 26 deletions

View file

@ -79,8 +79,7 @@ class schema_generator
{ {
foreach ($migrations as $key => $migration_class) foreach ($migrations as $key => $migration_class)
{ {
// Unset classes that do not exist or do not extend the // Unset classes that are not a valid migration
// abstract class phpbb\db\migration\migration
if (\phpbb\db\migrator::is_migration($migration_class) === false) if (\phpbb\db\migrator::is_migration($migration_class) === false)
{ {
unset($migrations[$key]); unset($migrations[$key]);

View file

@ -861,31 +861,16 @@ class migrator
/** /**
* Check if a class is a migration. * Check if a class is a migration.
* *
* @param mixed $migration An array of migration name strings, or * @param string $migration A migration class name
* a single migration name string. * @return bool Return true if class is a migration, false otherwise
* @return bool Returns true or false for a single migration.
* If an array was received, non-migrations will
* be removed from the array, and false is returned.
*/ */
static public function is_migration(&$migration) static public function is_migration($migration)
{ {
if (is_array($migration)) if (class_exists($migration))
{
foreach ($migration as $key => $name)
{
if (self::is_migration($name))
{
continue;
}
unset($migration[$key]);
}
}
else if (class_exists($migration))
{ {
// Migration classes should extend the abstract class // Migration classes should extend the abstract class
// phpbb\db\migration\migration which implements the // phpbb\db\migration\migration (which implements the
// migration_interface and be instantiable. // migration_interface) and be instantiable.
$reflector = new \ReflectionClass($migration); $reflector = new \ReflectionClass($migration);
if ($reflector->implementsInterface('\phpbb\db\migration\migration_interface') && $reflector->isInstantiable()) if ($reflector->implementsInterface('\phpbb\db\migration\migration_interface') && $reflector->isInstantiable())
{ {

View file

@ -137,9 +137,16 @@ class base implements \phpbb\extension\extension_interface
$migrations = $this->extension_finder->get_classes_from_files($migrations); $migrations = $this->extension_finder->get_classes_from_files($migrations);
// Unset classes that do not exist or do not extend the // Unset classes that are not a valid migration
// abstract class phpbb\db\migration\migration foreach ($migrations as $key => $migration)
\phpbb\db\migrator::is_migration($migrations); {
if (\phpbb\db\migrator::is_migration($migration) === true)
{
continue;
}
unset($migrations[$key]);
}
return $migrations; return $migrations;
} }