本文整理汇总了PHP中Drupal\Component\Utility\Random::string方法的典型用法代码示例。如果您正苦于以下问题:PHP Random::string方法的具体用法?PHP Random::string怎么用?PHP Random::string使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Drupal\Component\Utility\Random
的用法示例。
在下文中一共展示了Random::string方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: providerTestPhpTransliterationWithAlter
/**
* Provides test data for testPhpTransliterationWithAlter.
*
* @return array
*/
public function providerTestPhpTransliterationWithAlter()
{
$random_generator = new Random();
$random = $random_generator->string(10);
// Make some strings with two, three, and four-byte characters for testing.
// Note that the 3-byte character is overridden by the 'kg' language.
$two_byte = 'Ä Ö Ü Å Ø äöüåøhello';
// These are two Gothic alphabet letters. See
// http://en.wikipedia.org/wiki/Gothic_alphabet
// They are not in our tables, but should at least give us '?' (unknown).
$five_byte = html_entity_decode('𐌰𐌸', ENT_NOQUOTES, 'UTF-8');
// Five-byte characters do not work in MySQL, so make a printable version.
$five_byte_printable = '𐌰𐌸';
$cases = array(array('zz', $two_byte, 'Z O U A O aouaohello'), array('zz', $random, $random), array('zz', $five_byte, 'ATh', $five_byte_printable));
return $cases;
}
示例2: providerTestPhpTransliteration
/**
* Provides data for self::testPhpTransliteration().
*
* @return array
* An array of arrays, each containing the parameters for
* self::testPhpTransliteration().
*/
public function providerTestPhpTransliteration()
{
$random_generator = new Random();
$random = $random_generator->string(10);
// Make some strings with two, three, and four-byte characters for testing.
// Note that the 3-byte character is overridden by the 'kg' language.
$two_byte = 'Ä Ö Ü Å Ø äöüåøhello';
// This is a Cyrrillic character that looks something like a u. See
// http://www.unicode.org/charts/PDF/U0400.pdf
$three_byte = html_entity_decode('ц', ENT_NOQUOTES, 'UTF-8');
// This is a Canadian Aboriginal character like a triangle. See
// http://www.unicode.org/charts/PDF/U1400.pdf
$four_byte = html_entity_decode('ᐑ', ENT_NOQUOTES, 'UTF-8');
// These are two Gothic alphabet letters. See
// http://wikipedia.org/wiki/Gothic_alphabet
// They are not in our tables, but should at least give us '?' (unknown).
$five_byte = html_entity_decode('𐌰𐌸', ENT_NOQUOTES, 'UTF-8');
return array(array('en', $random, $random), array('fr', $random, $random), array('fr', $three_byte, 'c'), array('fr', $four_byte, 'wii'), array('en', $five_byte, '??'), array('en', $two_byte, 'A O U A O aouaohello'), array('de', $two_byte, 'Ae Oe Ue A O aeoeueaohello'), array('de', $random, $random), array('dk', $two_byte, 'A O U Aa Oe aouaaoehello'), array('dk', $random, $random), array('kg', $three_byte, 'ts'), array('tr', 'Abayı serdiler bize. Söyleyeceğim yüzlerine. Sanırım hepimiz aynı şeyi düşünüyoruz.', 'Abayi serdiler bize. Soyleyecegim yuzlerine. Sanirim hepimiz ayni seyi dusunuyoruz.'), array('en', chr(0xf8) . chr(0x80) . chr(0x80) . chr(0x80) . chr(0x80), '?'), array('de', $two_byte, 'Ae Oe', '?', 5));
}
示例3: validate
/**
* {@inheritdoc}
*/
public function validate($text = NULL)
{
$random = new Random();
$errors = [];
// Check if the object properties are set correctly.
if (!$this->getEncryptionMethodId()) {
$errors[] = $this->t('No encryption method selected.');
}
if (!$this->getEncryptionKeyId()) {
$errors[] = $this->t('No encryption key selected.');
}
// If the properties are set, continue validation.
if ($this->getEncryptionMethodId() && $this->getEncryptionKeyId()) {
// Check if the linked encryption method is valid.
$encryption_method = $this->getEncryptionMethod();
if (!$encryption_method) {
$errors[] = $this->t('The encryption method linked to this encryption profile does not exist.');
}
// Check if the linked encryption key is valid.
$selected_key = $this->getEncryptionKey();
if (!$selected_key) {
$errors[] = $this->t('The key linked to this encryption profile does not exist.');
}
// If the encryption method and key are valid, continue validation.
if (empty($errors)) {
// Check if the selected key type matches encryption method settings.
$allowed_key_types = $encryption_method->getPluginDefinition()['key_type'];
if (!empty($allowed_key_types)) {
$selected_key_type = $selected_key->getKeyType();
if (!in_array($selected_key_type->getPluginId(), $allowed_key_types)) {
$errors[] = $this->t('The selected key cannot be used with the selected encryption method.');
}
}
// Check if encryption method dependencies are met.
$encryption_method = $this->getEncryptionMethod();
if (!$text) {
$text = $random->string();
}
$dependency_errors = $encryption_method->checkDependencies($text, $selected_key->getKeyValue());
$errors = array_merge($errors, $dependency_errors);
}
}
return $errors;
}
示例4: testRandomStringValidator
/**
* Tests random string validation callbacks.
*
* @covers ::string
*/
public function testRandomStringValidator()
{
$random = new Random();
$this->firstStringGenerated = '';
$str = $random->string(1, TRUE, array($this, '_RandomStringValidate'));
$this->assertNotEquals($this->firstStringGenerated, $str);
}
示例5: tryClaimPaymentOnce
/**
* Tries to claim a payment once.
*
* @param integer $payment_id
*
* @return string|false
* An acquisition code to acquire the payment with on success, or FALSE if
* the payment could not be claimed.
*/
protected function tryClaimPaymentOnce($payment_id)
{
$acquisition_code = $this->randomGenerator->string(255);
$count = $this->database->update('payment_queue', array('return' => Database::RETURN_AFFECTED))->condition('claimed', time() - $this->getClaimExpirationPeriod(), '<')->condition('payment_id', $payment_id)->condition('queue_id', $this->queueId)->fields(array('acquisition_code' => $acquisition_code, 'claimed' => time()))->execute();
return $count ? $acquisition_code : FALSE;
}
示例6: createNode
/**
* @Given /^I am viewing (?:a|an) "([^"]*)" node$/
* @Given /^I create (?:a|an) "([^"]*)" node$/
*
* This overrides the parent createNode() method, allowing node properties
* to be passes via $properties argument.
*
* @override
*/
public function createNode($type, $properties = array())
{
$node = (object) array('title' => Random::string(25), 'type' => $type, 'uid' => 1);
if ($properties) {
foreach ($properties as $key => $value) {
$node->{$key} = $value;
}
}
$this->dispatcher->dispatch('beforeNodeCreate', new EntityEvent($this, $node));
$saved = $this->getDriver()->createNode($node);
$this->dispatcher->dispatch('afterNodeCreate', new EntityEvent($this, $saved));
$this->nodes[] = $saved;
// Set internal page on the new node.
$this->getSession()->visit($this->locatePath('/node/' . $saved->nid));
return $saved;
}