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


PHP Strings::random方法代码示例

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


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

示例1: generateMessage

 /**
  * Returns encoded message.
  * @return string
  */
 public function generateMessage()
 {
     $output = '';
     $boundary = '--------' . Strings::random();
     foreach ($this->headers as $name => $value) {
         $output .= $name . ': ' . $this->getEncodedHeader($name);
         if ($this->parts && $name === 'Content-Type') {
             $output .= ';' . self::EOL . "\tboundary=\"{$boundary}\"";
         }
         $output .= self::EOL;
     }
     $output .= self::EOL;
     $body = (string) $this->body;
     if ($body !== '') {
         switch ($this->getEncoding()) {
             case self::ENCODING_QUOTED_PRINTABLE:
                 $output .= function_exists('quoted_printable_encode') ? quoted_printable_encode($body) : self::encodeQuotedPrintable($body);
                 break;
             case self::ENCODING_BASE64:
                 $output .= rtrim(chunk_split(base64_encode($body), self::LINE_LENGTH, self::EOL));
                 break;
             case self::ENCODING_7BIT:
                 $body = preg_replace('#[\\x80-\\xFF]+#', '', $body);
                 // break intentionally omitted
             // break intentionally omitted
             case self::ENCODING_8BIT:
                 $body = str_replace(array("", "\r"), '', $body);
                 $body = str_replace("\n", self::EOL, $body);
                 $output .= $body;
                 break;
             default:
                 throw new InvalidStateException('Unknown encoding.');
         }
     }
     if ($this->parts) {
         if (substr($output, -strlen(self::EOL)) !== self::EOL) {
             $output .= self::EOL;
         }
         foreach ($this->parts as $part) {
             $output .= '--' . $boundary . self::EOL . $part->generateMessage() . self::EOL;
         }
         $output .= '--' . $boundary . '--';
     }
     return $output;
 }
开发者ID:riskatlas,项目名称:micka,代码行数:49,代码来源:MimePart.php

示例2: nodeOpened

 /**
  * New node is found.
  * @return bool
  */
 public function nodeOpened(MacroNode $node)
 {
     $this->used = TRUE;
     $node->isEmpty = FALSE;
     $node->openingCode = PhpWriter::using($node)->write('<?php if (CacheMacro::createCache($netteCacheStorage, %var, $_g->caches, %node.array?)) { ?>', Strings::random());
 }
开发者ID:riskatlas,项目名称:micka,代码行数:10,代码来源:CacheMacro.php

示例3: addProtection

 /**
  * Cross-Site Request Forgery (CSRF) form protection.
  * @param  string
  * @param  int
  * @return void
  */
 public function addProtection($message = NULL, $timeout = NULL)
 {
     $session = $this->getSession()->getSection('Nette.Forms.Form/CSRF');
     $key = "key{$timeout}";
     if (isset($session->{$key})) {
         $token = $session->{$key};
     } else {
         $session->{$key} = $token = Strings::random();
     }
     $session->setExpiration($timeout, $key);
     $this[self::PROTECTOR_ID] = new HiddenField($token);
     $this[self::PROTECTOR_ID]->addRule(self::PROTECTION, $message, $token);
 }
开发者ID:riskatlas,项目名称:micka,代码行数:19,代码来源:Form.php

示例4: __destruct

 /**
  * @return void
  */
 public function __destruct()
 {
     if (self::$fixIE && isset($_SERVER['HTTP_USER_AGENT']) && strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE ') !== FALSE && in_array($this->code, array(400, 403, 404, 405, 406, 408, 409, 410, 500, 501, 505), TRUE) && $this->getHeader('Content-Type', 'text/html') === 'text/html') {
         echo Strings::random(2000.0, " \t\r\n");
         // sends invisible garbage for IE
         self::$fixIE = FALSE;
     }
 }
开发者ID:riskatlas,项目名称:micka,代码行数:11,代码来源:Response.php

示例5: getFlashSession

 /**
  * Returns session namespace provided to pass temporary data between redirects.
  * @return SessionSection
  */
 public function getFlashSession()
 {
     if (empty($this->params[self::FLASH_KEY])) {
         $this->params[self::FLASH_KEY] = Strings::random(4);
     }
     return $this->getSession('Nette.Application.Flash/' . $this->params[self::FLASH_KEY]);
 }
开发者ID:riskatlas,项目名称:micka,代码行数:11,代码来源:Presenter.php

