mult1mate\crontab\TaskLoader::loadController PHP Метод

loadController() публичный статический Метод

Looks for and loads required class via require_once
public static loadController ( $class_name ) : boolean
$class_name
Результат boolean
    public static function loadController($class_name)
    {
        foreach (self::$class_folders as $f) {
            $f = rtrim($f, '/');
            $filename = $f . '/' . $class_name . '.php';
            if (file_exists($filename)) {
                require_once $filename;
                if (class_exists($class_name)) {
                    return true;
                } else {
                    throw new TaskManagerException('file found but class ' . $class_name . ' not loaded');
                }
            }
        }
        throw new TaskManagerException('class ' . $class_name . ' not found');
    }

Usage Example

Пример #1
0
 /**
  * Parses given command, creates new class object and calls its method via call_user_func_array
  * @param string $command
  * @return mixed
  */
 public static function parseAndRunCommand($command)
 {
     try {
         list($class, $method, $args) = TaskManager::parseCommand($command);
         if (!class_exists($class)) {
             TaskLoader::loadController($class);
         }
         $obj = new $class();
         if (!method_exists($obj, $method)) {
             throw new TaskManagerException('method ' . $method . ' not found in class ' . $class);
         }
         return call_user_func_array(array($obj, $method), $args);
     } catch (\Exception $e) {
         echo 'Caught an exception: ' . get_class($e) . ': ' . PHP_EOL . $e->getMessage() . PHP_EOL;
         return false;
     }
 }
All Usage Examples Of mult1mate\crontab\TaskLoader::loadController