Esempio n. 1
0
 public static function factory($id = 'core', $command = '', $args = array())
 {
     $module = new CoreAPIModule();
     $module->init($command, $args);
     return $module;
 }
Esempio n. 2
0
$parts = explode('/', ltrim($path, '/'), 2);

if ($parts[0]==API_URL_PREFIX) {
    set_exception_handler("exceptionHandlerForAPI");
    $parts = explode('/', ltrim($path, '/'));

    switch (count($parts))
    {
        case 1:
            throw new Exception("Invalid API request: '{$_SERVER['REQUEST_URI']}'", 1);

        case 2: 
            $id = 'core';
            $command = $parts[1];
            if (!$module = CoreAPIModule::factory($command, $args)) {
                throw new Exception("Module $id cannot be loaded");
            }
            break;
            
        case 3:
            $id = isset($parts[1]) ? $parts[1] : '';
            $command = isset($parts[2]) ? $parts[2] : '';
            if (!$module = APIModule::factory($id, $command, $args)) {
                throw new Exception("Module $id cannot be loaded");
            }
            break;

        default:
            throw new Exception("Invalid API request: '{$_SERVER['REQUEST_URI']}'", 1);
            break;
Esempio n. 3
0
 public static function getAllModules()
 {
     $dirs = array(MODULES_DIR, SITE_MODULES_DIR);
     $modules = array('core' => CoreAPIModule::factory());
     foreach ($dirs as $dir) {
         if (is_dir($dir)) {
             $d = dir($dir);
             while (false !== ($entry = $d->read())) {
                 if ($entry[0] != '.' && is_dir(sprintf("%s/%s", $dir, $entry))) {
                     try {
                         if ($module = APIModule::factory($entry)) {
                             $modules[$entry] = $module;
                         }
                     } catch (KurogoException $e) {
                     }
                 }
             }
             $d->close();
         }
     }
     ksort($modules);
     return $modules;
 }