示例6: writeAttrsMacro

 /**
  * Generates code for macro <tag n:attr> to the output.
  * @param  string
  * @return void
  */
 public function writeAttrsMacro($code, HtmlNode $htmlNode)
 {
     $attrs = $htmlNode->macroAttrs;
     $left = $right = array();
     $attrCode = '';
     foreach ($this->macros as $name => $foo) {
         $attrName = MacroNode::PREFIX_INNER . "-{$name}";
         if (isset($attrs[$attrName])) {
             if ($htmlNode->closing) {
                 $left[] = array("/{$name}", '', MacroNode::PREFIX_INNER);
             } else {
                 array_unshift($right, array($name, $attrs[$attrName], MacroNode::PREFIX_INNER));
             }
             unset($attrs[$attrName]);
         }
     }
     foreach (array_reverse($this->macros) as $name => $foo) {
         $attrName = MacroNode::PREFIX_TAG . "-{$name}";
         if (isset($attrs[$attrName])) {
             $left[] = array($name, $attrs[$attrName], MacroNode::PREFIX_TAG);
             array_unshift($right, array("/{$name}", '', MacroNode::PREFIX_TAG));
             unset($attrs[$attrName]);
         }
     }
     foreach ($this->macros as $name => $foo) {
         if (isset($attrs[$name])) {
             if ($htmlNode->closing) {
                 $right[] = array("/{$name}", '', NULL);
             } else {
                 array_unshift($left, array($name, $attrs[$name], NULL));
             }
             unset($attrs[$name]);
         }
     }
     if ($attrs) {
         throw new CompileException("Unknown macro-attribute " . Parser::N_PREFIX . implode(' and ' . Parser::N_PREFIX, array_keys($attrs)));
     }
     if (!$htmlNode->closing) {
         $htmlNode->attrCode =& $this->attrCodes[$uniq = ' n:' . Strings::random()];
         $code = substr_replace($code, $uniq, ($tmp = strrpos($code, '/>')) ? $tmp : strrpos($code, '>'), 0);
     }
     foreach ($left as $item) {
         $node = $this->writeMacro($item[0], $item[1], NULL, NULL, $htmlNode, $item[2]);
         if ($node->closing || $node->isEmpty) {
             $htmlNode->attrCode .= $node->attrCode;
             if ($node->isEmpty) {
                 unset($htmlNode->macroAttrs[$node->name]);
             }
         }
     }
     $this->output .= $code;
     foreach ($right as $item) {
         $node = $this->writeMacro($item[0], $item[1], NULL, NULL, $htmlNode);
         if ($node->closing) {
             $htmlNode->attrCode .= $node->attrCode;
         }
     }
     if ($right && substr($this->output, -2) === '?>') {
         $this->output .= "\n";
     }
 }
开发者ID:riskatlas,项目名称:micka,代码行数:66,代码来源:Compiler.php

示例7: getRandomId

 /** @return string */
 private function getRandomId()
 {
     return '<' . Strings::random() . '@' . (isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : (isset($_SERVER['SERVER_NAME']) ? $_SERVER['SERVER_NAME'] : 'localhost')) . '>';
 }
开发者ID:riskatlas,项目名称:micka,代码行数:5,代码来源:Message.php

示例8: start

 /**
  * Starts and initializes session data.
  * @throws InvalidStateException
  * @return void
  */
 public function start()
 {
     if (self::$started) {
         return;
     }
     $this->configure($this->options);
     Debugger::tryError();
     session_start();
     if (Debugger::catchError($e) && !session_id()) {
         @session_write_close();
         // this is needed
         throw new InvalidStateException('session_start(): ' . $e->getMessage(), 0, $e);
     }
     self::$started = TRUE;
     /* structure:
     			__NF: Counter, BrowserKey, Data, Meta, Time
     				DATA: section->variable = data
     				META: section->variable = Timestamp, Browser, Version
     		*/
     unset($_SESSION['__NT'], $_SESSION['__NS'], $_SESSION['__NM']);
     // old unused structures
     // initialize structures
     $nf =& $_SESSION['__NF'];
     if (empty($nf)) {
         // new session
         $nf = array('C' => 0);
     } else {
         $nf['C']++;
     }
     // session regenerate every 30 minutes
     $nfTime =& $nf['Time'];
     $time = time();
     if ($time - $nfTime > self::REGENERATE_INTERVAL) {
         $this->regenerated = $this->regenerated || isset($nfTime);
         $nfTime = $time;
     }
     // browser closing detection
     $browserKey = $this->request->getCookie('nette-browser');
     if (!$browserKey) {
         $browserKey = Strings::random();
     }
     $browserClosed = !isset($nf['B']) || $nf['B'] !== $browserKey;
     $nf['B'] = $browserKey;
     // resend cookie
     $this->sendCookie();
     // process meta metadata
     if (isset($nf['META'])) {
         $now = time();
         // expire section variables
         foreach ($nf['META'] as $section => $metadata) {
             if (is_array($metadata)) {
                 foreach ($metadata as $variable => $value) {
                     if (!empty($value['B']) && $browserClosed || !empty($value['T']) && $now > $value['T'] || isset($nf['DATA'][$section][$variable]) && is_object($nf['DATA'][$section][$variable]) && (isset($value['V']) ? $value['V'] : NULL) != ClassReflection::from($nf['DATA'][$section][$variable])->getAnnotation('serializationVersion')) {
                         if ($variable === '') {
                             // expire whole section
                             unset($nf['META'][$section], $nf['DATA'][$section]);
                             continue 2;
                         }
                         unset($nf['META'][$section][$variable], $nf['DATA'][$section][$variable]);
                     }
                 }
             }
         }
     }
     if ($this->regenerated) {
         $this->regenerated = FALSE;
         $this->regenerateId();
     }
     register_shutdown_function(array($this, 'clean'));
 }
开发者ID:riskatlas,项目名称:micka,代码行数:75,代码来源:Session.php


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