Пример #1
0
 public function testGetTemplateObject()
 {
     $sl = new AetherServiceLocator();
     $sl->set('projectRoot', AETHER_PATH . 'tests/templating/');
     $tpl = AetherTemplate::get('smarty', $sl);
     $this->assertTrue($tpl instanceof AetherTemplateSmarty);
 }
Пример #2
0
 public function testArray()
 {
     $asl = new AetherServiceLocator();
     $arr = $asl->getVector('foo');
     $arr['foo'] = 'bar';
     $arr2 = $asl->getVector('foo');
     $this->assertEquals($arr['foo'], $arr2['foo']);
 }
Пример #3
0
 public function testGetTemplateObject()
 {
     $sl = new AetherServiceLocator();
     $sl->set('projectRoot', AETHER_PATH . 'tests/templating/');
     $config = new AetherConfig('./aether.config.xml');
     $sl->set('aetherConfig', $config);
     $tpl = $sl->getTemplate();
     $this->assertTrue($tpl instanceof AetherTemplateSmarty);
 }
Пример #4
0
 public function testGetSmartyEngine()
 {
     // Go through SL
     $sl = new AetherServiceLocator();
     // TODO THIS IS UGLY AND MUST BE BAD
     $sl->set('projectRoot', AETHER_PATH . 'tests/templating/');
     // Fetch smarty
     $tpl = $sl->getTemplate();
     $tpl->set('foo', array('a' => 'hello', 'b' => 'world'));
     $out = $tpl->fetch('test.tpl');
     $this->assertTrue(substr_count($out, 'hello world') > 0);
 }
Пример #5
0
 public function testSectionCan404()
 {
     $sl = new AetherServiceLocator();
     $config = $this->getLoadedConfig('http://raw.no/unittest/goodtimes/nay');
     $sl->set('aetherConfig', $config);
     AetherSectionFactory::$strict = true;
     AetherSectionFactory::$path = __DIR__ . '/fixtures';
     $section = AetherSectionFactory::create('Testsection', $sl);
     $response = $section->response();
     $this->assertTrue($response instanceof AetherTextResponse);
     $this->assertEquals('404 Eg fant han ikkje', $response->get(), 'Response should be NotFoundSection\'s output');
     $this->assertArrayNotHasKey('id', $response->options, 'Options should be cleared when reloading config');
 }
Пример #6
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;
 }
Пример #7
0
 protected function triggerDefaultRule()
 {
     $config = $this->sl->get('aetherConfig');
     $config->reloadConfigFromDefaultRule();
     $section = AetherSectionFactory::create($config->getSection(), $this->sl);
     return $section->response();
 }
Пример #8
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);
         }
     }
 }
Пример #9
0
 /**
  * Provide the output of a module
  *
  * @access public
  * @return void
  * @param string $name
  * @param string $content
  */
 public function provide($name, $content)
 {
     $vector = $this->sl->getVector('aetherProviders');
     $vector[$name] = $content;
 }
Пример #10
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);
             }
         }
     }
 }