예제 #1
0
 public function testShouldNotAcceptMaliciousModuleNames()
 {
     AetherModuleFactory::$strict = false;
     AetherModuleFactory::$path = __DIR__ . '/fixtures/modules';
     $this->setExpectedException('AetherInvalidModuleNameException');
     $mod = AetherModuleFactory::create('../sections/Testsection', new AetherServiceLocator(), []);
 }
예제 #2
0
 public function testCreateModuleFromCustomFolder()
 {
     $dir = dirname(__FILE__) . '/';
     AetherModuleFactory::$strict = false;
     AetherModuleFactory::$path = $dir;
     $mod = AetherModuleFactory::create('Hellolocal', new AetherServiceLocator(), array('foo' => 'bar'));
     $this->assertEquals($mod->run(), 'Hello local');
 }
예제 #3
0
 /**
  * Render service
  *
  * @access public
  * @return AetherResponse
  * @param string $moduleName
  * @param string $serviceName Name of service
  */
 public function service($moduleName, $serviceName)
 {
     // Locate module containing service
     $config = $this->sl->get('aetherConfig');
     $options = $config->getOptions();
     // Support custom searchpaths
     $searchPath = isset($options['searchpath']) ? $options['searchpath'] : $this->sl->get("aetherPath");
     AetherModuleFactory::$path = $searchPath;
     // Create module
     $mod = null;
     foreach ($config->getModules() as $module) {
         if ($module['name'] != $moduleName) {
             continue;
         }
         if (!isset($module['options'])) {
             $module['options'] = array();
         }
         $opts = $module['options'] + $options;
         if (array_key_exists('session', $opts) and $opts['session'] == 'on') {
             session_start();
         }
         // Get module object
         $mod = AetherModuleFactory::create($module['name'], $this->sl, $module['options']);
         break;
     }
     // Run service
     if ($mod instanceof AetherModule) {
         // Run service
         return $mod->service($serviceName);
     }
     throw new Exception("Service run error: Failed to locate module [{$moduleName}], check if it is loaded in config for this url: " . $_SERVER['SCRIPT_URI']);
 }
예제 #4
0
 /**
  * Render service
  *
  * @access public
  * @return AetherResponse
  * @param string $moduleName
  * @param string $serviceName Name of service
  */
 public function service($name, $serviceName, $type = 'module')
 {
     // Locate module containing service
     $config = $this->sl->get('aetherConfig');
     $options = $config->getOptions();
     // Support custom searchpaths
     $searchPath = isset($options['searchpath']) ? $options['searchpath'] : $this->sl->get("aetherPath");
     AetherModuleFactory::$path = $searchPath;
     $locale = isset($options['locale']) ? $options['locale'] : "nb_NO.UTF-8";
     setlocale(LC_ALL, $locale);
     $lc_numeric = isset($options['lc_numeric']) ? $options['lc_numeric'] : 'C';
     setlocale(LC_NUMERIC, $lc_numeric);
     if ($type == 'fragment') {
         $fragment = $config->getFragments($name);
         $moduleNames = isset($fragment['modules']) ? array_keys($fragment['modules']) : [];
     } else {
         $moduleNames = [$name];
     }
     // Create module
     $mod = null;
     $modules = [];
     $configModules = $config->getModules();
     $configModuleNames = array_map(function ($mod) {
         return $mod['name'];
     }, $configModules);
     foreach ($moduleNames as $moduleName) {
         if (isset($configModules[$moduleName])) {
             $module = $configModules[$moduleName];
         } elseif (in_array($moduleName, $configModuleNames)) {
             foreach ($configModules as $m) {
                 if ($m['name'] == $moduleName) {
                     $module = $m;
                     break;
                 }
             }
         } else {
             $module = array('name' => $moduleName);
         }
         if (!isset($module['options'])) {
             $module['options'] = array();
         }
         $opts = $module['options'] + $options;
         if (array_key_exists('session', $opts) and $opts['session'] == 'on') {
             session_start();
         }
         // Get module object
         $mod = AetherModuleFactory::create($module['name'], $this->sl, $opts);
         if ($type == 'module') {
             $modules = [$mod];
             break;
         } else {
             $modules[$moduleName] = $mod;
         }
     }
     // Run service
     $moduleResponses = [];
     foreach ($modules as $id => $mod) {
         if ($mod instanceof AetherModule) {
             // Run service
             if ($type == 'module') {
                 return $mod->service($serviceName);
             } else {
                 if ($serviceName === null) {
                     $moduleResponses[$id] = new AetherTextResponse($mod->run());
                 } else {
                     $moduleResponses[$id] = $mod->service($serviceName);
                 }
             }
         } else {
             throw new AetherServiceNotFoundException("Service run error: Failed to locate {$type} [{$name}], check if it is loaded in config for this url: " . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] . (isset($_SERVER['HTTP_REFERER']) ? ", called from URI: " . $_SERVER['HTTP_REFERER'] : ""));
         }
     }
     return new AetherFragmentResponse($moduleResponses);
 }