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


PHP phutil_utf8ize函数代码示例

本文整理汇总了PHP中phutil_utf8ize函数的典型用法代码示例。如果您正苦于以下问题:PHP phutil_utf8ize函数的具体用法?PHP phutil_utf8ize怎么用?PHP phutil_utf8ize使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


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

示例1: handleLogEvent

 private function handleLogEvent(PhutilEvent $event)
 {
     $daemon = $this->getDaemon($event->getValue('id'));
     // TODO: This is a bit awkward for historical reasons, clean it up after
     // removing Conduit.
     $message = $event->getValue('message');
     $context = $event->getValue('context');
     if (strlen($context) && $context !== $message) {
         $message = "({$context}) {$message}";
     }
     $type = $event->getValue('type');
     $message = phutil_utf8ize($message);
     id(new PhabricatorDaemonLogEvent())->setLogID($daemon->getID())->setLogType($type)->setMessage((string) $message)->setEpoch(time())->save();
     switch ($type) {
         case 'WAIT':
             $current_status = PhabricatorDaemonLog::STATUS_WAIT;
             break;
         default:
             $current_status = PhabricatorDaemonLog::STATUS_RUNNING;
             break;
     }
     if ($current_status !== $daemon->getStatus()) {
         $daemon->setStatus($current_status)->save();
     }
 }
开发者ID:pugong,项目名称:phabricator,代码行数:25,代码来源:PhabricatorDaemonEventListener.php

示例2: truncateValue

 private static function truncateValue($value, $length)
 {
     if (is_string($value)) {
         if (strlen($value) <= $length) {
             return $value;
         } else {
             // NOTE: PhutilUTF8StringTruncator has huge runtime for giant strings.
             return phutil_utf8ize(substr($value, 0, $length) . "\n<...>");
         }
     } else {
         if (is_array($value)) {
             foreach ($value as $key => $v) {
                 if ($length <= 0) {
                     $value['<...>'] = '<...>';
                     unset($value[$key]);
                 } else {
                     $v = self::truncateValue($v, $length);
                     $length -= strlen($v);
                     $value[$key] = $v;
                 }
             }
             return $value;
         } else {
             return $value;
         }
     }
 }
开发者ID:pugong,项目名称:phabricator,代码行数:27,代码来源:HeraldObjectTranscript.php

示例3: testUTF8ize_owl_isCuteAndFerocious

 public function testUTF8ize_owl_isCuteAndFerocious()
 {
     // This was once a ferocious owl when we used to use "?" as the replacement
     // character instead of U+FFFD, but now he is sort of not as cute or
     // ferocious.
     $input = "M(o���o)M";
     $expect = "M(o���o)M";
     $result = phutil_utf8ize($input);
     $this->assertEqual($expect, $result);
 }
开发者ID:relrod,项目名称:libphutil,代码行数:10,代码来源:PhutilUTF8TestCase.php

示例4: getSVNLogXMLObject

 /**
  * This method is kind of awkward here but both the SVN message and
  * change parsers use it.
  */
 protected function getSVNLogXMLObject($uri, $revision, $verbose = false)
 {
     if ($verbose) {
         $verbose = '--verbose';
     }
     list($xml) = $this->repository->execxRemoteCommand("log --xml {$verbose} --limit 1 %s@%d", $uri, $revision);
     // Subversion may send us back commit messages which won't parse because
     // they have non UTF-8 garbage in them. Slam them into valid UTF-8.
     $xml = phutil_utf8ize($xml);
     return new SimpleXMLElement($xml);
 }
开发者ID:nexeck,项目名称:phabricator,代码行数:15,代码来源:PhabricatorRepositoryCommitParserWorker.php

示例5: __construct

 public function __construct($status_code, $body)
 {
     // NOTE: Avoiding phutil_utf8_shorten() here because this isn't lazy
     // and responses may be large.
     if (strlen($body) > 512) {
         $excerpt = substr($body, 0, 512) . '...';
     } else {
         $excerpt = $body;
     }
     $this->excerpt = phutil_utf8ize($excerpt);
     parent::__construct($status_code);
 }
