• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

PHP Utility\Random类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: generateSampleValue

 /**
  * {@inheritdoc}
  */
 public static function generateSampleValue(FieldDefinitionInterface $field_definition)
 {
     $random = new Random();
     if ($field_definition->getItemDefinition()->getSetting('link_type') & LinkItemInterface::LINK_EXTERNAL) {
         // Set of possible top-level domains.
         $tlds = array('com', 'net', 'gov', 'org', 'edu', 'biz', 'info');
         // Set random length for the domain name.
         $domain_length = mt_rand(7, 15);
         switch ($field_definition->getSetting('title')) {
             case DRUPAL_DISABLED:
                 $values['title'] = '';
                 break;
             case DRUPAL_REQUIRED:
                 $values['title'] = $random->sentences(4);
                 break;
             case DRUPAL_OPTIONAL:
                 // In case of optional title, randomize its generation.
                 $values['title'] = mt_rand(0, 1) ? $random->sentences(4) : '';
                 break;
         }
         $values['uri'] = 'http://www.' . $random->word($domain_length) . '.' . $tlds[mt_rand(0, sizeof($tlds) - 1)];
     } else {
         $values['uri'] = 'base:' . $random->name(mt_rand(1, 64));
     }
     return $values;
 }
开发者ID:DrupalCamp-NYC,项目名称:dcnyc16,代码行数:29,代码来源:LinkItem.php


示例2: fixStepArgument

 /**
  * Override MinkContext::fixStepArgument().
  *
  * Make it possible to use [random].
  * If you want to use the previous random value [random:1].
  * Also, allow newlines in arguments.
  */
 public function fixStepArgument($argument)
 {
     // Token replace the argument.
     static $random = array();
     for ($start = 0; ($start = strpos($argument, '[', $start)) !== FALSE;) {
         $end = strpos($argument, ']', $start);
         if ($end === FALSE) {
             break;
         }
         $random_generator = new Random();
         $name = substr($argument, $start + 1, $end - $start - 1);
         if ($name == 'random') {
             $this->vars[$name] = $random_generator->name(8);
             $random[] = $this->vars[$name];
         } elseif (substr($name, 0, 7) == 'random:') {
             $num = substr($name, 7);
             if (is_numeric($num) && $num <= count($random)) {
                 $this->vars[$name] = $random[count($random) - $num];
             }
         }
         if (isset($this->vars[$name])) {
             $argument = substr_replace($argument, $this->vars[$name], $start, $end - $start + 1);
             $start += strlen($this->vars[$name]);
         } else {
             $start = $end + 1;
         }
     }
     return $argument;
 }
开发者ID:lliss,项目名称:drupal-bear-test,代码行数:36,代码来源:FeatureContext.php


示例3: generateSampleValue

 /**
  * {@inheritdoc}
  */
 public static function generateSampleValue(FieldDefinitionInterface $field_definition)
 {
     $random = new Random();
     $max = $field_definition->getSetting('max_length');
     $values['value'] = $random->word(mt_rand(1, $max));
     return $values;
 }
开发者ID:davidsoloman,项目名称:drupalconsole.com,代码行数:10,代码来源:StringItem.php


示例4: generateSampleValue

 /**
  * {@inheritdoc}
  */
 public static function generateSampleValue(FieldDefinitionInterface $field_definition)
 {
     // Set random length for the path.
     $domain_length = mt_rand(7, 15);
     $random = new Random();
     $values['path'] = 'http://www.' . $random->word($domain_length);
     return $values;
 }
开发者ID:aakb,项目名称:cfia,代码行数:11,代码来源:RedirectSourceItem.php


示例5: render

 /**
  * {@inheritdoc}
  */
 public function render(ResultRow $values)
 {
     // Return a random text, here you can include your custom logic.
     // Include any namespace required to call the method required to generte the
     // output desired
     $random = new Random();
     return $random->name();
 }
开发者ID:emilienGallet,项目名称:DrupalUnicef,代码行数:11,代码来源:CustomViewsField.php


示例6: prepareEntity

 /**
  * {@inheritdoc}
  */
 protected function prepareEntity()
 {
     if (empty($this->entity->name->value)) {
         // Assign a random name to new EntityTest entities, to avoid repetition in
         // tests.
         $random = new Random();
         $this->entity->name->value = $random->name();
     }
 }
开发者ID:jeyram,项目名称:camp-gdl,代码行数:12,代码来源:EntityTestForm.php


示例7: migrateDumpAlter

 /**
  * {@inheritdoc}
  */
 public static function migrateDumpAlter(TestBase $test)
 {
     // Creates a random filename and updates the source database.
     $random = new Random();
     $temp_directory = $test->getTempFilesDirectory();
     file_prepare_directory($temp_directory, FILE_CREATE_DIRECTORY);
     static::$tempFilename = $test->getDatabasePrefix() . $random->name() . '.jpg';
     $file_path = $temp_directory . '/' . static::$tempFilename;
     file_put_contents($file_path, '');
     Database::getConnection('default', 'migrate')->update('files')->condition('fid', 6)->fields(array('filename' => static::$tempFilename, 'filepath' => $file_path))->execute();
     return static::$tempFilename;
 }
