예제 #1
0
 /**
  * @dataProvider findFileProvider
  */
 public function testFindFile(array $composerNamespaces, array $psr4Namespaces, $class, $expectedFile)
 {
     foreach ($composerNamespaces as &$dirs) {
         foreach ($dirs as &$dir) {
             $dir = getcwd() . '/' . $dir;
         }
     }
     unset($dirs);
     unset($dir);
     foreach ($psr4Namespaces as &$dirs) {
         foreach ($dirs as &$dir) {
             $dir = getcwd() . '/' . $dir;
         }
     }
     unset($dirs);
     unset($dir);
     $namespaces = Kwf_Loader::_prepareNamespaces($composerNamespaces, $psr4Namespaces);
     $file = Kwf_Loader::_findFile($class, $namespaces, array());
     $this->assertEquals(getcwd() . '/' . $expectedFile, $file);
 }
예제 #2
0
 private static function _findComponentFile($c)
 {
     static $cache = array();
     if (isset($cache[$c])) {
         return $cache[$c];
     }
     static $dirs;
     if (!isset($dirs)) {
         $dirs = array_reverse(explode(PATH_SEPARATOR, get_include_path()));
     }
     static $namespaces;
     if (!isset($namespaces)) {
         $composerNamespaces = (include VENDOR_PATH . '/composer/autoload_namespaces.php');
         $psr4Namespaces = (include VENDOR_PATH . '/composer/autoload_psr4.php');
         $namespaces = Kwf_Loader::_prepareNamespaces($composerNamespaces, $psr4Namespaces);
     }
     static $classMap;
     if (!isset($classMap)) {
         $classMap = (include VENDOR_PATH . '/composer/autoload_classmap.php');
     }
     $file = Kwf_Loader::_findFile($c, $namespaces, $classMap);
     if (substr($file, 0, strlen(getcwd())) == getcwd()) {
         $path = substr($file, strlen(getcwd()) + 1);
     } else {
         if (KWF_PATH == '..') {
             $cwd = getcwd();
             $parentCwd = substr($cwd, 0, strrpos($cwd, '/'));
             if (substr($file, 0, strlen($parentCwd)) != $parentCwd) {
                 throw new Kwf_Exception("'{$file}' is not in web directory '{$parentCwd}'");
             }
             if ($file == $parentCwd) {
                 $path = '..';
             } else {
                 $path = '../' . substr($file, strlen($parentCwd) + 1);
             }
         } else {
             $file = str_replace('_', '/', $c) . '.php';
             foreach ($dirs as $dir) {
                 $path = $dir . ($dir ? '/' : '') . $file;
                 if (is_file($path)) {
                     break;
                 }
             }
             if (!is_file($path)) {
                 throw new Kwf_Exception("Can't find file");
             }
         }
     }
     $path = str_replace(DIRECTORY_SEPARATOR, '/', $path);
     $cache[$c] = $path;
     return $path;
 }
예제 #3
0
 private static function _findComponentFile($c)
 {
     static $cache = array();
     if (isset($cache[$c])) {
         return $cache[$c];
     }
     static $dirs;
     if (!isset($dirs)) {
         $dirs = array_reverse(explode(PATH_SEPARATOR, get_include_path()));
     }
     static $namespaces;
     if (!isset($namespaces)) {
         $composerNamespaces = (include VENDOR_PATH . '/composer/autoload_namespaces.php');
         $psr4Namespaces = (include VENDOR_PATH . '/composer/autoload_psr4.php');
         $namespaces = Kwf_Loader::_prepareNamespaces($composerNamespaces, $psr4Namespaces);
     }
     static $classMap;
     if (!isset($classMap)) {
         $classMap = (include VENDOR_PATH . '/composer/autoload_classmap.php');
     }
     $file = Kwf_Loader::_findFile($c, $namespaces, $classMap);
     if (substr($file, 0, strlen(getcwd())) == getcwd()) {
         $path = substr($file, strlen(getcwd()) + 1);
     } else {
         $file = str_replace('_', '/', $c) . '.php';
         foreach ($dirs as $dir) {
             $path = $dir . ($dir ? '/' : '') . $file;
             if (is_file($path)) {
                 break;
             }
         }
     }
     $cache[$c] = $path;
     return $path;
 }