1
0
mirror of https://github.com/e107inc/e107.git synced 2025-10-13 14:04:51 +02:00
Files
php-e107/lib/preparers/PreparerFactory.php
Nick Liu c72b08616b Refactored E107Base suite cleanup into "Preparer" classes
Now works with the best of both worlds:

* Barebones cleanup in slow Windows environments
* Git snapshots in other Git environments
2018-09-12 12:54:15 -05:00

57 lines
1.1 KiB
PHP

<?php
spl_autoload_register(function($class_name) {
$candidate_path = __DIR__ . "/$class_name.php";
if (file_exists($candidate_path))
{
include_once($candidate_path);
}
});
class PreparerFactory
{
/**
* @return Preparer
*/
public static function create()
{
if (self::systemIsSlow())
{
return self::createFromName('E107Preparer');
}
elseif (self::systemHasGit() && self::appPathIsGitRepo())
{
return self::createFromName('GitPreparer');
}
return self::createFromName('E107Preparer');
}
/**
* @param $class_name
* @return Preparer
*/
public static function createFromName($class_name)
{
codecept_debug('Instantiating Preparer: ' . $class_name);
return new $class_name();
}
private static function systemIsSlow()
{
return self::systemIsWindows();
}
private static function systemIsWindows()
{
return strtolower(substr(php_uname('s'), 0, 3)) === 'win';
}
private static function systemHasGit()
{
return stripos(shell_exec('git --version'), 'git version') !== false;
}
private static function appPathIsGitRepo()
{
return file_exists(APP_PATH."/.git");
}
}