public function testRelative3()
 {
     $result = ezcBaseFile::calculateRelativePath('/foo/1/2/php.php', '/foo/bar');
     self::assertEquals('..' . DIRECTORY_SEPARATOR . '1' . DIRECTORY_SEPARATOR . '2' . DIRECTORY_SEPARATOR . 'php.php', $result);
     $result = ezcBaseFile::calculateRelativePath('/foo/bar/php.php', '/foo/bar');
     self::assertEquals('php.php', $result);
     $result = ezcBaseFile::calculateRelativePath('/php.php', '/foo/bar/1/2');
     self::assertEquals('..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'php.php', $result);
     $result = ezcBaseFile::calculateRelativePath('/bar/php.php', '/foo/bar/1/2');
     self::assertEquals('..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'bar' . DIRECTORY_SEPARATOR . 'php.php', $result);
 }
 /**
  * Extracts class information from PHP sourcecode.
  * @return array (className=>filename)
  */
 protected function getClassFileList($fileList, $mode)
 {
     $retArray = array();
     $this->log("Searching for classes (tokenizing).");
     $statArray = array('nFiles' => count($fileList), 'classCount' => 0, 'classAdded' => 0);
     $this->setStatArray(self::OUTPUT_PROGRESS_PHASE2, $statArray);
     if (count($fileList)) {
         $this->startProgressOutput(self::OUTPUT_PROGRESS_PHASE2);
         // Compatibility with PHP 5.2 where T_NAMESPACE constant is not available
         // Assigning the constant value to $tNamespace
         // 377 is the value for T_NAMESPACE in PHP 5.3.x
         $tNamespace = defined('T_NAMESPACE') ? T_NAMESPACE : self::UNDEFINED_TOKEN;
         // Traits support, see http://issues.ez.no/19028
         $tTrait = defined('T_TRAIT') ? T_TRAIT : self::UNDEFINED_TOKEN;
         foreach ($fileList as $file) {
             $this->updateProgressOutput(self::OUTPUT_PROGRESS_PHASE2);
             if ($mode === self::MODE_SINGLE_EXTENSION) {
                 $file = getcwd() . DIRECTORY_SEPARATOR . $this->options->basePath . DIRECTORY_SEPARATOR . $file;
             }
             $tokens = @token_get_all(file_get_contents($file));
             $namespace = null;
             foreach ($tokens as $key => $token) {
                 if (is_array($token)) {
                     switch ($token[0]) {
                         case self::UNDEFINED_TOKEN:
                             // Unsupported token, do nothing
                             break;
                             // Store namespace name, if applicable, to concatenate with class name
                         // Store namespace name, if applicable, to concatenate with class name
                         case $tNamespace:
                             // NAMESPACE_TOKEN - WHITESPACE_TOKEN - TEXT_TOKENS (containing namespace name)
                             $offset = $key + 2;
                             $namespace = "";
                             while ($tokens[$offset] !== ";" && $tokens[$offset] !== "{") {
                                 if (is_array($tokens[$offset])) {
                                     $namespace .= $tokens[$offset][1];
                                 }
                                 $offset++;
                             }
                             $namespace = trim(addcslashes($namespace, '\\'));
                             break;
                         case T_CLASS:
                         case T_INTERFACE:
                         case $tTrait:
                             // Increment stat for found class.
                             $this->incrementProgressStat(self::OUTPUT_PROGRESS_PHASE2, 'classCount');
                             // CLASS_TOKEN - WHITESPACE_TOKEN - TEXT_TOKEN (containing class name)
                             $className = $tokens[$key + 2][1];
                             if ($namespace !== null) {
                                 $className = "{$namespace}\\\\{$className}";
                             }
                             $filePath = $file;
                             if ($mode === self::MODE_SINGLE_EXTENSION) {
                                 $filePath = ezcBaseFile::calculateRelativePath($filePath, getcwd() . DIRECTORY_SEPARATOR . $this->options->basePath);
                             }
                             // make sure we store cross-platform file system paths,
                             // using a forward slash as directory separator
                             if (DIRECTORY_SEPARATOR != '/') {
                                 $filePath = str_replace(DIRECTORY_SEPARATOR, '/', $filePath);
                             }
                             // Here there are two code paths.
                             // MODE_KERNEL_OVERRIDE will only add a class if
                             // it exists in the MODE_KERNEL autoload array.
                             // All other modes will only add a class if the
                             // class name is unique.
                             $addClass = $this->classCanBeAdded($className, $filePath, $mode, $retArray);
                             if ($addClass) {
                                 // increment stat for actually added number of classes.
                                 $this->incrementProgressStat(self::OUTPUT_PROGRESS_PHASE2, 'classAdded');
                                 $retArray[$className] = $filePath;
                             }
                             break;
                     }
                 }
             }
         }
         $this->stopProgressOutput(self::OUTPUT_PROGRESS_PHASE2);
         ksort($retArray);
     }
     if ($this->output !== null) {
         extract($this->getStatArray(self::OUTPUT_PROGRESS_PHASE2));
         $this->log("Found {$classCount} classes, added {$classAdded} of them to the autoload array.");
     }
     return $retArray;
 }
 public function testEqual()
 {
     self::assertEquals('.', ezcBaseFile::calculateRelativePath('/bar/php.php', '/bar/php.php'));
     self::assertEquals('.', ezcBaseFile::calculateRelativePath('C:\\workspace\\xxx_upgrade', 'C:\\workspace\\xxx_upgrade'));
 }
 /**
  * Extracts class information from PHP sourcecode.
  * @return array (className=>filename)
  */
 protected function getClassFileList($fileList, $mode)
 {
     $retArray = array();
     $this->log("Searching for classes (tokenizing).");
     $statArray = array('nFiles' => count($fileList), 'classCount' => 0, 'classAdded' => 0);
     $this->setStatArray(self::OUTPUT_PROGRESS_PHASE2, $statArray);
     $this->startProgressOutput(self::OUTPUT_PROGRESS_PHASE2);
     foreach ($fileList as $file) {
         $this->updateProgressOutput(self::OUTPUT_PROGRESS_PHASE2);
         if ($mode === self::MODE_SINGLE_EXTENSION) {
             $file = getcwd() . DIRECTORY_SEPARATOR . $this->options->basePath . DIRECTORY_SEPARATOR . $file;
         }
         $tokens = @token_get_all(file_get_contents($file));
         foreach ($tokens as $key => $token) {
             if (is_array($token)) {
                 switch ($token[0]) {
                     case T_CLASS:
                     case T_INTERFACE:
                         // Increment stat for found class.
                         $this->incrementProgressStat(self::OUTPUT_PROGRESS_PHASE2, 'classCount');
                         // CLASS_TOKEN - WHITESPACE_TOKEN - TEXT_TOKEN (containing class name)
                         $className = $tokens[$key + 2][1];
                         $filePath = $file;
                         if ($mode === self::MODE_SINGLE_EXTENSION) {
                             $filePath = ezcBaseFile::calculateRelativePath($filePath, getcwd() . DIRECTORY_SEPARATOR . $this->options->basePath);
                         }
                         // make sure we store cross-platform file system paths,
                         // using a forward slash as directory separator
                         if (DIRECTORY_SEPARATOR != '/') {
                             $filePath = str_replace(DIRECTORY_SEPARATOR, '/', $filePath);
                         }
                         // Here there are two code paths.
                         // MODE_KERNEL_OVERRIDE will only add a class if
                         // it exists in the MODE_KERNEL autoload array.
                         // All other modes will only add a class if the
                         // class name is unique.
                         $addClass = $this->classCanBeAdded($className, $filePath, $mode, $retArray);
                         if ($addClass) {
                             // increment stat for actually added number of classes.
                             $this->incrementProgressStat(self::OUTPUT_PROGRESS_PHASE2, 'classAdded');
                             $retArray[$className] = $filePath;
                         }
                         break;
                 }
             }
         }
     }
     $this->stopProgressOutput(self::OUTPUT_PROGRESS_PHASE2);
     if ($this->output !== null) {
         extract($this->getStatArray(self::OUTPUT_PROGRESS_PHASE2));
         $this->log("Found {$classCount} classes, added {$classAdded} of them to the autoload array.");
     }
     ksort($retArray);
     return $retArray;
 }