开发者ID:komejo,项目名称:article-test,代码行数:15,代码来源:MigrateFileTest.php


示例8: generateSampleValue

 /**
  * {@inheritdoc}
  */
 public static function generateSampleValue(FieldDefinitionInterface $field_definition)
 {
     $random = new Random();
     $settings = $field_definition->getSettings();
     if (empty($settings['max_length'])) {
         // Textarea handling
         $value = $random->paragraphs();
     } else {
         // Textfield handling.
         $value = substr($random->sentences(mt_rand(1, $settings['max_length'] / 3), FALSE), 0, $settings['max_length']);
     }
     $values = array('value' => $value, 'summary' => $value, 'format' => filter_fallback_format());
     return $values;
 }
开发者ID:nstielau,项目名称:drops-8,代码行数:17,代码来源:TextItemBase.php


示例9: 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('&#x10330;&#x10338;', ENT_NOQUOTES, 'UTF-8');
     // Five-byte characters do not work in MySQL, so make a printable version.
     $five_byte_printable = '&#x10330;&#x10338;';
     $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;
 }
开发者ID:ddrozdik,项目名称:dmaps,代码行数:21,代码来源:PhpTransliterationTest.php


示例10: 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('&#x446;', 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('&#x1411;', 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('&#x10330;&#x10338;', 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));
 }
开发者ID:sojo,项目名称:d8_friendsofsilence,代码行数:26,代码来源:PhpTransliterationTest.php


示例11: testViewsBaseUrlField

 /**
  * Test views base url field.
  */
 function testViewsBaseUrlField()
 {
     global $base_url;
     $random = new Random();
     /** @var \Drupal\Core\Render\RendererInterface $renderer */
     $renderer = $this->container->get('renderer');
     // Create 10 nodes.
     $this->drupalLogin($this->adminUser);
     $this->nodes = array();
     for ($i = 1; $i <= 10; $i++) {
         // Create node.
         $title = $random->name();
         $image = current($this->drupalGetTestFiles('image'));
         $edit = array('title[0][value]' => $title, 'files[field_image_0]' => drupal_realpath($image->uri));
         $this->drupalPostForm('node/add/article', $edit, t('Save'));
         $this->drupalPostForm(NULL, array('field_image[0][alt]' => $title), t('Save'));
         $this->nodes[$i] = $this->drupalGetNodeByTitle($title);
         // Create path alias.
         $path = array('source' => 'node/' . $this->nodes[$i]->id(), 'alias' => "content/{$title}");
         \Drupal::service('path.alias_storage')->save('/node/' . $this->nodes[$i]->id(), "/content/{$title}");
     }
     $this->drupalLogout();
     $this->drupalGet('views-base-url-test');
     $this->assertResponse(200);
     // Check whether there are ten rows.
     $rows = $this->xpath('//div[contains(@class,"view-views-base-url-test")]/div[@class="view-content"]/div[contains(@class,"views-row")]');
     $this->assertEqual(count($rows), 10, t('There are 10 rows'));
     // We check for at least one views result that link is properly rendered as
     // image.
     $node = $this->nodes[1];
     $field = $node->get('field_image');
     $file = $field->entity;
     $value = $field->getValue();
     $image = array('#theme' => 'image', '#uri' => $file->getFileUri(), '#alt' => $value[0]['alt'], '#attributes' => array('width' => $value[0]['width'], 'height' => $value[0]['height']));
     $url = Url::fromUri($base_url . '/' . \Drupal::service('path.alias_manager')->getAliasByPath('/node/' . $node->id()), array('attributes' => array('class' => 'views-base-url-test', 'title' => $node->getTitle(), 'rel' => 'rel-attribute', 'target' => '_blank'), 'fragment' => 'new', 'query' => array('destination' => 'node')));
     $link = \Drupal::l(SafeMarkup::format(str_replace("\n", NULL, $renderer->renderRoot($image))), $url);
     $this->verbose($link);
     $this->assertRaw($link, t('Views base url rendered as link image'));
 }
开发者ID:dev981,项目名称:gaptest,代码行数:42,代码来源:ViewsBaseUrlFieldTest.php


示例12: generateSampleValue

 /**
  * {@inheritdoc}
  */
 public static function generateSampleValue(FieldDefinitionInterface $field_definition)
 {
     $random = new Random();
     $values['alias'] = str_replace(' ', '-', strtolower($random->sentences(3)));
     return $values;
 }
