Example #1
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']);
 }
Example #2
0
 protected function triggerDefaultRule()
 {
     $config = $this->sl->get('aetherConfig');
     $config->reloadConfigFromDefaultRule();
     $section = AetherSectionFactory::create($config->getSection(), $this->sl);
     return $section->response();
 }
 public function testCustomObjectStorage()
 {
     // Create a small class for testing
     $obj = new stdClass();
     $obj->foo = 'bar';
     $asl = new AetherServiceLocator();
     $asl->set('tester', $obj);
     $tester = $asl->get('tester');
     $this->assertSame($tester, $obj);
 }
Example #4
0
 /**
  * Draw text response. Echoes out the response
  *
  * @access public
  * @return void
  * @param AetherServiceLocator $sl
  */
 public function draw($sl)
 {
     if (session_id() !== '') {
         $_SESSION['wasGoingTo'] = $_SERVER['REQUEST_URI'];
     }
     try {
         // Timer
         $timer = $sl->get('timer');
         $timer->end('aether_main');
         // Replace into out content
         $tpl = $sl->getTemplate();
         //$tpl->selectTemplate('debugBar');
         $timers = $timer->all();
         foreach ($timers as $key => $tr) {
             foreach ($tr as $k => $t) {
                 if (!array_key_exists('elapsed', $t)) {
                     $t['elapsed'] = 0;
                 }
                 $timers[$key][$k]['elapsed'] = number_format($t['elapsed'], 4);
                 // Format memory
                 if (isset($t['memory'])) {
                     $memLen = strlen($t['memory']);
                     $memUse = $t['memory'];
                     if ($memLen > 9) {
                         $memUse = round($memUse / (1000 * 1000 * 1000), 1) . "GB";
                     }
                     if ($memLen > 6) {
                         $memUse = round($memUse / (1000 * 1000), 1) . "MB";
                     } elseif ($memLen > 3) {
                         $memUse = round($memUse / 1000, 1) . "KB";
                     }
                     $timers[$key][$k]['mem_use'] = $memUse;
                 }
             }
         }
         $tpl->set('timers', $timers);
         try {
             $out = $tpl->fetch('debugBar.tpl');
         } catch (Exception $e) {
             echo $e;
         }
         $out = str_replace("<!--INSERTIONPOINT-->", $out, $this->out);
     } catch (Exception $e) {
         // No timing, we're in prod
         $out = $this->out;
     }
     if ($this->contentType) {
         header("Content-Type: {$this->contentType}; charset=UTF-8");
     }
     echo $out;
 }
Example #5
0
 /**
  * Ask the AetherSection to render itself,
  * or if a service is requested it will try to load that service
  *
  * @access public
  * @return string
  */
 public function render()
 {
     $config = $this->sl->get('aetherConfig');
     $options = $config->getOptions();
     /**
      * If a service is requested simply render the service
      */
     if (isset($_GET['module']) && isset($_GET['service'])) {
         $response = $this->section->service($_GET['module'], $_GET['service']);
         if (!is_object($response) || !$response instanceof AetherResponse) {
             trigger_error("Expected " . preg_replace("/[^A-z0-9]+/", "", $_GET['module']) . "::service() to return an AetherResponse object", E_USER_WARNING);
         } else {
             $response->draw($this->sl);
         }
     } else {
         if (isset($_GET['_esi'])) {
             /**
              * ESI support and rendering of only one module by provider name
              * # _esi to list
              * # _esi=<providerName> to render one module with settings of the url path
              */
             if (strlen($_GET['_esi']) > 0) {
                 $this->section->renderProviderWithCacheHeaders($_GET['_esi']);
             } else {
                 $modules = $config->getModules();
                 $providers = array();
                 foreach ($modules as $m) {
                     $providers[] = array('provides' => $m['provides'], 'cache' => isset($m['cache']) ? $m['cache'] : false);
                 }
                 $response = new AetherJSONResponse(array('providers' => $providers));
                 $response->draw($this->sl);
             }
         } else {
             /**
              * Start session if session switch is turned on in 
              * configuration file
              */
             if (array_key_exists('session', $options) and $options['session'] == 'on') {
                 session_start();
             }
             $response = $this->section->response();
             $response->draw($this->sl);
         }
     }
 }
Example #6
0
 /**
  * Ask the AetherSection to render itself,
  * or if a service is requested it will try to load that service
  *
  * @access public
  * @return string
  */
 public function render()
 {
     $config = $this->sl->get('aetherConfig');
     $options = $config->getOptions();
     /**
      * If a service is requested simply render the service
      */
     if (isset($_GET['module']) && isset($_GET['service'])) {
         $response = $this->section->service($_GET['module'], $_GET['service']);
         if (!is_object($response) || !$response instanceof AetherResponse) {
             trigger_error("Expected " . preg_replace("/[^A-z0-9]+/", "", $_GET['module']) . "::service() to return an AetherResponse object." . (isset($_SERVER['HTTP_REFERER']) ? " Referer: " . $_SERVER['HTTP_REFERER'] : ""), E_USER_WARNING);
         } else {
             $response->draw($this->sl);
         }
     } else {
         if (isset($_GET['fragment']) && isset($_GET['service'])) {
             $response = $this->section->service($_GET['fragment'], $_GET['service'] !== "_esi" ? $_GET['service'] : null, 'fragment');
             $response->draw($this->sl);
         } else {
             if (isset($_GET['_esi'])) {
                 /**
                  * ESI support and rendering of only one module by provider name
                  * # _esi to list
                  * # _esi=<providerName> to render one module with settings of the url path
                  */
                 if (strlen($_GET['_esi']) > 0) {
                     $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 (isset($options['lc_messages'])) {
                         $localeDomain = "messages";
                         setlocale(LC_MESSAGES, $options['lc_messages']);
                         bindtextdomain($localeDomain, self::$aetherPath . "/locales");
                         bind_textdomain_codeset($localeDomain, 'UTF-8');
                         textdomain($localeDomain);
                     }
                     $this->section->renderProviderWithCacheHeaders($_GET['_esi']);
                 } else {
                     $modules = $config->getModules();
                     $fragments = $config->getFragments();
                     $providers = array();
                     foreach ($modules + $fragments as $m) {
                         $provider = ['provides' => isset($m['provides']) ? $m['provides'] : null, 'cache' => isset($m['cache']) ? $m['cache'] : false];
                         if (isset($m['module'])) {
                             $provider['providers'] = array_map(function ($m) {
                                 return ['provides' => $m['provides'], 'cache' => isset($m['cache']) ? $m['cache'] : false];
                             }, array_values($m['module']));
                         }
                         $providers[] = $provider;
                     }
                     $response = new AetherJSONResponse(array('providers' => $providers));
                     $response->draw($this->sl);
                 }
             } else {
                 /**
                  * Start session if session switch is turned on in 
                  * configuration file
                  */
                 if (array_key_exists('session', $options) and $options['session'] == 'on') {
                     session_start();
                 }
                 $response = $this->section->response();
                 $response->draw($this->sl);
             }
         }
     }
 }