开发者ID:rwray,项目名称:libphutil,代码行数:12,代码来源:HTTPFutureResponseStatusHTTP.php

示例6: parseSVNLogXML

 private function parseSVNLogXML($xml)
 {
     $xml = phutil_utf8ize($xml);
     $result = array();
     $log = new SimpleXMLElement($xml);
     foreach ($log->logentry as $entry) {
         $commit = (int) $entry['revision'];
         $epoch = (int) strtotime((string) $entry->date[0]);
         $result[$commit] = $epoch;
     }
     return $result;
 }
开发者ID:hwang36,项目名称:phabricator,代码行数:12,代码来源:PhabricatorRepositorySvnCommitDiscoveryDaemon.php

示例7: parseCommit

 public function parseCommit(PhabricatorRepository $repository, PhabricatorRepositoryCommit $commit)
 {
     // NOTE: %B was introduced somewhat recently in git's history, so pull
     // commit message information with %s and %b instead.
     // Even though we pass --encoding here, git doesn't always succeed, so
     // we try a little harder, since git *does* tell us what the actual encoding
     // is correctly (unless it doesn't; encoding is sometimes empty).
     list($info) = $repository->execxLocalCommand('log -n 1 --encoding=%s --format=%s %s --', 'UTF-8', implode('%x00', array('%e', '%cn', '%ce', '%an', '%ae', '%s%n%n%b')), $commit->getCommitIdentifier());
     $parts = explode("", $info);
     $encoding = array_shift($parts);
     // See note above - git doesn't always convert the encoding correctly.
     $do_convert = false;
     if (strlen($encoding) && strtoupper($encoding) != 'UTF-8') {
         if (function_exists('mb_convert_encoding')) {
             $do_convert = true;
         }
     }
     foreach ($parts as $key => $part) {
         if ($do_convert) {
             $parts[$key] = mb_convert_encoding($part, 'UTF-8', $encoding);
         }
         $parts[$key] = phutil_utf8ize($part);
     }
     $committer_name = $parts[0];
     $committer_email = $parts[1];
     $author_name = $parts[2];
     $author_email = $parts[3];
     $message = $parts[4];
     if (strlen($author_email)) {
         $author = "{$author_name} <{$author_email}>";
     } else {
         $author = "{$author_name}";
     }
     if (strlen($committer_email)) {
         $committer = "{$committer_name} <{$committer_email}>";
     } else {
         $committer = "{$committer_name}";
     }
     if ($committer == $author) {
         $committer = null;
     }
     $this->updateCommitData($author, $message, $committer);
     if ($this->shouldQueueFollowupTasks()) {
         $task = new PhabricatorWorkerTask();
         $task->setTaskClass('PhabricatorRepositoryGitCommitChangeParserWorker');
         $task->setData(array('commitID' => $commit->getID()));
         $task->save();
     }
 }
开发者ID:nexeck,项目名称:phabricator,代码行数:49,代码来源:PhabricatorRepositoryGitCommitMessageParserWorker.php

示例8: parseCommit

 public function parseCommit(PhabricatorRepository $repository, PhabricatorRepositoryCommit $commit)
 {
     list($stdout) = $repository->execxLocalCommand('log --template %s --rev %s', '{author}\\n{desc}', $commit->getCommitIdentifier());
     list($author, $message) = explode("\n", $stdout, 2);
     $author = phutil_utf8ize($author);
     $message = phutil_utf8ize($message);
     $message = trim($message);
     $this->updateCommitData($author, $message);
     if ($this->shouldQueueFollowupTasks()) {
         $task = new PhabricatorWorkerTask();
         $task->setTaskClass('PhabricatorRepositoryMercurialCommitChangeParserWorker');
         $task->setData(array('commitID' => $commit->getID()));
         $task->save();
     }
 }
