示例#1
0
文件: path.php 项目: poef/ariadne
 /**
  *  Returns the difference between sourcePath and targetPath as a relative path in
  *  such a way that if you append the relative path to the source path and collapse
  *  that, the result is the targetPath.
  *  @param string $targetPath The target path to map to.
  *  @param string $sourcePath The source path to start with.
  *  @return string The relative path from source to target.
  */
 public static function diff($sourcePath, $targetPath)
 {
     $diff = '';
     $targetPath = \arc\path::collapse($targetPath);
     $sourcePath = \arc\path::collapse($sourcePath);
     $commonParent = \arc\path::search($sourcePath, function ($path) use($targetPath, &$diff) {
         if (!\arc\path::isChild($targetPath, $path)) {
             $diff .= '../';
         } else {
             return $path;
         }
     }, false);
     $diff .= substr($targetPath, strlen($commonParent));
     return $diff;
 }
示例#2
0
 function testIsChild()
 {
     $this->assertTrue(\arc\path::isChild('/a/b/', '/a/'));
     $this->assertFalse(\arc\path::isChild('/b/', '/a/'));
 }