|
|
@ -20,34 +20,40 @@ class Autoload |
|
|
|
/** |
|
|
|
/** |
|
|
|
* Autoload a Class by it's Class Name |
|
|
|
* Autoload a Class by it's Class Name |
|
|
|
* @param string $className |
|
|
|
* @param string $className |
|
|
|
|
|
|
|
* @return boolean |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public static function autoload($className) |
|
|
|
public function autoLoad($className) |
|
|
|
{ |
|
|
|
{ |
|
|
|
$baseDir = dirname(dirname(__FILE__)); |
|
|
|
$className = ltrim($className, '/'); |
|
|
|
$classFile = $baseDir . '/' . str_replace(array('_', '\\'), '/', $className . '.php'); |
|
|
|
$postfix = '/' . str_replace(array('_', '\\'), '/', $className . '.php'); |
|
|
|
require_once $classFile; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
//Try to load a normal Mage class (or Task). Think that Mage component is compiled to .phar |
|
|
|
* Checks if a Class can be loaded. |
|
|
|
|
|
|
|
* @param string $className |
|
|
|
|
|
|
|
* @return boolean |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
public static function isLoadable($className) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
$baseDir = dirname(dirname(__FILE__)); |
|
|
|
$baseDir = dirname(dirname(__FILE__)); |
|
|
|
$classFile = $baseDir . '/' . str_replace(array('_', '\\'), '/', $className . '.php'); |
|
|
|
$classFileWithinPhar = $baseDir . $postfix; |
|
|
|
return (file_exists($classFile) && is_readable($classFile)); |
|
|
|
if($this->isReadable($classFileWithinPhar)) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
require_once $classFileWithinPhar; |
|
|
|
|
|
|
|
return true; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//Try to load a custom Task or Class. Notice that the path is absolute to CWD |
|
|
|
|
|
|
|
$classFileOutsidePhar = getcwd() . '/.mage/tasks' . $postfix; |
|
|
|
|
|
|
|
if($this->isReadable($classFileOutsidePhar)){ |
|
|
|
|
|
|
|
require_once $classFileOutsidePhar; |
|
|
|
|
|
|
|
return true; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return false; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Loads a User's Tasks |
|
|
|
* Checks if a file can be read. |
|
|
|
* @param string $taskName |
|
|
|
* @param string $filePath |
|
|
|
|
|
|
|
* @return boolean |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public static function loadUserTask($taskName) |
|
|
|
public function isReadable($filePath) |
|
|
|
{ |
|
|
|
{ |
|
|
|
$classFile = getcwd() . '/.mage/tasks/' . ucfirst($taskName) . '.php'; |
|
|
|
return is_readable($filePath); |
|
|
|
require_once $classFile; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|