本文整理汇总了PHP中Filesystem::pathExists方法的典型用法代码示例。如果您正苦于以下问题:PHP Filesystem::pathExists方法的具体用法?PHP Filesystem::pathExists怎么用?PHP Filesystem::pathExists使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Filesystem
的用法示例。
在下文中一共展示了Filesystem::pathExists方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: deleteFile
/**
* Deletes the file from local disk, if it exists.
* @task impl
*/
public function deleteFile($handle)
{
$path = $this->getLocalDiskFileStorageFullPath($handle);
if (Filesystem::pathExists($path)) {
Filesystem::remove($path);
}
}
示例2: execute
public function execute(PhutilArgumentParser $args)
{
$console = PhutilConsole::getConsole();
$public_keyfile = $args->getArg('public');
if (!strlen($public_keyfile)) {
throw new PhutilArgumentUsageException(pht('You must specify the path to a public keyfile with %s.', '--public'));
}
if (!Filesystem::pathExists($public_keyfile)) {
throw new PhutilArgumentUsageException(pht('Specified public keyfile "%s" does not exist!', $public_keyfile));
}
$public_key = Filesystem::readFile($public_keyfile);
$pkcs8_keyfile = $args->getArg('pkcs8');
if (!strlen($pkcs8_keyfile)) {
throw new PhutilArgumentUsageException(pht('You must specify the path to a pkcs8 keyfile with %s.', '--pkc8s'));
}
if (!Filesystem::pathExists($pkcs8_keyfile)) {
throw new PhutilArgumentUsageException(pht('Specified pkcs8 keyfile "%s" does not exist!', $pkcs8_keyfile));
}
$pkcs8_key = Filesystem::readFile($pkcs8_keyfile);
$warning = pht('Adding a PKCS8 keyfile to the cache can be very dangerous. If the ' . 'PKCS8 file really encodes a different public key than the one ' . 'specified, an attacker could use it to gain unauthorized access.' . "\n\n" . 'Generally, you should use this option only in a development ' . 'environment where ssh-keygen is broken and it is inconvenient to ' . 'fix it, and only if you are certain you understand the risks. You ' . 'should never cache a PKCS8 file you did not generate yourself.');
$console->writeOut("%s\n", phutil_console_wrap($warning));
$prompt = pht('Really trust this PKCS8 keyfile?');
if (!phutil_console_confirm($prompt)) {
throw new PhutilArgumentUsageException(pht('Aborted workflow.'));
}
$key = PhabricatorAuthSSHPublicKey::newFromRawKey($public_key);
$key->forcePopulatePKCS8Cache($pkcs8_key);
$console->writeOut("%s\n", pht('Cached PKCS8 key for public key.'));
return 0;
}
示例3: run
public function run()
{
$roots = array();
$roots['libphutil'] = dirname(phutil_get_library_root('phutil'));
$roots['arcanist'] = dirname(phutil_get_library_root('arcanist'));
foreach ($roots as $lib => $root) {
echo "Upgrading {$lib}...\n";
if (!Filesystem::pathExists($root . '/.git')) {
throw new ArcanistUsageException("{$lib} must be in its git working copy to be automatically " . "upgraded. This copy of {$lib} (in '{$root}') is not in a git " . "working copy.");
}
$working_copy = ArcanistWorkingCopyIdentity::newFromPath($root);
$repository_api = ArcanistRepositoryAPI::newAPIFromWorkingCopyIdentity($working_copy);
// Force the range to HEAD^..HEAD, which is meaningless but keeps us
// from triggering "base" rules or other commit range resolution rules
// that might prompt the user when we pull the working copy status.
$repository_api->setRelativeCommit('HEAD^');
$this->setRepositoryAPI($repository_api);
// Require no local changes.
$this->requireCleanWorkingCopy();
// Require the library be on master.
$branch_name = $repository_api->getBranchName();
if ($branch_name != 'master') {
throw new ArcanistUsageException("{$lib} must be on branch 'master' to be automatically upgraded. " . "This copy of {$lib} (in '{$root}') is on branch '{$branch_name}'.");
}
chdir($root);
try {
phutil_passthru('git pull --rebase');
} catch (Exception $ex) {
phutil_passthru('git rebase --abort');
throw $ex;
}
}
echo phutil_console_wrap(phutil_console_format("**Updated!** Your copy of arc is now up to date.\n"));
return 0;
}
示例4: phabricator_read_config_file
function phabricator_read_config_file($original_config)
{
$root = dirname(dirname(__FILE__));
// Accept either "myconfig" (preferred) or "myconfig.conf.php".
$config = preg_replace('/\\.conf\\.php$/', '', $original_config);
$full_config_path = $root . '/conf/' . $config . '.conf.php';
// Make sure config file errors are reported.
$old_error_level = error_reporting(E_ALL | E_STRICT);
$old_display_errors = ini_get('display_errors');
ini_set('display_errors', 1);
ob_start();
$conf = (include $full_config_path);
$errors = ob_get_clean();
error_reporting($old_error_level);
ini_set('display_errors', $old_display_errors);
if ($conf === false) {
if (!Filesystem::pathExists($full_config_path)) {
$files = id(new FileFinder($root . '/conf/'))->withType('f')->withSuffix('conf.php')->withFollowSymlinks(true)->find();
foreach ($files as $key => $file) {
$file = trim($file, './');
$files[$key] = preg_replace('/\\.conf\\.php$/', '', $file);
}
$files = " " . implode("\n ", $files);
throw new Exception("CONFIGURATION ERROR\n" . "Config file '{$original_config}' does not exist. Valid config files " . "are:\n\n" . $files);
}
throw new Exception("Failed to read config file '{$config}': {$errors}");
}
return $conf;
}
示例5: executeChecks
/**
* @phutil-external-symbol class PhabricatorStartup
*/
protected function executeChecks()
{
$upload_limit = PhabricatorEnv::getEnvConfig('storage.upload-size-limit');
if (!$upload_limit) {
$message = pht('The Phabricator file upload limit is not configured. You may only ' . 'be able to upload very small files until you configure it, because ' . 'some PHP default limits are very low (as low as 2MB).');
$this->newIssue('config.storage.upload-size-limit')->setShortName(pht('Upload Limit'))->setName(pht('Upload Limit Not Yet Configured'))->setMessage($message)->addPhabricatorConfig('storage.upload-size-limit');
} else {
$memory_limit = PhabricatorStartup::getOldMemoryLimit();
if ($memory_limit && (int) $memory_limit > 0) {
$memory_limit_bytes = phutil_parse_bytes($memory_limit);
$memory_usage_bytes = memory_get_usage();
$upload_limit_bytes = phutil_parse_bytes($upload_limit);
$available_bytes = $memory_limit_bytes - $memory_usage_bytes;
if ($upload_limit_bytes > $available_bytes) {
$summary = pht('Your PHP memory limit is configured in a way that may prevent ' . 'you from uploading large files.');
$message = pht('When you upload a file via drag-and-drop or the API, the entire ' . 'file is buffered into memory before being written to permanent ' . 'storage. Phabricator needs memory available to store these ' . 'files while they are uploaded, but PHP is currently configured ' . 'to limit the available memory.' . "\n\n" . 'Your Phabricator %s is currently set to a larger value (%s) than ' . 'the amount of available memory (%s) that a PHP process has ' . 'available to use, so uploads via drag-and-drop and the API will ' . 'hit the memory limit before they hit other limits.' . "\n\n" . '(Note that the application itself must also fit in available ' . 'memory, so not all of the memory under the memory limit is ' . 'available for buffering file uploads.)' . "\n\n" . "The easiest way to resolve this issue is to set %s to %s in your " . "PHP configuration, to disable the memory limit. There is " . "usually little or no value to using this option to limit " . "Phabricator process memory." . "\n\n" . "You can also increase the limit, or decrease %s, or ignore this " . "issue and accept that these upload mechanisms will be limited " . "in the size of files they can handle.", phutil_tag('tt', array(), 'storage.upload-size-limit'), phutil_format_bytes($upload_limit_bytes), phutil_format_bytes($available_bytes), phutil_tag('tt', array(), 'memory_limit'), phutil_tag('tt', array(), '-1'), phutil_tag('tt', array(), 'storage.upload-size-limit'));
$this->newIssue('php.memory_limit.upload')->setName(pht('Memory Limit Restricts File Uploads'))->setSummary($summary)->setMessage($message)->addPHPConfig('memory_limit')->addPHPConfigOriginalValue('memory_limit', $memory_limit)->addPhabricatorConfig('storage.upload-size-limit');
}
}
}
$local_path = PhabricatorEnv::getEnvConfig('storage.local-disk.path');
if (!$local_path) {
return;
}
if (!Filesystem::pathExists($local_path) || !is_readable($local_path) || !is_writable($local_path)) {
$message = pht('Configured location for storing uploaded files on disk ("%s") does ' . 'not exist, or is not readable or writable. Verify the directory ' . 'exists and is readable and writable by the webserver.', $local_path);
$this->newIssue('config.storage.local-disk.path')->setShortName(pht('Local Disk Storage'))->setName(pht('Local Disk Storage Not Readable/Writable'))->setMessage($message)->addPhabricatorConfig('storage.local-disk.path');
}
}
示例6: executeChecks
protected function executeChecks()
{
$adapter = PhabricatorEnv::getEnvConfig('metamta.mail-adapter');
switch ($adapter) {
case 'PhabricatorMailImplementationPHPMailerLiteAdapter':
if (!Filesystem::pathExists('/usr/bin/sendmail') && !Filesystem::pathExists('/usr/sbin/sendmail')) {
$message = pht('Mail is configured to send via sendmail, but this system has ' . 'no sendmail binary. Install sendmail or choose a different ' . 'mail adapter.');
$this->newIssue('config.metamta.mail-adapter')->setShortName(pht('Missing Sendmail'))->setName(pht('No Sendmail Binary Found'))->setMessage($message)->addRelatedPhabricatorConfig('metamta.mail-adapter');
}
break;
case 'PhabricatorMailImplementationAmazonSESAdapter':
if (PhabricatorEnv::getEnvConfig('metamta.can-send-as-user')) {
$message = pht('Amazon SES does not support sending email as users. Disable ' . 'send as user, or choose a different mail adapter.');
$this->newIssue('config.can-send-as-user')->setName(pht("SES Can't Send As User"))->setMessage($message)->addRelatedPhabricatorConfig('metamta.mail-adapter')->addPhabricatorConfig('metamta.can-send-as-user');
}
if (!PhabricatorEnv::getEnvConfig('amazon-ses.access-key')) {
$message = pht('Amazon SES is selected as the mail adapter, but no SES access ' . 'key is configured. Provide an SES access key, or choose a ' . 'different mail adapter.');
$this->newIssue('config.amazon-ses.access-key')->setName(pht('Amazon SES Access Key Not Set'))->setMessage($message)->addRelatedPhabricatorConfig('metamta.mail-adapter')->addPhabricatorConfig('amazon-ses.access-key');
}
if (!PhabricatorEnv::getEnvConfig('amazon-ses.secret-key')) {
$message = pht('Amazon SES is selected as the mail adapter, but no SES secret ' . 'key is configured. Provide an SES secret key, or choose a ' . 'different mail adapter.');
$this->newIssue('config.amazon-ses.secret-key')->setName(pht('Amazon SES Secret Key Not Set'))->setMessage($message)->addRelatedPhabricatorConfig('metamta.mail-adapter')->addPhabricatorConfig('amazon-ses.secret-key');
}
$address_key = 'metamta.default-address';
$options = PhabricatorApplicationConfigOptions::loadAllOptions();
$default = $options[$address_key]->getDefault();
$value = PhabricatorEnv::getEnvConfig($address_key);
if ($default === $value) {
$message = pht('Amazon SES requires verification of the "From" address, but ' . 'you have not configured a "From" address. Configure and verify ' . 'a "From" address, or choose a different mail adapter.');
$this->newIssue('config.metamta.default-address')->setName(pht('No SES From Address Configured'))->setMessage($message)->addRelatedPhabricatorConfig('metamta.mail-adapter')->addPhabricatorConfig('metamta.default-address');
}
break;
}
}
示例7: run
public function run()
{
$roots = array();
$roots['libphutil'] = dirname(phutil_get_library_root('phutil'));
$roots['arcanist'] = dirname(phutil_get_library_root('arcanist'));
foreach ($roots as $lib => $root) {
echo "Upgrading {$lib}...\n";
if (!Filesystem::pathExists($root . '/.git')) {
throw new ArcanistUsageException("{$lib} must be in its git working copy to be automatically " . "upgraded. This copy of {$lib} (in '{$root}') is not in a git " . "working copy.");
}
$working_copy = ArcanistWorkingCopyIdentity::newFromPath($root);
$configuration_manager = clone $this->getConfigurationManager();
$configuration_manager->setWorkingCopyIdentity($working_copy);
$repository_api = ArcanistRepositoryAPI::newAPIFromConfigurationManager($configuration_manager);
$this->setRepositoryAPI($repository_api);
// Require no local changes.
$this->requireCleanWorkingCopy();
// Require the library be on master.
$branch_name = $repository_api->getBranchName();
if ($branch_name != 'master') {
throw new ArcanistUsageException("{$lib} must be on branch 'master' to be automatically upgraded. " . "This copy of {$lib} (in '{$root}') is on branch '{$branch_name}'.");
}
chdir($root);
try {
phutil_passthru('git pull --rebase');
} catch (Exception $ex) {
phutil_passthru('git rebase --abort');
throw $ex;
}
}
echo phutil_console_wrap(phutil_console_format("**Updated!** Your copy of arc is now up to date.\n"));
return 0;
}
示例8: loadSkinSpecification
private static function loadSkinSpecification($path)
{
$config_path = $path . DIRECTORY_SEPARATOR . 'skin.json';
$config = array();
if (Filesystem::pathExists($config_path)) {
$config = Filesystem::readFile($config_path);
try {
$config = phutil_json_decode($config);
} catch (PhutilJSONParserException $ex) {
throw new PhutilProxyException(pht("Skin configuration file '%s' is not a valid JSON file.", $config_path), $ex);
}
$type = idx($config, 'type', self::TYPE_BASIC);
} else {
$type = self::TYPE_BASIC;
}
$spec = new PhameSkinSpecification();
$spec->setRootDirectory($path);
$spec->setConfig($config);
switch ($type) {
case self::TYPE_BASIC:
$spec->setSkinClass('PhameBasicTemplateBlogSkin');
break;
case self::TYPE_ADVANCED:
$spec->setSkinClass($config['class']);
$spec->addPhutilLibrary($path . DIRECTORY_SEPARATOR . 'src');
break;
default:
throw new Exception(pht('Unknown skin type!'));
}
$spec->setType($type);
return $spec;
}
示例9: run
public function run()
{
$roots = array('libphutil' => dirname(phutil_get_library_root('phutil')), 'arcanist' => dirname(phutil_get_library_root('arcanist')));
foreach ($roots as $lib => $root) {
echo phutil_console_format("%s\n", pht('Upgrading %s...', $lib));
$working_copy = ArcanistWorkingCopyIdentity::newFromPath($root);
$configuration_manager = clone $this->getConfigurationManager();
$configuration_manager->setWorkingCopyIdentity($working_copy);
$repository = ArcanistRepositoryAPI::newAPIFromConfigurationManager($configuration_manager);
if (!Filesystem::pathExists($repository->getMetadataPath())) {
throw new ArcanistUsageException(pht("%s must be in its git working copy to be automatically upgraded. " . "This copy of %s (in '%s') is not in a git working copy.", $lib, $lib, $root));
}
$this->setRepositoryAPI($repository);
// Require no local changes.
$this->requireCleanWorkingCopy();
// Require the library be on master.
$branch_name = $repository->getBranchName();
if ($branch_name != 'master') {
throw new ArcanistUsageException(pht("%s must be on branch '%s' to be automatically upgraded. " . "This copy of %s (in '%s') is on branch '%s'.", $lib, 'master', $lib, $root, $branch_name));
}
chdir($root);
try {
phutil_passthru('git pull --rebase');
} catch (Exception $ex) {
phutil_passthru('git rebase --abort');
throw $ex;
}
}
echo phutil_console_format("**%s** %s\n", pht('Updated!'), pht('Your copy of arc is now up to date.'));
return 0;
}
示例10: buildBareRepository
protected function buildBareRepository($callsign)
{
$existing_repository = id(new PhabricatorRepositoryQuery())->withCallsigns(array($callsign))->setViewer(PhabricatorUser::getOmnipotentUser())->executeOne();
if ($existing_repository) {
$existing_repository->delete();
}
$data_dir = dirname(__FILE__) . '/data/';
$types = array('svn' => PhabricatorRepositoryType::REPOSITORY_TYPE_SVN, 'hg' => PhabricatorRepositoryType::REPOSITORY_TYPE_MERCURIAL, 'git' => PhabricatorRepositoryType::REPOSITORY_TYPE_GIT);
$hits = array();
foreach ($types as $type => $const) {
$path = $data_dir . $callsign . '.' . $type . '.tgz';
if (Filesystem::pathExists($path)) {
$hits[$const] = $path;
}
}
if (!$hits) {
throw new Exception("No test data for callsign '{$callsign}'. Expected an archive " . "like '{$callsign}.git.tgz' in '{$data_dir}'.");
}
if (count($hits) > 1) {
throw new Exception("Expected exactly one archive matching callsign '{$callsign}', " . "found too many: " . implode(', ', $hits));
}
$path = head($hits);
$vcs_type = head_key($hits);
$dir = PhutilDirectoryFixture::newFromArchive($path);
$local = new TempFile('.ignore');
$user = $this->generateNewTestUser();
$repo = PhabricatorRepository::initializeNewRepository($user)->setCallsign($callsign)->setName(pht('Test Repo "%s"', $callsign))->setVersionControlSystem($vcs_type)->setDetail('local-path', dirname($local) . '/' . $callsign)->setDetail('remote-uri', 'file://' . $dir->getPath() . '/');
$this->didConstructRepository($repo);
$repo->save();
$repo->makeEphemeral();
// Keep the disk resources around until we exit.
$this->dirs[] = $dir;
$this->dirs[] = $local;
return $repo;
}
示例11: getProxyCommand
protected function getProxyCommand()
{
$uri = new PhutilURI($this->proxyURI);
$username = AlmanacKeys::getClusterSSHUser();
if ($username === null) {
throw new Exception(pht('Unable to determine the username to connect with when trying ' . 'to proxy an SSH request within the Phabricator cluster.'));
}
$port = $uri->getPort();
$host = $uri->getDomain();
$key_path = AlmanacKeys::getKeyPath('device.key');
if (!Filesystem::pathExists($key_path)) {
throw new Exception(pht('Unable to proxy this SSH request within the cluster: this device ' . 'is not registered and has a missing device key (expected to ' . 'find key at "%s").', $key_path));
}
$options = array();
$options[] = '-o';
$options[] = 'StrictHostKeyChecking=no';
$options[] = '-o';
$options[] = 'UserKnownHostsFile=/dev/null';
// This is suppressing "added <address> to the list of known hosts"
// messages, which are confusing and irrelevant when they arise from
// proxied requests. It might also be suppressing lots of useful errors,
// of course. Ideally, we would enforce host keys eventually.
$options[] = '-o';
$options[] = 'LogLevel=quiet';
// NOTE: We prefix the command with "@username", which the far end of the
// connection will parse in order to act as the specified user. This
// behavior is only available to cluster requests signed by a trusted
// device key.
return csprintf('ssh %Ls -l %s -i %s -p %s %s -- %s %Ls', $options, $username, $key_path, $port, $host, '@' . $this->getUser()->getUsername(), $this->getOriginalArguments());
}
示例12: run
public final function run()
{
$repository = $this->loadRepository();
$expected_type = $this->getSupportedRepositoryType();
$repo_type = $repository->getVersionControlSystem();
if ($repo_type != $expected_type) {
$repo_type_name = PhabricatorRepositoryType::getNameForRepositoryType($repo_type);
$expected_type_name = PhabricatorRepositoryType::getNameForRepositoryType($expected_type);
$repo_name = $repository->getName() . ' (' . $repository->getCallsign() . ')';
throw new Exception("This daemon pulls '{$expected_type_name}' repositories, but the " . "repository '{$repo_name}' is a '{$repo_type_name}' repository.");
}
$tracked = $repository->isTracked();
if (!$tracked) {
throw new Exception("Tracking is not enabled for this repository.");
}
$local_path = $repository->getDetail('local-path');
if (!$local_path) {
throw new Exception("No local path is available for this repository.");
}
while (true) {
if (!Filesystem::pathExists($local_path)) {
execx('mkdir -p %s', dirname($local_path));
$this->executeCreate($repository, $local_path);
} else {
$this->executeUpdate($repository, $local_path);
}
$this->sleep($repository->getDetail('pull-frequency', 15));
}
}
示例13: testSVNPullBasic
public function testSVNPullBasic()
{
$repo = $this->buildPulledRepository('ST');
// We don't pull local clones for SVN, so we don't expect there to be
// a working copy.
$this->assertFalse(Filesystem::pathExists($repo->getLocalPath()));
}
示例14: run
public function run()
{
$repository = $this->loadRepository();
if ($repository->getVersionControlSystem() != 'git') {
throw new Exception("Not a git repository!");
}
$tracked = $repository->getDetail('tracking-enabled');
if (!$tracked) {
throw new Exception("Tracking is not enabled for this repository.");
}
$local_path = $repository->getDetail('local-path');
$remote_uri = $repository->getDetail('remote-uri');
if (!$local_path) {
throw new Exception("No local path is available for this repository.");
}
while (true) {
if (!Filesystem::pathExists($local_path)) {
if (!$remote_uri) {
throw new Exception("No remote URI is available.");
}
execx('mkdir -p %s', dirname($local_path));
execx('git clone %s %s', $remote_uri, rtrim($local_path, '/'));
} else {
execx('(cd %s && git fetch --all)', $local_path);
}
$this->sleep($repository->getDetail('pull-frequency', 15));
}
}
示例15: getPEP8Path
public function getPEP8Path()
{
$working_copy = $this->getEngine()->getWorkingCopy();
$prefix = $working_copy->getConfig('lint.pep8.prefix');
$bin = $working_copy->getConfig('lint.pep8.bin');
if ($bin === null && $prefix === null) {
$bin = csprintf('/usr/bin/env python2.6 %s', phutil_get_library_root('arcanist') . '/../externals/pep8/pep8.py');
} else {
if ($bin === null) {
$bin = 'pep8';
}
if ($prefix !== null) {
if (!Filesystem::pathExists($prefix . '/' . $bin)) {
throw new ArcanistUsageException("Unable to find PEP8 binary in a specified directory. Make sure " . "that 'lint.pep8.prefix' and 'lint.pep8.bin' keys are set " . "correctly. If you'd rather use a copy of PEP8 installed " . "globally, you can just remove these keys from your .arcconfig");
}
$bin = csprintf("%s/%s", $prefix, $bin);
return $bin;
}
// Look for globally installed PEP8
list($err) = exec_manual('which %s', $bin);
if ($err) {
throw new ArcanistUsageException("PEP8 does not appear to be installed on this system. Install it " . "(e.g., with 'easy_install pep8') or configure " . "'lint.pep8.prefix' in your .arcconfig to point to the directory " . "where it resides.");
}
}
return $bin;
}