当前位置: 首页>>代码示例>>PHP>>正文


PHP Filesystem::readFile方法代码示例

本文整理汇总了PHP中Filesystem::readFile方法的典型用法代码示例。如果您正苦于以下问题:PHP Filesystem::readFile方法的具体用法?PHP Filesystem::readFile怎么用?PHP Filesystem::readFile使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Filesystem的用法示例。


在下文中一共展示了Filesystem::readFile方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: editInteractively

 /**
  * Launch an editor and edit the content. The edited content will be
  * returned.
  *
  * @return string    Edited content.
  * @throws Exception The editor exited abnormally or something untoward
  *                   occurred.
  *
  * @task edit
  */
 public function editInteractively()
 {
     $name = $this->getName();
     $content = $this->getContent();
     if (phutil_is_windows()) {
         $content = str_replace("\n", "\r\n", $content);
     }
     $tmp = Filesystem::createTemporaryDirectory('edit.');
     $path = $tmp . DIRECTORY_SEPARATOR . $name;
     try {
         Filesystem::writeFile($path, $content);
     } catch (Exception $ex) {
         Filesystem::remove($tmp);
         throw $ex;
     }
     $editor = $this->getEditor();
     $offset = $this->getLineOffset();
     $err = $this->invokeEditor($editor, $path, $offset);
     if ($err) {
         Filesystem::remove($tmp);
         throw new Exception("Editor exited with an error code (#{$err}).");
     }
     try {
         $result = Filesystem::readFile($path);
         Filesystem::remove($tmp);
     } catch (Exception $ex) {
         Filesystem::remove($tmp);
         throw $ex;
     }
     if (phutil_is_windows()) {
         $result = str_replace("\r\n", "\n", $result);
     }
     $this->setContent($result);
     return $this->getContent();
 }
开发者ID:lsubra,项目名称:libphutil,代码行数:45,代码来源:PhutilInteractiveEditor.php

示例2: detectCopiesIn

 private function detectCopiesIn($file)
 {
     $root = dirname(__FILE__) . '/diff/';
     $parser = new ArcanistDiffParser();
     $diff = DifferentialDiff::newFromRawChanges(PhabricatorUser::getOmnipotentUser(), $parser->parseDiff(Filesystem::readFile($root . $file)));
     return idx(head($diff->getChangesets())->getMetadata(), 'copy:lines');
 }
开发者ID:pugong,项目名称:phabricator,代码行数:7,代码来源:DifferentialDiffTestCase.php

示例3: getKeys

 public function getKeys(array $keys)
 {
     $this->validateKeys($keys);
     try {
         $this->lockCache();
     } catch (PhutilLockException $ex) {
         return array();
     }
     $now = time();
     $results = array();
     foreach ($keys as $key) {
         $key_file = $this->getKeyFile($key);
         try {
             $data = Filesystem::readFile($key_file);
         } catch (FilesystemException $ex) {
             continue;
         }
         $data = unserialize($data);
         if (!$data) {
             continue;
         }
         if (isset($data['ttl']) && $data['ttl'] < $now) {
             continue;
         }
         $results[$key] = $data['value'];
     }
     $this->unlockCache();
     return $results;
 }
开发者ID:lsubra,项目名称:libphutil,代码行数:29,代码来源:PhutilDirectoryKeyValueCache.php

示例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;
 }
开发者ID:rchicoli,项目名称:phabricator,代码行数:25,代码来源:NuanceGitHubRawEventTestCase.php

示例5: 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;
 }
开发者ID:pugong,项目名称:phabricator,代码行数:30,代码来源:PhabricatorAuthManagementCachePKCS8Workflow.php

示例6: markupText

 private function markupText($markup_file)
 {
     $contents = Filesystem::readFile($markup_file);
     $file = basename($markup_file);
     $parts = explode("\n~~~~~~~~~~\n", $contents);
     $this->assertEqual(3, count($parts), $markup_file);
     list($input_remarkup, $expected_output, $expected_text) = $parts;
     $engine = $this->buildNewTestEngine();
     switch ($file) {
         case 'raw-escape.txt':
             // NOTE: Here, we want to test PhutilRemarkupRuleEscapeRemarkup and
             // PhutilRemarkupBlockStorage, which are triggered by "\1". In the
             // test, "~" is used as a placeholder for "\1" since it's hard to type
             // "\1".
             $input_remarkup = str_replace("~", "", $input_remarkup);
             $expected_output = str_replace("~", "", $expected_output);
             $expected_text = str_replace("~", "", $expected_text);
             break;
         case 'toc.txt':
             $engine->setConfig('header.generate-toc', true);
             break;
     }
     $actual_output = (string) $engine->markupText($input_remarkup);
     switch ($file) {
         case 'toc.txt':
             $table_of_contents = PhutilRemarkupEngineRemarkupHeaderBlockRule::renderTableOfContents($engine);
             $actual_output = $table_of_contents . "\n\n" . $actual_output;
             break;
     }
     $this->assertEqual($expected_output, $actual_output, "Failed to markup HTML in file '{$file}'.");
     $engine->setMode(PhutilRemarkupEngine::MODE_TEXT);
     $actual_output = (string) $engine->markupText($input_remarkup);
     $this->assertEqual($expected_text, $actual_output, "Failed to markup text in file '{$file}'.");
 }
开发者ID:chaozhang80,项目名称:tool-package,代码行数:34,代码来源:PhutilRemarkupEngineTestCase.php

示例7: testParseAll

 public function testParseAll()
 {
     $root = dirname(__FILE__) . '/mercurial/';
     foreach (Filesystem::listDirectory($root, $hidden = false) as $file) {
         $this->parseData(basename($file), Filesystem::readFile($root . '/' . $file));
     }
 }
开发者ID:barcelonascience,项目名称:arcanist,代码行数:7,代码来源:ArcanistMercurialParserTestCase.php

示例8: run

 public function run()
 {
     $conduit = $this->getConduit();
     $results = array();
     foreach ($this->paths as $path) {
         $name = basename($path);
         $this->writeStatusMessage("Uploading '{$name}'...\n");
         try {
             $data = Filesystem::readFile($path);
         } catch (FilesystemException $ex) {
             $this->writeStatusMessage("Unable to upload file: " . $ex->getMessage() . "\n");
             $results[$path] = null;
             continue;
         }
         $phid = $conduit->callMethodSynchronous('file.upload', array('data_base64' => base64_encode($data), 'name' => $name));
         $info = $conduit->callMethodSynchronous('file.info', array('phid' => $phid));
         $results[$path] = $info;
         if (!$this->getJSON()) {
             echo "  {$name}: " . $info['uri'] . "\n\n";
         }
     }
     if ($this->getJSON()) {
         echo json_encode($results) . "\n";
     } else {
         $this->writeStatusMessage("Done.\n");
     }
     return 0;
 }
开发者ID:nik-kor,项目名称:arcanist,代码行数:28,代码来源:ArcanistUploadWorkflow.php

示例9: 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);
     }
 }
开发者ID:pugong,项目名称:phabricator,代码行数:25,代码来源:DifferentialCommitMessageParserTestCase.php

示例10: readBookConfiguration

 protected function readBookConfiguration($book_path)
 {
     if ($book_path === null) {
         throw new PhutilArgumentUsageException('Specify a Diviner book configuration file with --book.');
     }
     $book_data = Filesystem::readFile($book_path);
     $book = json_decode($book_data, true);
     if (!is_array($book)) {
         throw new PhutilArgumentUsageException("Book configuration '{$book_path}' is not in JSON format.");
     }
     PhutilTypeSpec::checkMap($book, array('name' => 'string', 'title' => 'optional string', 'short' => 'optional string', 'preface' => 'optional string', 'root' => 'optional string', 'uri.source' => 'optional string', 'rules' => 'optional map<regex, string>', 'exclude' => 'optional regex|list<regex>', 'groups' => 'optional map<string, map<string, wild>>'));
     // If the book specifies a "root", resolve it; otherwise, use the directory
     // the book configuration file lives in.
     $full_path = dirname(Filesystem::resolvePath($book_path));
     if (empty($book['root'])) {
         $book['root'] = '.';
     }
     $book['root'] = Filesystem::resolvePath($book['root'], $full_path);
     if (!preg_match('/^[a-z][a-z-]*\\z/', $book['name'])) {
         $name = $book['name'];
         throw new PhutilArgumentUsageException("Book configuration '{$book_path}' has name '{$name}', but book names " . "must include only lowercase letters and hyphens.");
     }
     foreach (idx($book, 'groups', array()) as $group) {
         PhutilTypeSpec::checkmap($group, array('name' => 'string', 'include' => 'optional regex|list<regex>'));
     }
     $this->bookConfigPath = $book_path;
     $this->config = $book;
 }