开发者ID:netcomtec,项目名称:phabricator,代码行数:15,代码来源:PhabricatorRepositoryMercurialCommitMessageParserWorker.php

示例9: loadSubversionCommitRef

 private function loadSubversionCommitRef()
 {
     $repository = $this->getRepository();
     list($xml) = $repository->execxRemoteCommand('log --xml --limit 1 %s', $repository->getSubversionPathURI(null, $this->identifier));
     // Subversion may send us back commit messages which won't parse because
     // they have non UTF-8 garbage in them. Slam them into valid UTF-8.
     $xml = phutil_utf8ize($xml);
     $log = new SimpleXMLElement($xml);
     $entry = $log->logentry[0];
     $author = (string) $entry->author;
     $message = (string) $entry->msg;
     list($author_name, $author_email) = $this->splitUserIdentifier($author);
     // No hashes in Subversion.
     $hashes = array();
     return id(new DiffusionCommitRef())->setAuthorName($author_name)->setAuthorEmail($author_email)->setMessage($message)->setHashes($hashes);
 }
开发者ID:denghp,项目名称:phabricator,代码行数:16,代码来源:DiffusionLowLevelCommitQuery.php

示例10: parseCommit

 public function parseCommit(PhabricatorRepository $repository, PhabricatorRepositoryCommit $commit)
 {
     // NOTE: %B was introduced somewhat recently in git's history, so pull
     // commit message information with %s and %b instead.
     list($info) = $repository->execxLocalCommand("log -n 1 --encoding='UTF-8' --pretty=format:%%an%%x00%%s%%n%%n%%b %s", $commit->getCommitIdentifier());
     list($author, $message) = explode("", $info);
     // Make sure these are valid UTF-8.
     $author = phutil_utf8ize($author);
     $message = phutil_utf8ize($message);
     $message = trim($message);
     $this->updateCommitData($author, $message);
     if ($this->shouldQueueFollowupTasks()) {
         $task = new PhabricatorWorkerTask();
         $task->setTaskClass('PhabricatorRepositoryGitCommitChangeParserWorker');
         $task->setData(array('commitID' => $commit->getID()));
         $task->save();
     }
 }
开发者ID:ramons03,项目名称:phabricator,代码行数:18,代码来源:PhabricatorRepositoryGitCommitMessageParserWorker.php

示例11: __construct

 public function __construct($status_code, $body, array $headers, $expect = null)
 {
     // NOTE: Avoiding PhutilUTF8StringTruncator here because this isn't lazy
     // and responses may be large.
     if (strlen($body) > 512) {
         $excerpt = substr($body, 0, 512) . '...';
     } else {
         $excerpt = $body;
     }
     $content_type = BaseHTTPFuture::getHeader($headers, 'Content-Type');
     $match = null;
     if (preg_match('/;\\s*charset=([^;]+)/', $content_type, $match)) {
         $encoding = trim($match[1], "\"'");
         try {
             $excerpt = phutil_utf8_convert($excerpt, 'UTF-8', $encoding);
         } catch (Exception $ex) {
         }
     }
     $this->excerpt = phutil_utf8ize($excerpt);
     $this->expect = $expect;
     parent::__construct($status_code);
 }
开发者ID:lsubra,项目名称:libphutil,代码行数:22,代码来源:HTTPFutureHTTPResponseStatus.php

示例12: getSVNLogXMLObject

 /**
  * This method is kind of awkward here but both the SVN message and
  * change parsers use it.
  */
 protected function getSVNLogXMLObject($uri, $revision, $verbose = false)
 {
     if ($verbose) {
         $verbose = '--verbose';
     }
     try {
         list($xml) = execx("svn log --xml {$verbose} --limit 1 --non-interactive %s@%d", $uri, $revision);
     } catch (CommandException $ex) {
         // HTTPS is generally faster and more reliable than svn+ssh, but some
         // commit messages with non-UTF8 text can't be retrieved over HTTPS, see
         // Facebook rE197184 for one example. Make an attempt to fall back to
         // svn+ssh if we've failed outright to retrieve the message.
         $fallback_uri = new PhutilURI($uri);
         if ($fallback_uri->getProtocol() != 'https') {
             throw $ex;
         }
         $fallback_uri->setProtocol('svn+ssh');
         list($xml) = execx("svn log --xml {$verbose} --limit 1 --non-interactive %s@%d", $fallback_uri, $revision);
     }
     // Subversion may send us back commit messages which won't parse because
     // they have non UTF-8 garbage in them. Slam them into valid UTF-8.
     $xml = phutil_utf8ize($xml);
     return new SimpleXMLElement($xml);
 }