开发者ID:eigentor,项目名称:tommiblog,代码行数:9,代码来源:PathItem.php


示例13: generateSampleValue

 /**
  * {@inheritdoc}
  */
 public static function generateSampleValue(FieldDefinitionInterface $field_definition)
 {
     $random = new Random();
     $settings = $field_definition->getSettings();
     // Generate a file entity.
     $destination = $settings['uri_scheme'] . '://' . $settings['file_directory'] . $random->name(10, TRUE) . '.txt';
     $data = $random->paragraphs(3);
     $file = file_save_data($data, $destination, FILE_EXISTS_ERROR);
     $values = array('target_id' => $file->id(), 'display' => (int) $settings['display_default'], 'description' => $random->sentences(10));
     return $values;
 }
开发者ID:davidsoloman,项目名称:drupalconsole.com,代码行数:14,代码来源:FileItem.php


示例14: getMailCreds

 /**
  * Return a valid mail address.
  */
 protected function getMailCreds()
 {
     if (empty($this->mailCreds)) {
         $creds = $this->fetchUserPassword('drupal', 'mail');
         if ($creds) {
             // Split the parameter based creds on a / separator.
             $creds_array = explode('/', $creds);
             $creds_array += array(2 => 'gmail.com', 3 => 'imap.gmail.com:993');
             // Create keyed array of mail credentials.
             $this->mailCreds = array('user' => $creds_array[0], 'pass' => $creds_array[1], 'host' => $creds_array[2], 'imap' => $creds_array[3]);
             $this->mailCreds['email'] = $this->mailCreds['user'] . '+' . Random::name(8) . '@' . $this->mailCreds['host'];
         }
     }
     return $this->mailCreds;
 }
开发者ID:tag1consulting,项目名称:behat-drupalextension,代码行数:18,代码来源:Tag1Context.php


示例15: 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;
 }
开发者ID:rlhawk,项目名称:encrypt,代码行数:47,代码来源:EncryptionProfile.php


示例16: fillCommerceAddress

 /**
  * Fill commerce address form fields in a single step.
  */
 private function fillCommerceAddress($args, $type)
 {
     // Replace <random> or member <property> token if is set for any field
     foreach ($args as $delta => $arg) {
         if (preg_match("/^<random>\$/", $arg, $matches)) {
             $random = new Random();
             $args[$delta] = $random->name();
         }
     }
     // Need to manually fill country to trigger the AJAX refresh of fields for given country
     $country_field = $this->fixStepArgument("{$type}[commerce_customer_address][und][0][country]");
     $country_value = $this->fixStepArgument($args[4]);
     $this->getSession()->getPage()->fillField($country_field, $country_value);
     $this->iWaitForAjaxToFinish();
     return array(new Given("I fill in \"{$type}[commerce_customer_address][und][0][locality]\" with \"{$args['1']}\""), new Given("I fill in \"{$type}[commerce_customer_address][und][0][administrative_area]\" with \"{$args['2']}\""), new Given("I fill in \"{$type}[commerce_customer_address][und][0][postal_code]\" with \"{$args['3']}\""), new Given("I fill in \"{$type}[commerce_customer_address][und][0][thoroughfare]\" with \"{$args['0']}\""));
 }
开发者ID:achton,项目名称:rooms,代码行数:19,代码来源:FeatureContext.php


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


示例18: generateSampleValue

 /**
  * {@inheritdoc}
  */
 public static function generateSampleValue(FieldDefinitionInterface $field_definition)
 {
     $random = new Random();
     $values['value'] = $random->name() . '@example.com';
     return $values;
 }
开发者ID:papillon-cendre,项目名称:d8,代码行数:9,代码来源:EmailItem.php


示例19: 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);
 }
开发者ID:ddrozdik,项目名称:dmaps,代码行数:12,代码来源:RandomTest.php


示例20: generateSampleValue

 /**
  * {@inheritdoc}
  */
 public static function generateSampleValue(FieldDefinitionInterface $field_definition)
 {
     $random = new Random();
     $settings = $field_definition->getSettings();
     // Prepare destination.
     $dirname = static::doGetUploadLocation($settings);
     file_prepare_directory($dirname, FILE_CREATE_DIRECTORY);
     // Generate a file entity.
     $destination = $dirname . '/' . $random->name(10, TRUE) . '.txt';
     $data = $random->paragraphs(3);
     $file = file_save_data($data, $destination, FILE_EXISTS_ERROR);
     $values = array('target_id' => $file->id(), 'display' => (int) $settings['display_default'], 'description' => $random->sentences(10));
     return $values;
 }
开发者ID:vinodpanicker,项目名称:drupal-under-the-hood,代码行数:17,代码来源:FileItem.php



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP Utility\SafeMarkup类代码示例发布时间:2022-05-23
下一篇:
PHP Utility\NestedArray类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap