本文整理汇总了PHP中Drupal\Component\Utility\Unicode::validateUtf8方法的典型用法代码示例。如果您正苦于以下问题:PHP Unicode::validateUtf8方法的具体用法?PHP Unicode::validateUtf8怎么用?PHP Unicode::validateUtf8使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Drupal\Component\Utility\Unicode
的用法示例。
在下文中一共展示了Unicode::validateUtf8方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testValidateUtf8
/**
* Tests UTF-8 validation.
*
* @dataProvider providerTestValidateUtf8
* @covers ::validateUtf8
*
* @param string $text
* The text to validate.
* @param boolean $expected
* The expected return value from Unicode::validateUtf8().
* @param string $message
* The message to display on failure.
*/
public function testValidateUtf8($text, $expected, $message)
{
$this->assertEquals($expected, Unicode::validateUtf8($text), $message);
}
示例2: extractMollomValues
//.........这里部分代码省略.........
$data['postId'] = $mapping['post_id'];
}
// Post title.
if (!empty($mapping['post_title'])) {
$data['postTitle'] = $mapping['post_title'];
}
// Post body.
if (!empty($post_body)) {
$data['postBody'] = $post_body;
}
// Author ID.
// If a non-anonymous user ID was mapped via form values, use that.
if (!empty($mapping['author_id'])) {
$data['authorId'] = $mapping['author_id'];
} elseif (!empty($user->id())) {
$data['authorId'] = $user->id();
}
// Load the user account of the author, if any, for the following author*
// property assignments.
$account = FALSE;
if (isset($data['authorId'])) {
/** @var \Drupal\user\Entity\User $account */
$account = User::load($data['authorId']);
$author_username = $account->getUsername();
$author_email = $account->getEmail();
// Author creation date.
$data['authorCreated'] = $account->getCreatedTime();
// In case a post of a registered user is edited and a form value mapping
// exists for author_id, but no form value mapping exists for author_name,
// use the name of the user account associated with author_id.
// $account may be the same as the currently logged-in $user at this point.
if (!empty($author_username)) {
$data['authorName'] = $author_username;
}
if (!empty($author_email)) {
$data['authorMail'] = $author_email;
}
}
// Author name.
// A form value mapping always has precedence.
if (!empty($mapping['author_name'])) {
$data['authorName'] = $mapping['author_name'];
}
// Author e-mail.
if (!empty($mapping['author_mail'])) {
$data['authorMail'] = $mapping['author_mail'];
}
// Author homepage.
if (!empty($mapping['author_url'])) {
$data['authorUrl'] = $mapping['author_url'];
}
// Author OpenID.
if (!empty($mapping['author_openid'])) {
$data['authorOpenid'] = $mapping['author_openid'];
}
// Author IP.
$data['authorIp'] = \Drupal::request()->getClientIp();
$mollom_form = $form_state->getValue('mollom');
// Honeypot.
// For the Mollom backend, it only matters whether 'honeypot' is non-empty.
// The submitted value is only taken over to allow site administrators to
// see the actual honeypot value in watchdog log entries.
if (isset($mollom_form['homepage']) && $mollom_form['homepage'] !== '') {
$data['honeypot'] = $mollom_form['homepage'];
}
// Add the contextCreated parameter if a callback exists.
if (isset($mollom_form['context created callback']) && function_exists($mollom_form['context created callback'])) {
if (!empty($mapping['context_id'])) {
$contextCreated = call_user_func($mollom_form['context created callback'], $mapping['context_id']);
if ($contextCreated !== FALSE) {
$data['contextCreated'] = $contextCreated;
}
}
}
// Ensure that all $data values contain valid UTF-8. Invalid UTF-8 would be
// sanitized into an empty string, so the Mollom backend would not receive
// any value.
$invalid_utf8 = FALSE;
$invalid_xml = FALSE;
// Include the CAPTCHA solution user input in the UTF-8 validation.
$solution = isset($mollom_form['captcha']['captcha_input']) ? array('solution' => $mollom_form['captcha']['captcha_input']) : array();
foreach ($data + $solution as $key => $value) {
// Check for invalid UTF-8 byte sequences first.
if (!Unicode::validateUtf8($value)) {
$invalid_utf8 = TRUE;
// Replace the bogus string, since $data will be logged as
// check_plain(var_export($data)), and check_plain() would empty the
// entire exported variable string otherwise.
$data[$key] = '- Invalid UTF-8 -';
} elseif (preg_match('@[^\\x9\\xA\\xD\\x20-\\x{D7FF}\\x{E000}-\\x{FFFD}\\x{10000}-\\x{10FFFF}]@u', $value)) {
$invalid_xml = TRUE;
}
}
if ($invalid_utf8 || $invalid_xml) {
$form_state->setErrorByName('', t('Your submission contains invalid characters and will not be accepted.'));
Logger::addMessage(['message' => 'Invalid @type in form values', 'arguments' => ['@type' => $invalid_utf8 ? 'UTF-8' : 'XML characters'], 'data' => $data]);
$data = FALSE;
}
return $data;
}