开发者ID:nguyennamtien,项目名称:phabricator,代码行数:28,代码来源:PhabricatorRepositoryCommitParserWorker.php

示例13: serveGitRequest

 /**
  * @phutil-external-symbol class PhabricatorStartup
  */
 private function serveGitRequest(PhabricatorRepository $repository, PhabricatorUser $viewer)
 {
     $request = $this->getRequest();
     $request_path = $this->getRequestDirectoryPath($repository);
     $repository_root = $repository->getLocalPath();
     // Rebuild the query string to strip `__magic__` parameters and prevent
     // issues where we might interpret inputs like "service=read&service=write"
     // differently than the server does and pass it an unsafe command.
     // NOTE: This does not use getPassthroughRequestParameters() because
     // that code is HTTP-method agnostic and will encode POST data.
     $query_data = $_GET;
     foreach ($query_data as $key => $value) {
         if (!strncmp($key, '__', 2)) {
             unset($query_data[$key]);
         }
     }
     $query_string = http_build_query($query_data, '', '&');
     // We're about to wipe out PATH with the rest of the environment, so
     // resolve the binary first.
     $bin = Filesystem::resolveBinary('git-http-backend');
     if (!$bin) {
         throw new Exception(pht('Unable to find `%s` in %s!', 'git-http-backend', '$PATH'));
     }
     $env = array('REQUEST_METHOD' => $_SERVER['REQUEST_METHOD'], 'QUERY_STRING' => $query_string, 'CONTENT_TYPE' => $request->getHTTPHeader('Content-Type'), 'HTTP_CONTENT_ENCODING' => $request->getHTTPHeader('Content-Encoding'), 'REMOTE_ADDR' => $_SERVER['REMOTE_ADDR'], 'GIT_PROJECT_ROOT' => $repository_root, 'GIT_HTTP_EXPORT_ALL' => '1', 'PATH_INFO' => $request_path, 'REMOTE_USER' => $viewer->getUsername()) + $this->getCommonEnvironment($viewer);
     $input = PhabricatorStartup::getRawInput();
     $command = csprintf('%s', $bin);
     $command = PhabricatorDaemon::sudoCommandAsDaemonUser($command);
     list($err, $stdout, $stderr) = id(new ExecFuture('%C', $command))->setEnv($env, true)->write($input)->resolve();
     if ($err) {
         if ($this->isValidGitShallowCloneResponse($stdout, $stderr)) {
             // Ignore the error if the response passes this special check for
             // validity.
             $err = 0;
         }
     }
     if ($err) {
         return new PhabricatorVCSResponse(500, pht('Error %d: %s', $err, phutil_utf8ize($stderr)));
     }
     return id(new DiffusionGitResponse())->setGitData($stdout);
 }
开发者ID:bigboi900,项目名称:phabricator,代码行数:43,代码来源:DiffusionServeController.php

