本文整理汇总了PHP中Filesystem::listDirectory方法的典型用法代码示例。如果您正苦于以下问题:PHP Filesystem::listDirectory方法的具体用法?PHP Filesystem::listDirectory怎么用?PHP Filesystem::listDirectory使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Filesystem
的用法示例。
在下文中一共展示了Filesystem::listDirectory方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: executeUpdate
protected function executeUpdate(PhabricatorRepository $repository, $local_path)
{
// Run a bunch of sanity checks to detect people checking out repositories
// inside other repositories, making empty directories, pointing the local
// path at some random file or path, etc.
list($err, $stdout) = $repository->execLocalCommand('rev-parse --show-toplevel');
if ($err) {
// Try to raise a more tailored error message in the more common case
// of the user creating an empty directory. (We could try to remove it,
// but might not be able to, and it's much simpler to raise a good
// message than try to navigate those waters.)
if (is_dir($local_path)) {
$files = Filesystem::listDirectory($local_path, $include_hidden = true);
if (!$files) {
throw new Exception("Expected to find a git repository at '{$local_path}', but there " . "is an empty directory there. Remove the directory: the daemon " . "will run 'git clone' for you.");
}
}
throw new Exception("Expected to find a git repository at '{$local_path}', but there is " . "a non-repository directory (with other stuff in it) there. Move or " . "remove this directory (or reconfigure the repository to use a " . "different directory), and then either clone a repository yourself " . "or let the daemon do it.");
} else {
$repo_path = rtrim($stdout, "\n");
if (empty($repo_path)) {
throw new Exception("Expected to find a git repository at '{$local_path}', but " . "there was no result from `git rev-parse --show-toplevel`. " . "Something is misconfigured or broken. The git repository " . "may be inside a '.git/' directory.");
}
if (!Filesystem::pathsAreEquivalent($repo_path, $local_path)) {
throw new Exception("Expected to find repo at '{$local_path}', but the actual " . "git repository root for this directory is '{$repo_path}'. " . "Something is misconfigured. The repository's 'Local Path' should " . "be set to some place where the daemon can check out a working " . "copy, and should not be inside another git repository.");
}
}
// This is a local command, but needs credentials.
$future = $repository->getRemoteCommandFuture('fetch --all --prune');
$future->setCWD($local_path);
$future->resolvex();
}
示例2: loadAllSkinSpecifications
public static function loadAllSkinSpecifications()
{
static $specs;
if ($specs === null) {
$paths = PhabricatorEnv::getEnvConfig('phame.skins');
$base = dirname(phutil_get_library_root('phabricator'));
$specs = array();
foreach ($paths as $path) {
$path = Filesystem::resolvePath($path, $base);
foreach (Filesystem::listDirectory($path) as $skin_directory) {
$skin_path = $path . DIRECTORY_SEPARATOR . $skin_directory;
if (!is_dir($skin_path)) {
continue;
}
$spec = self::loadSkinSpecification($skin_path);
if (!$spec) {
continue;
}
$name = trim($skin_directory, DIRECTORY_SEPARATOR);
$spec->setName($name);
if (isset($specs[$name])) {
$that_dir = $specs[$name]->getRootDirectory();
$this_dir = $spec->getRootDirectory();
throw new Exception(pht("Two skins have the same name ('%s'), in '%s' and '%s'. " . "Rename one or adjust your '%s' configuration.", $name, $this_dir, $that_dir, 'phame.skins'));
}
$specs[$name] = $spec;
}
}
}
return $specs;
}
示例3: processRequest
public function processRequest()
{
$root = dirname(phutil_get_library_root('phabricator'));
require_once $root . '/support/phame/libskin.php';
$this->cssResources = array();
$css = $this->getPath('css/');
if (Filesystem::pathExists($css)) {
foreach (Filesystem::listDirectory($css) as $path) {
if (!preg_match('/.css$/', $path)) {
continue;
}
$this->cssResources[] = phutil_tag('link', array('rel' => 'stylesheet', 'type' => 'text/css', 'href' => $this->getResourceURI('css/' . $path)));
}
}
$map = CelerityResourceMap::getNamedInstance('phabricator');
$resource_symbol = 'syntax-highlighting-css';
$resource_uri = $map->getURIForSymbol($resource_symbol);
$this->cssResources[] = phutil_tag('link', array('rel' => 'stylesheet', 'type' => 'text/css', 'href' => PhabricatorEnv::getCDNURI($resource_uri)));
$this->cssResources = phutil_implode_html("\n", $this->cssResources);
$request = $this->getRequest();
// Render page parts in order so the templates execute in order, if we're
// using templates.
$header = $this->renderHeader();
$content = $this->renderContent($request);
$footer = $this->renderFooter();
if (!$content) {
$content = $this->render404Page();
}
$content = array($header, $content, $footer);
$response = new AphrontWebpageResponse();
$response->setContent(phutil_implode_html("\n", $content));
return $response;
}
示例4: readTestCases
private function readTestCases($path)
{
$files = Filesystem::listDirectory($path, $include_hidden = false);
$tests = array();
foreach ($files as $file) {
$data = Filesystem::readFile($path . $file);
$parts = preg_split('/^~{5,}$/m', $data);
if (count($parts) < 2) {
throw new Exception(pht('Expected test file "%s" to contain an input section in JSON, ' . 'then an expected result section in JSON, with the two sections ' . 'separated by a line of "~~~~~", but the divider is not present ' . 'in the file.', $file));
} else {
if (count($parts) > 2) {
throw new Exception(pht('Expected test file "%s" to contain exactly two sections, ' . 'but it has more than two sections.'));
}
}
list($input, $expect) = $parts;
try {
$input = phutil_json_decode($input);
$expect = phutil_json_decode($expect);
} catch (Exception $ex) {
throw new PhutilProxyException(pht('Exception while decoding test data for test "%s".', $file), $ex);
}
$tests[$file] = array('input' => $input, 'expect' => $expect);
}
return $tests;
}
示例5: getPatches
public function getPatches()
{
$patches = array();
foreach ($this->getOldPatches() as $old_name => $old_patch) {
if (preg_match('/^db\\./', $old_name)) {
$old_patch['name'] = substr($old_name, 3);
$old_patch['type'] = 'db';
} else {
if (empty($old_patch['name'])) {
$old_patch['name'] = $this->getPatchPath($old_name);
}
if (empty($old_patch['type'])) {
$matches = null;
preg_match('/\\.(sql|php)$/', $old_name, $matches);
$old_patch['type'] = $matches[1];
}
}
$patches[$old_name] = $old_patch;
}
$root = dirname(phutil_get_library_root('phabricator'));
$auto_root = $root . '/resources/sql/autopatches/';
$auto_list = Filesystem::listDirectory($auto_root, $include_hidden = false);
sort($auto_list);
foreach ($auto_list as $auto_patch) {
$matches = null;
if (!preg_match('/\\.(sql|php)$/', $auto_patch, $matches)) {
throw new Exception(pht('Unknown patch "%s" in "%s", expected ".php" or ".sql" suffix.', $auto_patch, $auto_root));
}
$patches[$auto_patch] = array('type' => $matches[1], 'name' => $auto_root . $auto_patch);
}
return $patches;
}
示例6: testParseAll
public function testParseAll()
{
$root = dirname(__FILE__) . '/mercurial/';
foreach (Filesystem::listDirectory($root, $hidden = false) as $file) {
$this->parseData(basename($file), Filesystem::readFile($root . '/' . $file));
}
}
示例7: testDifferentialCommitMessageParser
public function testDifferentialCommitMessageParser()
{
$dir = dirname(__FILE__) . '/messages/';
$list = Filesystem::listDirectory($dir, $include_hidden = false);
foreach ($list as $file) {
if (!preg_match('/.txt$/', $file)) {
continue;
}
$data = Filesystem::readFile($dir . $file);
$divider = "~~~~~~~~~~\n";
$parts = explode($divider, $data);
if (count($parts) !== 4) {
throw new Exception(pht('Expected test file "%s" to contain four parts (message, fields, ' . 'output, errors) divided by "%s".', $file, '~~~~~~~~~~'));
}
list($message, $fields, $output, $errors) = $parts;
$fields = phutil_json_decode($fields);
$output = phutil_json_decode($output);
$errors = phutil_json_decode($errors);
$parser = id(new DifferentialCommitMessageParser())->setLabelMap($fields)->setTitleKey('title')->setSummaryKey('summary');
$result_output = $parser->parseCorpus($message);
$result_errors = $parser->getErrors();
$this->assertEqual($output, $result_output);
$this->assertEqual($errors, $result_errors);
}
}
示例8: deleteDocumentsByHash
protected function deleteDocumentsByHash(array $hashes)
{
$root = $this->getConfig('root');
$cache = $this->getPublishCache();
foreach ($hashes as $hash) {
$paths = $cache->getAtomPathsFromCache($hash);
foreach ($paths as $path) {
$abs = $root . DIRECTORY_SEPARATOR . $path;
Filesystem::remove($abs);
// If the parent directory is now empty, clean it up.
$dir = dirname($abs);
while (true) {
if (!Filesystem::isDescendant($dir, $root)) {
// Directory is outside of the root.
break;
}
if (Filesystem::listDirectory($dir)) {
// Directory is not empty.
break;
}
Filesystem::remove($dir);
$dir = dirname($dir);
}
}
$cache->removeAtomPathsFromCache($hash);
$cache->deleteAtomFromIndex($hash);
}
}
示例9: testEngine
public function testEngine()
{
$root = dirname(__FILE__) . '/remarkup/';
foreach (Filesystem::listDirectory($root, $hidden = false) as $file) {
$this->markupText($root . $file);
}
}
示例10: testParseRender
public function testParseRender()
{
$dir = dirname(__FILE__) . '/data/';
foreach (Filesystem::listDirectory($dir, $show_hidden = false) as $file) {
if (!preg_match('/\\.diff$/', $file)) {
continue;
}
$data = Filesystem::readFile($dir . $file);
$opt_file = $dir . $file . '.options';
if (Filesystem::pathExists($opt_file)) {
$options = Filesystem::readFile($opt_file);
$options = json_decode($options, true);
if (!is_array($options)) {
throw new Exception("Invalid options file: {$opt_file}.");
}
} else {
$options = array();
}
foreach (array('one', 'two') as $type) {
$parser = $this->buildChangesetParser($type, $data, $file);
$actual = $parser->render(null, null, array());
$expect = Filesystem::readFile($dir . $file . '.' . $type . '.expect');
$this->assertEqual($expect, (string) $actual, $file . '.' . $type);
}
}
}
示例11: testParser
public function testParser()
{
$root = dirname(__FILE__) . '/data/';
foreach (Filesystem::listDirectory($root, $hidden = false) as $file) {
$this->parseDiff($root . $file);
}
}
示例12: testParseRender
public function testParseRender()
{
$dir = $this->getTestDataDirectory();
foreach (Filesystem::listDirectory($dir, $show_hidden = false) as $file) {
if (!preg_match('/\\.diff$/', $file)) {
continue;
}
$data = Filesystem::readFile($dir . $file);
$opt_file = $dir . $file . '.options';
if (Filesystem::pathExists($opt_file)) {
$options = Filesystem::readFile($opt_file);
try {
$options = phutil_json_decode($options);
} catch (PhutilJSONParserException $ex) {
throw new PhutilProxyException(pht('Invalid options file: %s.', $opt_file), $ex);
}
} else {
$options = array();
}
foreach (array('one', 'two') as $type) {
$this->runParser($type, $data, $file, 'expect');
$this->runParser($type, $data, $file, 'unshielded');
$this->runParser($type, $data, $file, 'whitespace');
}
}
}
示例13: testPHPFragmentLexer
public function testPHPFragmentLexer()
{
$dir = dirname(__FILE__) . '/php';
foreach (Filesystem::listDirectory($dir, $hidden = false) as $file) {
$data = Filesystem::readFile($dir . '/' . $file);
$this->runLexer($file, $data);
}
}
示例14: testShellLexer
public function testShellLexer()
{
$dir = dirname(__FILE__) . '/shell';
foreach (Filesystem::listDirectory($dir, $hidden = false) as $file) {
$data = Filesystem::readFile($dir . '/' . $file);
$data = rtrim($data, "\n");
$this->runLexer($file, $data);
}
}
示例15: testWrap
public function testWrap()
{
$dir = dirname(__FILE__) . '/wrap/';
$files = Filesystem::listDirectory($dir);
foreach ($files as $file) {
if (preg_match('/.txt$/', $file)) {
$this->assertEqual(Filesystem::readFile($dir . $file . '.expect'), phutil_console_wrap(Filesystem::readFile($dir . $file)), $file);
}
}
}