コード例 #1
0
ファイル: SectionFactoryTest.php プロジェクト: M4R7iNP/aether
 public function testCreate()
 {
     AetherSectionFactory::$strict = true;
     AetherSectionFactory::$path = __DIR__ . '/fixtures';
     $section = AetherSectionFactory::create('Testsection', new AetherServiceLocator());
     $this->assertTrue(is_subclass_of($section, 'AetherSection'));
     $this->assertEquals(get_class($section), 'Testsection');
 }
コード例 #2
0
 public function testCreate()
 {
     $dir = dirname(__FILE__) . '/';
     AetherSectionFactory::$strict = false;
     AetherSectionFactory::$path = $dir;
     $section = AetherSectionFactory::create('Testsection', new AetherServiceLocator());
     $this->assertType('AetherSectionTestsection', $section);
 }
コード例 #3
0
ファイル: SectionTest.php プロジェクト: M4R7iNP/aether
 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');
 }
コード例 #4
0
ファイル: Aether.php プロジェクト: M4R7iNP/aether
 /**
  * Start Aether.
  * On start it will parse the projects configuration file,
  * it will try to match the presented http request to a rule
  * in the project configuration and create some overview
  * over which modules it will need to render once
  * a request to render them comes
  *
  * @access public
  * @return Aether
  * @param string $configPath Optional path to the configuration file for the project
  */
 public function __construct($configPath = false)
 {
     self::$aetherPath = pathinfo(__FILE__, PATHINFO_DIRNAME) . "/";
     spl_autoload_register(array('Aether', 'autoLoad'));
     $this->sl = new AetherServiceLocator();
     $this->sl->set('aetherPath', self::$aetherPath);
     // Initiate all required helper objects
     $parsedUrl = new AetherUrlParser();
     $parsedUrl->parseServerArray($_SERVER);
     $this->sl->set('parsedUrl', $parsedUrl);
     // Set autoloader
     // TODO Make this more uesable
     /**
      * Find config folder for project
      * By convention the config folder is always placed at
      * $project/config, while using getcwd() MUST return the
      * $project/www/ folder
      */
     $projectPath = preg_replace("/www\\/?\$/", "", getcwd());
     $this->sl->set("projectRoot", $projectPath);
     if (!defined("PROJECT_PATH")) {
         define("PROJECT_PATH", $projectPath);
     }
     $paths = array($configPath, $projectPath . 'config/autogenerated.config.xml', $projectPath . 'config/aether.config.xml');
     foreach ($paths as $configPath) {
         if (file_exists($configPath)) {
             break;
         }
     }
     try {
         $config = new AetherConfig($configPath);
         $config->matchUrl($parsedUrl);
         $this->sl->set('aetherConfig', $config);
     } catch (AetherMissingFileException $e) {
         /**
          * This means that someone forgot to ensure the config
          * file actually exists
          */
         $msg = "No configuration file for project found: " . $e->getMessage();
         throw new Exception($msg);
     } catch (AetherNoUrlRuleMatchException $e) {
         /**
          * This means parsing of configuration file failed
          * by the simple fact that no rules matches
          * the url. This is due to a bad developer
          */
         $msg = "No rule matched url in config file: " . $e->getMessage();
         throw new Exception($msg);
     }
     $options = $config->getOptions(array('AetherRunningMode' => 'prod', 'cache' => 'off'));
     if ($options['cache'] == 'on') {
         $cacheClass = isset($options['cacheClass']) ? $options['cacheClass'] : 'AetherCache';
         $cacheOptions = isset($options['cacheOptions']) ? $options['cacheOptions'] : [];
         $cache = $this->getCacheObject($cacheClass, $cacheOptions);
         $this->sl->set("cache", $cache);
     }
     /**
      * Make sure base and root for this request is stored
      * in the service locator so it can be made available
      * to the magical $aether array in templates
      */
     $magic = $this->sl->getVector('templateGlobals');
     $magic['base'] = $config->getBase();
     $magic['root'] = $config->getRoot();
     $magic['urlVars'] = $config->getUrlVars();
     $magic['runningMode'] = $options['AetherRunningMode'];
     $magic['requestUri'] = $_SERVER['REQUEST_URI'];
     $magic['domain'] = $_SERVER['HTTP_HOST'];
     if (isset($_SERVER['HTTP_REFERER'])) {
         $magic['referer'] = $_SERVER['HTTP_REFERER'];
     }
     $magic['options'] = $options;
     /**
      * If we are in TEST mode we should prepare a timer object
      * and time everything that happens
      */
     if ($options['AetherRunningMode'] == 'test') {
         // Prepare timer
         $timer = new AetherTimer();
         $timer->start('aether_main');
         $this->sl->set('timer', $timer);
     }
     // Initiate section
     try {
         $searchPath = isset($options['searchpath']) ? $options['searchpath'] : $projectPath;
         AetherSectionFactory::$path = $searchPath;
         $this->section = AetherSectionFactory::create($config->getSection(), $this->sl);
         $this->sl->set('section', $this->section);
         if (isset($timer)) {
             $timer->tick('aether_main', 'section_initiate');
         }
     } catch (Exception $e) {
         // Failed to load section, what to do?
         throw new Exception('Failed horribly: ' . $e->getMessage());
     }
 }