示例14: renderCow

 public function renderCow()
 {
     $width = 40;
     $template = $this->template;
     // Real ".cow" files are Perl scripts which define a variable called
     // "$the_cow". We aren't going to interpret Perl, so strip all this stuff
     // (and any comments in the file) away.
     $template = phutil_split_lines($template, true);
     $keep = array();
     $is_perl_cowfile = false;
     foreach ($template as $key => $line) {
         if (preg_match('/^#/', $line)) {
             continue;
         }
         if (preg_match('/^\\s*\\$the_cow/', $line)) {
             $is_perl_cowfile = true;
             continue;
         }
         if (preg_match('/^\\s*EOC\\s*$/', $line)) {
             continue;
         }
         $keep[] = $line;
     }
     $template = implode('', $keep);
     // Original .cow files are perl scripts which contain escaped sequences.
     // We attempt to unescape here by replacing any character preceded by a
     // backslash/escape with just that character.
     if ($is_perl_cowfile) {
         $template = preg_replace('/\\\\(.)/', '$1', $template);
     }
     $template = preg_replace_callback('/\\$([a-z]+)/', array($this, 'replaceTemplateVariable'), $template);
     if ($template === false) {
         throw new Exception(pht('Failed to replace template variables while rendering cow!'));
     }
     $lines = $this->text;
     // TODO: It would be nice to use a utf8 soft wrap here instead, but we
     // do not currently have one. Soft wrap first, then force to utf8.
     $lines = wordwrap($lines, $width - 4, "\n", true);
     $lines = phutil_split_lines($lines, false);
     foreach ($lines as $key => $line) {
         $lines[$key] = phutil_utf8ize($line);
     }
     if ($this->action == 'think') {
         $borders = '((()))';
     } else {
         if (count($lines) == 1) {
             $borders = '<<<>>>';
         } else {
             $borders = '/|\\\\|/';
         }
     }
     $size = 0;
     foreach ($lines as $line) {
         $size = max(strlen($line), $size);
     }
     $balloon = array();
     $balloon[] = ' ' . str_repeat('_', $size + 2);
     $lines = array_values($lines);
     $last = count($lines) - 1;
     foreach ($lines as $idx => $line) {
         if ($idx == 0) {
             $l = $borders[0];
             $r = $borders[3];
         } else {
             if ($idx == $last) {
                 $l = $borders[2];
                 $r = $borders[5];
             } else {
                 $l = $borders[1];
                 $r = $borders[4];
             }
         }
         $balloon[] = $l . ' ' . str_pad($line, $size) . ' ' . $r;
     }
     $balloon[] = ' ' . str_repeat('-', $size + 2);
     $balloon = implode("\n", $balloon);
     return rtrim($balloon . "\n" . $template);
 }
开发者ID:barcelonascience,项目名称:libphutil,代码行数:78,代码来源:PhutilCowsay.php

示例15: phutil_validate_json

/**
 * Produce a human-readable explanation why a value can not be JSON-encoded.
 *
 * @param wild Value to validate.
 * @param string Path within the object to provide context.
 * @return string|null Explanation of why it can't be encoded, or null.
 */
function phutil_validate_json($value, $path = '')
{
    if ($value === null) {
        return;
    }
    if ($value === true) {
        return;
    }
    if ($value === false) {
        return;
    }
    if (is_int($value)) {
        return;
    }
    if (is_float($value)) {
        return;
    }
    if (is_array($value)) {
        foreach ($value as $key => $subvalue) {
            if (strlen($path)) {
                $full_key = $path . ' > ';
            } else {
                $full_key = '';
            }
            if (!phutil_is_utf8($key)) {
                $full_key = $full_key . phutil_utf8ize($key);
                return pht('Dictionary key "%s" is not valid UTF8, and can not be JSON encoded.', $full_key);
            }
            $full_key .= $key;
            $result = phutil_validate_json($subvalue, $full_key);
            if ($result !== null) {
                return $result;
            }
        }
    }
    if (is_string($value)) {
        if (!phutil_is_utf8($value)) {
            $display = substr($value, 0, 256);
            $display = phutil_utf8ize($display);
            if (!strlen($path)) {
                return pht('String value is not valid UTF8, and can not be JSON encoded: %s', $display);
            } else {
                return pht('Dictionary value at key "%s" is not valid UTF8, and can not be ' . 'JSON encoded: %s', $path, $display);
            }
        }
    }
    return;
}
开发者ID:fengshao0907,项目名称:libphutil,代码行数:55,代码来源:utils.php


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