本文整理汇总了PHP中Phalcon\Text::random方法的典型用法代码示例。如果您正苦于以下问题:PHP Text::random方法的具体用法?PHP Text::random怎么用?PHP Text::random使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Phalcon\Text
的用法示例。
在下文中一共展示了Text::random方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: beforeValidationOnCreate
public function beforeValidationOnCreate()
{
$this->createdAt = time();
if (!$this->slug) {
$this->slug = \Phalcon\Text::random(\Phalcon\Text::RANDOM_ALNUM, 8);
}
}
示例2: indexAction
public function indexAction()
{
// No view needed since this is all backend stuff.
$this->view->disable();
// Generate random ids until we find one not in use.
// This will cause one additional SQL query at minimum when creating a paste.
do {
$id = Text::random(Text::RANDOM_ALNUM, rand(5, 13));
} while (Paste::findFirstByid($id));
$paste = new Paste();
$paste->id = $id;
$paste->content = rtrim($this->request->getPost("content"));
$paste->lang = $this->request->getPost("lang") == null ? "auto" : $this->request->getPost("lang");
// No sanitisation needed if we accept anything at all to mean true and nothing to mean false.
// Also addresses http://stackoverflow.com/a/14067312
$paste->private = $this->request->getPost("private") == null ? 0 : 1;
$paste->owner_addr = $this->request->getClientAddress();
$paste->size_bytes = strlen($paste->content);
if (!$paste->save()) {
foreach ($paste->getMessages() as $message) {
$this->flash->error($message->getMessage());
}
return $this->response->redirect();
}
return $this->response->redirect($this->url->get("v/{$id}"));
}
示例3: registerAction
public function registerAction()
{
return $this->handleRequest(function () {
$req = new Request();
if ($req->isPost()) {
$post = json_decode($req->getRawBody());
$a = $this->getUserDocument();
$user = new $a();
$user->salt = Text::random(Text::RANDOM_ALNUM);
$user->password = $this->hash($post->password, $user->salt);
unset($post->password);
$post = (array) $post;
foreach ($post as $key => $value) {
$user->{$key} = $value;
}
$user->save();
$this->session->set('user', $user);
} else {
if ($req->isOptions()) {
return '';
}
}
return $this->jsonOutput($user);
});
}
示例4: beforeValidationOnCreate
public function beforeValidationOnCreate()
{
$this->createdAt = $this->createdAt ? $this->createdAt : time();
if (!$this->slug) {
$this->slug = \Phalcon\Text::random(\Phalcon\Text::RANDOM_ALNUM, 8);
}
$this->title = \Eva\EvaEngine\Text\Substring::substrCn(strip_tags($this->getContentHtml()), 100);
}
示例5: beforeValidationOnCreate
public function beforeValidationOnCreate()
{
$this->createdAt = $this->createdAt ? $this->createdAt : time();
if (!$this->slug) {
$this->slug = \Phalcon\Text::random(\Phalcon\Text::RANDOM_ALNUM, 8);
}
$this->validate(new Uniqueness(array('field' => 'slug')));
}
示例6: generateRandomString
/**
* @param int $length length of the string
* @param bool|true $strict whether or not the string should contain a symbol
* @return string
*/
public static function generateRandomString($length, $strict = true)
{
$password = Text::random(Text::RANDOM_ALNUM, $length);
if (!$strict) {
return $password;
}
//todo may add more symbols later
$shuffledSymbols = str_shuffle("@#\$%^&*!+-_~");
return substr($password, 0, strlen($password) - 1) . $shuffledSymbols[0];
}
示例7: apikeyAction
/**
* @operationName("Change API key")
* @operationDescription("Change API key")
*/
public function apikeyAction()
{
if (!$this->request->isPut()) {
return $this->showErrorMessageAsJson(405, 'ERR_REQUEST_METHOD_NOT_ALLOW');
}
$id = $this->dispatcher->getParam('id');
try {
$apikey = Entities\Apikeys::findFirst($id);
if ($apikey) {
$apikey->apikey = \Phalcon\Text::random(\Phalcon\Text::RANDOM_ALNUM, 8);
$apikey->save();
}
} catch (\Exception $e) {
return $this->showExceptionAsJson($e, $apikey->getMessages());
}
return $this->response->setJsonContent($apikey);
}
示例8: getId
public function getId()
{
if ($this->tokenId) {
return $this->tokenId;
}
$request = $this->getDI()->getRequest();
$token = TokenStorage::dicoverToken($this->getDI()->getRequest());
//$token = $request->getHeader('Authorization');
if ($token) {
return $this->tokenId = $token;
} else {
if (!empty($_SERVER['HTTP_CLIENT_IP'])) {
$ip = $_SERVER['HTTP_CLIENT_IP'];
} elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
$ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
} else {
$ip = $_SERVER['REMOTE_ADDR'];
}
//Generate random hash for even same IP
return $this->tokenId = 'ip' . ip2long($ip) . Text::random(Text::RANDOM_ALNUM, 6);
}
}
示例9: setRequestId
public function setRequestId()
{
$this->requestId = Text::random();
}
示例10: random
public static function random($type = 0, $length = 8)
{
return parent::random($type, $length);
}
示例11: uploadByEncodedData
public function uploadByEncodedData($data, $originalName, $mimeType = null)
{
if (!($headPos = strpos($data, ','))) {
throw new Exception\InvalidArgumentException('ERR_FILE_ENCODED_UPLOAD_FORMAT_INCORRECT');
}
$fileHead = substr($data, 0, $headPos + 1);
$fileEncodedData = trim(substr($data, $headPos + 1));
$data = base64_decode($fileEncodedData);
$tmpName = Text::random(\Phalcon\Text::RANDOM_ALNUM, 6);
$tmpPath = $this->getUploadTmpPath();
$tmp = $tmpPath . '/' . $tmpName;
$adapter = new \Gaufrette\Adapter\Local($tmpPath);
$filesystem = new \Gaufrette\Filesystem($adapter);
$filesystem->write($tmpName, $data);
$fileSize = filesize($tmp);
$type = $mimeType;
$filenameArray = explode(".", $originalName);
$fileExtension = strtolower(array_pop($filenameArray));
$originalFileName = implode('.', $filenameArray);
$fileName = Tag::friendlyTitle($originalFileName);
if ($fileName == '-') {
$fileName = Text::random(Text::RANDOM_ALNUM, 6);
}
//hash file less then 10M
if ($fileSize < 1048576 * 10) {
$fileHash = hash_file('CRC32', $tmp, false);
}
if (false === strpos($type, 'image')) {
$isImage = 0;
} else {
$isImage = 1;
}
$fileinfo = array('title' => $originalFileName, 'status' => 'published', 'storageAdapter' => 'local', 'originalName' => $originalName, 'fileSize' => $fileSize, 'mimeType' => $type, 'fileExtension' => $fileExtension, 'fileHash' => $fileHash, 'isImage' => $isImage, 'fileName' => $fileName . '.' . $fileExtension, 'createdAt' => time());
if ($isImage) {
$image = getimagesize($tmp);
$fileinfo['imageWidth'] = $image[0];
$fileinfo['imageHeight'] = $image[1];
}
$filesystem = $this->getDI()->getFileSystem();
$path = md5(time());
$path = str_split($path, 2);
$pathlevel = $this->getUploadPathLevel();
$pathlevel = $pathlevel > 6 ? 6 : $pathlevel;
$path = array_slice($path, 0, $pathlevel);
$filePath = implode('/', $path);
$path = $filePath . '/' . $fileName . '.' . $fileExtension;
$fileinfo['filePath'] = $filePath;
$this->assign($fileinfo);
if ($this->save()) {
if (!$filesystem->has($path)) {
if ($filesystem->write($path, file_get_contents($tmp))) {
unlink($tmp);
} else {
throw new Exception\IOException('ERR_FILE_MOVE_TO_STORAGE_FAILED');
}
} else {
throw new Exception\ResourceConflictException('ERR_FILE_UPLOAD_BY_CONFLICT_NAME');
}
} else {
throw new Exception\RuntimeException('ERR_FILE_SAVE_TO_DB_FAILED');
}
return $this;
}
示例12: testRandomNonZero
public function testRandomNonZero()
{
for ($i = 1; $i < 10; $i++) {
$text = PhText::random(PhText::RANDOM_NOZERO, $i);
$this->assertEquals(preg_match('/[1-9]+/', $text, $matches), 1);
$this->assertEquals($matches[0], $text);
$this->assertEquals(strlen($text), $i);
}
}
示例13: testRandomDefaultLength
public function testRandomDefaultLength()
{
$generated = \Phalcon\Text::random(\Phalcon\Text::RANDOM_NOZERO);
$this->assertEquals(strlen($generated), 8);
}
示例14: generateToken
/**
* issue a generic token
* replace with your own logic
*
* @return multitype:boolean NULL
*/
public function generateToken()
{
return \Phalcon\Text::random(\Phalcon\Text::RANDOM_ALNUM, 64);
}
示例15: beforeValidationOnCreate
public function beforeValidationOnCreate()
{
$this->createdAt = time();
$this->apikey = \Phalcon\Text::random(\Phalcon\Text::RANDOM_ALNUM, 8);
}