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


PHP String::random方法代码示例

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


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

示例1: addProtection

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

示例2: __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 Nette\String::random(2000.0, " \t\r\n");
         // sends invisible garbage for IE
         self::$fixIE = FALSE;
     }
 }
开发者ID:JanTvrdik,项目名称:nette,代码行数:11,代码来源:HttpResponse.php

示例3: initialize

	/**
	 * Initializes parsing.
	 * @param  LatteFilter
	 * @param  string
	 * @return void
	 */
	public function initialize($filter, & $s)
	{
		$this->filter = $filter;
		$this->nodes = array();
		$this->blocks = array();
		$this->namedBlocks = array();
		$this->extends = NULL;
		$this->uniq = String::random();
		$this->cacheCounter = 0;

		$filter->context = LatteFilter::CONTEXT_TEXT;
		$filter->escape = 'Nette\Templates\TemplateHelpers::escapeHtml';
	}
开发者ID:JanTvrdik,项目名称:StaticWeb,代码行数:19,代码来源:LatteMacros.php

示例4: generateMessage

	/**
	 * Returns encoded message.
	 * @return string
	 */
	public function generateMessage()
	{
		$output = '';
		$boundary = '--------' . Nette\String::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

			case self::ENCODING_8BIT:
				$body = str_replace(array("\x00", "\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:newPOPE,项目名称:screencast,代码行数:54,代码来源:MailMimePart.php

示例5: storeRequest

	/**
	 * Stores current request to session.
	 * @param  mixed  optional expiration time
	 * @return string key
	 */
	public function storeRequest($expiration = '+ 10 minutes')
	{
		$session = $this->getSession('Nette.Application/requests');
		do {
			$key = Nette\String::random(5);
		} while (isset($session[$key]));

		$session[$key] = end($this->requests);
		$session->setExpiration($expiration, $key);
		return $key;
	}
开发者ID:redhead,项目名称:nette,代码行数:16,代码来源:Application.php

示例6: build

	/**
	 * Builds email.
	 * @return void
	 */
	protected function build()
	{
		$mail = clone $this;
		$hostname = isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : (isset($_SERVER['SERVER_NAME']) ? $_SERVER['SERVER_NAME'] : 'localhost');
		$mail->setHeader('Message-ID', '<' . String::random() . "@$hostname>");

		$mail->buildHtml();
		$mail->buildText();

		$cursor = $mail;
		if ($mail->attachments) {
			$tmp = $cursor->setContentType('multipart/mixed');
			$cursor = $cursor->addPart();
			foreach ($mail->attachments as $value) {
				$tmp->addPart($value);
			}
		}

		if ($mail->html != NULL) { // intentionally ==
			$tmp = $cursor->setContentType('multipart/alternative');
			$cursor = $cursor->addPart();
			$alt = $tmp->addPart();
			if ($mail->inlines) {
				$tmp = $alt->setContentType('multipart/related');
				$alt = $alt->addPart();
				foreach ($mail->inlines as $name => $value) {
					$tmp->addPart($value);
				}
			}
			$alt->setContentType('text/html', 'UTF-8')
				->setEncoding(preg_match('#[\x80-\xFF]#', $mail->html) ? self::ENCODING_8BIT : self::ENCODING_7BIT)
				->setBody($mail->html);
		}

		$text = $mail->getBody();
		$mail->setBody(NULL);
		$cursor->setContentType('text/plain', 'UTF-8')
			->setEncoding(preg_match('#[\x80-\xFF]#', $text) ? self::ENCODING_8BIT : self::ENCODING_7BIT)
			->setBody($text);

		return $mail;
	}
开发者ID:newPOPE,项目名称:screencast,代码行数:46,代码来源:Mail.php

示例7: start

	/**
	 * Starts and initializes session data.
	 * @throws \InvalidStateException
	 * @return void
	 */
	public function start()
	{
		if (self::$started) {
			return;

		} elseif (self::$started === NULL && defined('SID')) {
			throw new \InvalidStateException('A session had already been started by session.auto-start or session_start().');
		}

		$this->configure($this->options);

		Nette\Debug::tryError();
		session_start();
		if (Nette\Debug::catchError($e)) {
			@session_write_close(); // this is needed
			throw new \InvalidStateException($e->getMessage());
		}

		self::$started = TRUE;
		if ($this->regenerationNeeded) {
			session_regenerate_id(TRUE);
			$this->regenerationNeeded = FALSE;
		}

		/* structure:
			__NF: Counter, BrowserKey, Data, Meta
				DATA: namespace->variable = data
				META: namespace->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']++;
		}

		// browser closing detection
		$browserKey = $this->getHttpRequest()->getCookie('nette-browser');
		if (!$browserKey) {
			$browserKey = Nette\String::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 namespace variables
			foreach ($nf['META'] as $namespace => $metadata) {
				if (is_array($metadata)) {
					foreach ($metadata as $variable => $value) {
						if ((!empty($value['B']) && $browserClosed) || (!empty($value['T']) && $now > $value['T']) // whenBrowserIsClosed || Time
							|| ($variable !== '' && is_object($nf['DATA'][$namespace][$variable]) && (isset($value['V']) ? $value['V'] : NULL) // Version
								!== Nette\Reflection\ClassReflection::from($nf['DATA'][$namespace][$variable])->getAnnotation('serializationVersion'))) {

							if ($variable === '') { // expire whole namespace
								unset($nf['META'][$namespace], $nf['DATA'][$namespace]);
								continue 2;
							}
							unset($nf['META'][$namespace][$variable], $nf['DATA'][$namespace][$variable]);
						}
					}
				}
			}
		}

		register_shutdown_function(array($this, 'clean'));
	}
开发者ID:JanTvrdik,项目名称:StaticWeb,代码行数:80,代码来源:Session.php

示例8: getFlashSession

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


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