Beispiel #1
0
 function testIsRootDir()
 {
     $this->assertTrue(DIRECTORY_SEPARATOR);
     $this->assertFalse(Ethna_Util::isRootDir("/home/ethna/test.txt"));
     $this->assertFalse(Ethna_Util::isRootDir("/home/ethna/"));
     $this->assertFalse(Ethna_Util::isRootDir("/home/ethna"));
     $this->assertFalse(Ethna_Util::isRootDir("/test.txt"));
 }
 function testIsRootDir()
 {
     $this->assertTrue(DIRECTORY_SEPARATOR);
     $util = new Ethna_Util();
     if (OS_WINDOWS) {
         $this->assertTrue($util->isRootDir("C:\\"));
         $this->assertFalse($util->isRootDir("C:\\Program Files\\hoge\\fuga.txt"));
         $this->assertFalse($util->isRootDir("C:\\Program Files\\hoge"));
         $this->assertFalse($util->isRootDir("C:\\hoge\\"));
         $this->assertFalse($util->isRootDir("C:\\hoge.txt"));
     } else {
         $this->assertFalse($util->isRootDir("/home/ethna/test.txt"));
         $this->assertFalse($util->isRootDir("/home/ethna/"));
         $this->assertFalse($util->isRootDir("/home/ethna"));
         $this->assertFalse($util->isRootDir("/test.txt"));
     }
 }
Beispiel #3
0
 /**
  * @test
  */
 public function isRootDir()
 {
     // MEMO(chobie): なしてわざわざチェックしているのか
     $this->assertTrue((bool) DIRECTORY_SEPARATOR);
     if (ETHNA_OS_WINDOWS) {
         $this->assertTrue(Ethna_Util::isRootDir("C:\\"));
         $this->assertFalse(Ethna_Util::isRootDir("C:\\Program Files\\hoge\\fuga.txt"));
         $this->assertFalse(Ethna_Util::isRootDir("C:\\Program Files\\hoge"));
         $this->assertFalse(Ethna_Util::isRootDir("C:\\hoge\\"));
         $this->assertFalse(Ethna_Util::isRootDir("C:\\hoge.txt"));
     } else {
         $this->assertFalse(Ethna_Util::isRootDir("/home/ethna/test.txt"));
         $this->assertFalse(Ethna_Util::isRootDir("/home/ethna/"));
         $this->assertFalse(Ethna_Util::isRootDir("/home/ethna"));
         $this->assertFalse(Ethna_Util::isRootDir("/test.txt"));
     }
 }
 /**
  *  アプリケーションのコントローラファイル/クラスを検索する
  *
  *  @access public
  *  @static
  */
 function &getAppController($app_dir = null)
 {
     static $app_controller = array();
     if (isset($app_controller[$app_dir])) {
         return $app_controller[$app_dir];
     } else {
         if ($app_dir === null) {
             return Ethna::raiseError('$app_dir not specified.');
         }
     }
     $ini_file = null;
     while (is_dir($app_dir)) {
         if (is_file("{$app_dir}/.ethna")) {
             $ini_file = "{$app_dir}/.ethna";
             break;
         }
         $app_dir = dirname($app_dir);
         if (Ethna_Util::isRootDir($app_dir)) {
             break;
         }
     }
     if ($ini_file === null) {
         return Ethna::raiseError('no .ethna file found');
     }
     $macro = parse_ini_file($ini_file);
     if (isset($macro['controller_file']) == false || isset($macro['controller_class']) == false) {
         return Ethna::raiseError('invalid .ethna file');
     }
     $file = $macro['controller_file'];
     $class = $macro['controller_class'];
     $controller_file = "{$app_dir}/{$file}";
     if (is_file($controller_file) == false) {
         return Ethna::raiseError("no such file {$controller_file}");
     }
     include_once $controller_file;
     if (class_exists($class) == false) {
         return Ethna::raiseError("no such class {$class}");
     }
     $global_controller =& $GLOBALS['_Ethna_controller'];
     $app_controller[$app_dir] =& new $class(GATEWAY_CLI);
     $GLOBALS['_Ethna_controller'] =& $global_controller;
     Ethna::clearErrorCallback();
     Ethna::setErrorCallback(array('Ethna_Handle', 'handleError'));
     return $app_controller[$app_dir];
 }