开发者ID:denghp,项目名称:phabricator,代码行数:28,代码来源:DivinerWorkflow.php

示例11: 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);
         }
     }
 }
开发者ID:denghp,项目名称:phabricator,代码行数:26,代码来源:DifferentialParseRenderTestCase.php

示例12: 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;
 }
开发者ID:patelhardik,项目名称:phabricator,代码行数:32,代码来源:PhameSkinSpecification.php

示例13: run

 public function run()
 {
     $argv = $this->getArgv();
     if (count($argv) !== 1) {
         throw new Exception("usage: PhabricatorIRCBot <json_config_file>");
     }
     $json_raw = Filesystem::readFile($argv[0]);
     $config = json_decode($json_raw, true);
     if (!is_array($config)) {
         throw new Exception("File '{$argv[0]}' is not valid JSON!");
     }
     $server = idx($config, 'server');
     $port = idx($config, 'port', 6667);
     $handlers = idx($config, 'handlers', array());
     $pass = idx($config, 'pass');
     $nick = idx($config, 'nick', 'phabot');
     $user = idx($config, 'user', $nick);
     $ssl = idx($config, 'ssl', false);
     $nickpass = idx($config, 'nickpass');
     $this->config = $config;
     if (!preg_match('/^[A-Za-z0-9_`[{}^|\\]\\-]+$/', $nick)) {
         throw new Exception("Nickname '{$nick}' is invalid!");
     }
     foreach ($handlers as $handler) {
         $obj = newv($handler, array($this));
         $this->handlers[] = $obj;
     }
     $conduit_uri = idx($config, 'conduit.uri');
     if ($conduit_uri) {
         $conduit_user = idx($config, 'conduit.user');
         $conduit_cert = idx($config, 'conduit.cert');
         $conduit = new ConduitClient($conduit_uri);
         $response = $conduit->callMethodSynchronous('conduit.connect', array('client' => 'PhabricatorIRCBot', 'clientVersion' => '1.0', 'clientDescription' => php_uname('n') . ':' . $nick, 'user' => $conduit_user, 'certificate' => $conduit_cert));
         $this->conduit = $conduit;
     }
     $errno = null;
     $error = null;
     if (!$ssl) {
         $socket = fsockopen($server, $port, $errno, $error);
     } else {
         $socket = fsockopen('ssl://' . $server, $port, $errno, $error);
     }
     if (!$socket) {
         throw new Exception("Failed to connect, #{$errno}: {$error}");
     }
     $ok = stream_set_blocking($socket, false);
     if (!$ok) {
         throw new Exception("Failed to set stream nonblocking.");
     }
     $this->socket = $socket;
     $this->writeCommand('USER', "{$user} 0 * :{$user}");
     if ($pass) {
         $this->writeCommand('PASS', "{$pass}");
     }
     if ($nickpass) {
         $this->writeCommand("NickServ IDENTIFY ", "{$nickpass}");
     }
     $this->writeCommand('NICK', "{$nick}");
     $this->runSelectLoop();
 }
开发者ID:netcomtec,项目名称:phabricator,代码行数:60,代码来源:PhabricatorIRCBot.php

示例14: read

function read($file)
{
    if ($file == '-') {
        return file_get_contents('php://stdin');
    } else {
        return Filesystem::readFile($file);
    }
}
开发者ID:rwray,项目名称:libphutil,代码行数:8,代码来源:utf8.php

示例15: getDeviceID

 public static function getDeviceID()
 {
     $device_id_path = self::getKeyPath('device.id');
     if (Filesystem::pathExists($device_id_path)) {
         return trim(Filesystem::readFile($device_id_path));
     }
     return null;
 }
开发者ID:pugong,项目名称:phabricator,代码行数:8,代码来源:AlmanacKeys.php


注:本文中的Filesystem::readFile方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。