function testSearch() { $path = '/a/b/c/'; $count = 0; $result = \arc\path::search($path, function ($parent) use(&$count) { $count++; if ($parent == '/a/') { return true; } }); $this->assertTrue($result); $this->assertTrue($count == 2); $count = 0; $result = \arc\path::search($path, function ($parent) use(&$count) { $count++; if ($parent == '/a/') { return true; } }, false); // reverse order $this->assertTrue($result); $this->assertTrue($count == 3); }
/** * 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; }