本文整理汇总了PHP中Filesystem::readablePath方法的典型用法代码示例。如果您正苦于以下问题:PHP Filesystem::readablePath方法的具体用法?PHP Filesystem::readablePath怎么用?PHP Filesystem::readablePath使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Filesystem
的用法示例。
在下文中一共展示了Filesystem::readablePath方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getPathArgumentForLinterFuture
protected function getPathArgumentForLinterFuture($path)
{
$full_path = Filesystem::resolvePath($path);
$ret = array($full_path);
// The |path| we get fed needs to be made relative to the project_root,
// otherwise the |engine| won't recognise it.
$relative_path = Filesystem::readablePath($full_path, $this->getProjectRoot());
$changed = $this->getEngine()->getPathChangedLines($relative_path);
if ($changed !== null) {
// Convert the ordered set of changed lines to a list of ranges.
$changed_lines = array_keys(array_filter($changed));
$ranges = array(array($changed_lines[0], $changed_lines[0]));
foreach (array_slice($changed_lines, 1) as $line) {
$range = last($ranges);
if ($range[1] + 1 === $line) {
++$range[1];
$ranges[last_key($ranges)] = $range;
} else {
$ranges[] = array($line, $line);
}
}
foreach ($ranges as $range) {
$ret[] = sprintf('--lines=%d:%d', $range[0], $range[1]);
}
}
return csprintf('%Ls', $ret);
}
示例2: render
public function render()
{
$user = $this->getUser();
$trace = $this->trace;
$libraries = PhutilBootloader::getInstance()->getAllLibraries();
// TODO: Make this configurable?
$path = 'https://secure.phabricator.com/diffusion/%s/browse/master/src/';
$callsigns = array('arcanist' => 'ARC', 'phutil' => 'PHU', 'phabricator' => 'P');
$rows = array();
$depth = count($trace);
foreach ($trace as $part) {
$lib = null;
$file = idx($part, 'file');
$relative = $file;
foreach ($libraries as $library) {
$root = phutil_get_library_root($library);
if (Filesystem::isDescendant($file, $root)) {
$lib = $library;
$relative = Filesystem::readablePath($file, $root);
break;
}
}
$where = '';
if (isset($part['class'])) {
$where .= $part['class'] . '::';
}
if (isset($part['function'])) {
$where .= $part['function'] . '()';
}
if ($file) {
if (isset($callsigns[$lib])) {
$attrs = array('title' => $file);
try {
$attrs['href'] = $user->loadEditorLink('/src/' . $relative, $part['line'], $callsigns[$lib]);
} catch (Exception $ex) {
// The database can be inaccessible.
}
if (empty($attrs['href'])) {
$attrs['href'] = sprintf($path, $callsigns[$lib]) . str_replace(DIRECTORY_SEPARATOR, '/', $relative) . '$' . $part['line'];
$attrs['target'] = '_blank';
}
$file_name = phutil_tag('a', $attrs, $relative);
} else {
$file_name = phutil_tag('span', array('title' => $file), $relative);
}
$file_name = hsprintf('%s : %d', $file_name, $part['line']);
} else {
$file_name = phutil_tag('em', array(), '(Internal)');
}
$rows[] = array($depth--, $lib, $file_name, $where);
}
$table = new AphrontTableView($rows);
$table->setHeaders(array(pht('Depth'), pht('Library'), pht('File'), pht('Where')));
$table->setColumnClasses(array('n', '', '', 'wide'));
return phutil_tag('div', array('class' => 'exception-trace'), $table->render());
}
示例3: buildFileContentHashes
public function buildFileContentHashes()
{
$files = array();
$root = $this->getConfiguration()->getProjectRoot();
$finder = new FileFinder($root . '/src');
$finder->excludePath('*/.*')->withSuffix('js')->withType('f')->setGenerateChecksums(true);
foreach ($finder->find() as $path => $hash) {
$path = Filesystem::readablePath($path, $root);
$files[$path] = $hash;
}
return $files;
}
示例4: findResourcesWithSuffixes
private function findResourcesWithSuffixes(array $suffixes)
{
$root = $this->getPathToResources();
$finder = id(new FileFinder($root))->withType('f')->withFollowSymlinks(true)->setGenerateChecksums(true);
foreach ($suffixes as $suffix) {
$finder->withSuffix($suffix);
}
$raw_files = $finder->find();
$results = array();
foreach ($raw_files as $path => $hash) {
$readable = Filesystem::readablePath($path, $root);
$results[$readable] = $hash;
}
return $results;
}
示例5: rebuildResources
/**
* Rebuild the resource map for a resource source.
*
* @param CelerityPhysicalResources Resource source to rebuild.
* @return void
*/
private function rebuildResources(CelerityPhysicalResources $resources)
{
$this->log(pht('Rebuilding resource source "%s" (%s)...', $resources->getName(), get_class($resources)));
$binary_map = $this->rebuildBinaryResources($resources);
$this->log(pht('Found %d binary resources.', new PhutilNumber(count($binary_map))));
$xformer = id(new CelerityResourceTransformer())->setMinify(false)->setRawURIMap(ipull($binary_map, 'uri'));
$text_map = $this->rebuildTextResources($resources, $xformer);
$this->log(pht('Found %d text resources.', new PhutilNumber(count($text_map))));
$resource_graph = array();
$requires_map = array();
$symbol_map = array();
foreach ($text_map as $name => $info) {
if (isset($info['provides'])) {
$symbol_map[$info['provides']] = $info['hash'];
// We only need to check for cycles and add this to the requires map
// if it actually requires anything.
if (!empty($info['requires'])) {
$resource_graph[$info['provides']] = $info['requires'];
$requires_map[$info['hash']] = $info['requires'];
}
}
}
$this->detectGraphCycles($resource_graph);
$name_map = ipull($binary_map, 'hash') + ipull($text_map, 'hash');
$hash_map = array_flip($name_map);
$package_map = $this->rebuildPackages($resources, $symbol_map, $hash_map);
$this->log(pht('Found %d packages.', new PhutilNumber(count($package_map))));
$component_map = array();
foreach ($package_map as $package_name => $package_info) {
foreach ($package_info['symbols'] as $symbol) {
$component_map[$symbol] = $package_name;
}
}
$name_map = $this->mergeNameMaps(array(array(pht('Binary'), ipull($binary_map, 'hash')), array(pht('Text'), ipull($text_map, 'hash')), array(pht('Package'), ipull($package_map, 'hash'))));
$package_map = ipull($package_map, 'symbols');
ksort($name_map);
ksort($symbol_map);
ksort($requires_map);
ksort($package_map);
$map_content = $this->formatMapContent(array('names' => $name_map, 'symbols' => $symbol_map, 'requires' => $requires_map, 'packages' => $package_map));
$map_path = $resources->getPathToMap();
$this->log(pht('Writing map "%s".', Filesystem::readablePath($map_path)));
Filesystem::writeFile($map_path, $map_content);
}
示例6: run
public function run()
{
$repository_api = $this->getRepositoryAPI();
$project_root = $this->getWorkingCopy()->getProjectRoot();
$in_paths = $this->getArgument('paths');
$paths = array();
foreach ($in_paths as $key => $path) {
$full_path = Filesystem::resolvePath($path);
$paths[$key] = Filesystem::readablePath($full_path, $project_root);
}
if (!$paths) {
throw new ArcanistUsageException("Specify a path to browse");
}
$base_uri = $this->getBaseURI();
$browser = $this->getBrowserCommand();
foreach ($paths as $path) {
$ret_code = phutil_passthru("%s %s", $browser, $base_uri . $path);
if ($ret_code) {
throw new ArcanistUsageException("It seems we failed to open the browser; Perhaps you should try to " . "set the 'browser' config option. The command we tried to use was: " . $browser);
}
}
return 0;
}
示例7: addLintMessage
protected final function addLintMessage(ArcanistLintMessage $message)
{
$root = $this->getProjectRoot();
$path = Filesystem::resolvePath($message->getPath(), $root);
$message->setPath(Filesystem::readablePath($path, $root));
$this->messages[] = $message;
return $message;
}
示例8: loadSourceFileMap
/**
* Build a map of all source files in a library to hashes of their content.
* Returns an array like this:
*
* array(
* 'src/parser/ExampleParser.php' => '60b725f10c9c85c70d97880dfe8191b3',
* // ...
* );
*
* @return dict Map of library-relative paths to content hashes.
* @task source
*/
private function loadSourceFileMap()
{
$root = $this->getPath();
$init = $this->getPathForLibraryInit();
if (!Filesystem::pathExists($init)) {
throw new Exception(pht("Provided path '%s' is not a %s library.", $root, 'phutil'));
}
$files = id(new FileFinder($root))->withType('f')->withSuffix('php')->excludePath('*/.*')->setGenerateChecksums(true)->find();
$map = array();
foreach ($files as $file => $hash) {
$file = Filesystem::readablePath($file, $root);
$file = ltrim($file, '/');
if (dirname($file) == '.') {
// We don't permit normal source files at the root level, so just ignore
// them; they're special library files.
continue;
}
if (dirname($file) == 'extensions') {
// Ignore files in the extensions/ directory.
continue;
}
// We include also filename in the hash to handle cases when the file is
// moved without modifying its content.
$map[$file] = md5($hash . $file);
}
return $map;
}
示例9: getTestPaths
/**
* Returns the paths in which we should look for tests to execute.
*
* @return list<string> A list of paths in which to search for test cases.
*/
public function getTestPaths()
{
$root = $this->getWorkingCopy()->getProjectRoot();
$paths = array();
foreach ($this->getPaths() as $path) {
$library_root = phutil_get_library_root_for_path($path);
if (!$library_root) {
continue;
}
$library_name = phutil_get_library_name_for_root($library_root);
if (!$library_name) {
throw new Exception(pht("Attempting to run unit tests on a libphutil library which has " . "not been loaded, at:\n\n" . " %s\n\n" . "This probably means one of two things:\n\n" . " - You may need to add this library to %s.\n" . " - You may be running tests on a copy of libphutil or " . "arcanist using a different copy of libphutil or arcanist. " . "This operation is not supported.\n", $library_root, '.arcconfig.'));
}
$path = Filesystem::resolvePath($path, $root);
$library_path = Filesystem::readablePath($path, $library_root);
if (!Filesystem::isDescendant($path, $library_root)) {
// We have encountered some kind of symlink maze -- for instance, $path
// is some symlink living outside the library that links into some file
// inside the library. Just ignore these cases, since the affected file
// does not actually lie within the library.
continue;
}
if (is_file($path) && preg_match('@(?:^|/)__tests__/@', $path)) {
$paths[$library_name . ':' . $library_path] = array('library' => $library_name, 'path' => $library_path);
continue;
}
foreach (Filesystem::walkToRoot($path, $library_root) as $subpath) {
if ($subpath == $library_root) {
$paths[$library_name . ':.'] = array('library' => $library_name, 'path' => '__tests__/');
} else {
$library_subpath = Filesystem::readablePath($subpath, $library_root);
$paths[$library_name . ':' . $library_subpath] = array('library' => $library_name, 'path' => $library_subpath . '/__tests__/');
}
}
}
return $paths;
}
示例10: renderStackTrace
private function renderStackTrace($trace)
{
$libraries = PhutilBootloader::getInstance()->getAllLibraries();
// TODO: Make this configurable?
$host = 'https://secure.phabricator.com';
$browse = array('arcanist' => $host . '/diffusion/ARC/browse/origin:master/src/', 'phutil' => $host . '/diffusion/PHU/browse/origin:master/src/', 'phabricator' => $host . '/diffusion/P/browse/origin:master/src/');
$rows = array();
$depth = count($trace);
foreach ($trace as $part) {
$lib = null;
$file = idx($part, 'file');
$relative = $file;
foreach ($libraries as $library) {
$root = phutil_get_library_root($library);
if (Filesystem::isDescendant($file, $root)) {
$lib = $library;
$relative = Filesystem::readablePath($file, $root);
break;
}
}
$where = '';
if (isset($part['class'])) {
$where .= $part['class'] . '::';
}
if (isset($part['function'])) {
$where .= $part['function'] . '()';
}
if ($file) {
if (isset($browse[$lib])) {
$file_name = phutil_render_tag('a', array('href' => $browse[$lib] . $relative . '$' . $part['line'], 'title' => $file, 'target' => '_blank'), phutil_escape_html($relative));
} else {
$file_name = phutil_render_tag('span', array('title' => $file), phutil_escape_html($relative));
}
$file_name = $file_name . ' : ' . (int) $part['line'];
} else {
$file_name = '<em>(Internal)</em>';
}
$rows[] = array($depth--, phutil_escape_html($lib), $file_name, phutil_escape_html($where));
}
$table = new AphrontTableView($rows);
$table->setHeaders(array('Depth', 'Library', 'File', 'Where'));
$table->setColumnClasses(array('n', '', '', 'wide'));
return '<div class="exception-trace">' . '<div class="exception-trace-header">Stack Trace</div>' . $table->render() . '</div>';
}
示例11: selectPathsForWorkflow
/**
* Workflows like 'lint' and 'unit' operate on a list of working copy paths.
* The user can either specify the paths explicitly ("a.js b.php"), or by
* specfifying a revision ("--rev a3f10f1f") to select all paths modified
* since that revision, or by omitting both and letting arc choose the
* default relative revision.
*
* This method takes the user's selections and returns the paths that the
* workflow should act upon.
*
* @param list List of explicitly provided paths.
* @param string|null Revision name, if provided.
* @param mask Mask of ArcanistRepositoryAPI flags to exclude.
* Defaults to ArcanistRepositoryAPI::FLAG_UNTRACKED.
* @return list List of paths the workflow should act on.
*/
protected function selectPathsForWorkflow(array $paths, $rev, $omit_mask = null)
{
if ($omit_mask === null) {
$omit_mask = ArcanistRepositoryAPI::FLAG_UNTRACKED;
}
if ($paths) {
$working_copy = $this->getWorkingCopy();
foreach ($paths as $key => $path) {
$full_path = Filesystem::resolvePath($path);
if (!Filesystem::pathExists($full_path)) {
throw new ArcanistUsageException("Path '{$path}' does not exist!");
}
$relative_path = Filesystem::readablePath($full_path, $working_copy->getProjectRoot());
$paths[$key] = $relative_path;
}
} else {
$repository_api = $this->getRepositoryAPI();
if ($rev) {
$this->parseBaseCommitArgument(array($rev));
}
$paths = $repository_api->getWorkingCopyStatus();
foreach ($paths as $path => $flags) {
if ($flags & $omit_mask) {
unset($paths[$path]);
}
}
$paths = array_keys($paths);
}
return array_values($paths);
}
示例12: renderStackTrace
private function renderStackTrace($trace, PhabricatorUser $user)
{
$libraries = PhutilBootloader::getInstance()->getAllLibraries();
$version = PhabricatorEnv::getEnvConfig('phabricator.version');
if (preg_match('/[^a-f0-9]/i', $version)) {
$version = '';
}
// TODO: Make this configurable?
$path = 'https://secure.phabricator.com/diffusion/%s/browse/master/src/';
$callsigns = array('arcanist' => 'ARC', 'phutil' => 'PHU', 'phabricator' => 'P');
$rows = array();
$depth = count($trace);
foreach ($trace as $part) {
$lib = null;
$file = idx($part, 'file');
$relative = $file;
foreach ($libraries as $library) {
$root = phutil_get_library_root($library);
if (Filesystem::isDescendant($file, $root)) {
$lib = $library;
$relative = Filesystem::readablePath($file, $root);
break;
}
}
$where = '';
if (isset($part['class'])) {
$where .= $part['class'] . '::';
}
if (isset($part['function'])) {
$where .= $part['function'] . '()';
}
if ($file) {
if (isset($callsigns[$lib])) {
$attrs = array('title' => $file);
try {
$attrs['href'] = $user->loadEditorLink('/src/' . $relative, $part['line'], $callsigns[$lib]);
} catch (Exception $ex) {
// The database can be inaccessible.
}
if (empty($attrs['href'])) {
$attrs['href'] = sprintf($path, $callsigns[$lib]) . str_replace(DIRECTORY_SEPARATOR, '/', $relative) . ($version && $lib == 'phabricator' ? ';' . $version : '') . '$' . $part['line'];
$attrs['target'] = '_blank';
}
$file_name = phutil_render_tag('a', $attrs, phutil_escape_html($relative));
} else {
$file_name = phutil_render_tag('span', array('title' => $file), phutil_escape_html($relative));
}
$file_name = $file_name . ' : ' . (int) $part['line'];
} else {
$file_name = '<em>(Internal)</em>';
}
$rows[] = array($depth--, phutil_escape_html($lib), $file_name, phutil_escape_html($where));
}
$table = new AphrontTableView($rows);
$table->setHeaders(array('Depth', 'Library', 'File', 'Where'));
$table->setColumnClasses(array('n', '', '', 'wide'));
return '<div class="exception-trace">' . '<div class="exception-trace-header">Stack Trace</div>' . $table->render() . '</div>';
}
示例13: addLintMessage
protected function addLintMessage(ArcanistLintMessage $message)
{
if (!$this->getEngine()->getCommitHookMode()) {
$root = $this->getEngine()->getWorkingCopy()->getProjectRoot();
$path = Filesystem::resolvePath($message->getPath(), $root);
$message->setPath(Filesystem::readablePath($path, $root));
}
$this->messages[] = $message;
return $message;
}
示例14: substr
$uri = '/res/' . substr($hash, 0, 8) . $path;
$runtime_map[$path] = array('hash' => $hash, 'uri' => $uri, 'disk' => $path, 'type' => $type);
}
echo "\n";
$xformer = id(new CelerityResourceTransformer())->setMinify(false)->setRawResourceMap($runtime_map);
echo "Finding transformable static resources...\n";
$finder = id(new FileFinder($root))->withType('f')->withSuffix('js')->withSuffix('css')->withFollowSymlinks(true)->setGenerateChecksums(true);
if (!$with_custom) {
$finder->excludePath('./rsrc/custom');
}
$files = $finder->find();
echo "Processing " . count($files) . " files";
$file_map = array();
foreach ($files as $path => $raw_hash) {
echo ".";
$path = '/' . Filesystem::readablePath($path, $root);
$data = Filesystem::readFile($root . $path);
$data = $xformer->transformResource($path, $data);
$hash = md5($data);
$hash = md5($hash . $path . $resource_hash);
$file_map[$path] = array('hash' => $hash, 'disk' => $path);
}
echo "\n";
$resource_graph = array();
$hash_map = array();
$parser = new PhutilDocblockParser();
foreach ($file_map as $path => $info) {
$type = CelerityResourceTransformer::getResourceType($path);
$data = Filesystem::readFile($root . $info['disk']);
$matches = array();
$ok = preg_match('@/[*][*].*?[*]/@s', $data, $matches);
示例15: loadSourceFileMap
/**
* Build a map of all source files in a library to hashes of their content.
* Returns an array like this:
*
* array(
* 'src/parser/ExampleParser.php' => '60b725f10c9c85c70d97880dfe8191b3',
* // ...
* );
*
* @return dict Map of library-relative paths to content hashes.
* @task source
*/
private function loadSourceFileMap()
{
$root = $this->getPath();
$init = $this->getPathForLibraryInit();
if (!Filesystem::pathExists($init)) {
throw new Exception("Provided path '{$root}' is not a phutil library.");
}
$files = id(new FileFinder($root))->withType('f')->withSuffix('php')->excludePath('*/.*')->setGenerateChecksums(true)->find();
$map = array();
foreach ($files as $file => $hash) {
if (basename($file) == '__init__.php') {
// TODO: Remove this once we kill __init__.php. This just makes the
// script run faster until we do, so testing and development is less
// annoying.
continue;
}
$file = Filesystem::readablePath($file, $root);
$file = ltrim($file, '/');
if (dirname($file) == '.') {
// We don't permit normal source files at the root level, so just ignore
// them; they're special library files.
continue;
}
// We include also filename in the hash to handle cases when the file is
// moved without modifying its content.
$map[$file] = md5($hash . $file);
}
return $map;
}