當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Text::random方法代碼示例

本文整理匯總了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);
     }
 }
開發者ID:skybird,項目名稱:phalcon,代碼行數:7,代碼來源:Category.php

示例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}"));
 }
開發者ID:carriercomm,項目名稱:Phaste,代碼行數:26,代碼來源:NewController.php

示例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);
     });
 }
開發者ID:serus22,項目名稱:phalconz,代碼行數:25,代碼來源:AuthController.php

示例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);
 }
開發者ID:skybird,項目名稱:phalcon,代碼行數:8,代碼來源:NewsManager.php

示例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')));
 }
開發者ID:skybird,項目名稱:phalcon,代碼行數:8,代碼來源:Post.php

示例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];
 }
開發者ID:cottacush,項目名稱:phalcon-user-auth,代碼行數:15,代碼來源:Utils.php

示例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);
 }
開發者ID:skybird,項目名稱:phalcon,代碼行數:21,代碼來源:ProcessController.php

示例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);
     }
 }
開發者ID:keepeye,項目名稱:EvaEngine,代碼行數:22,代碼來源:TokenStorage.php

示例9: setRequestId

 public function setRequestId()
 {
     $this->requestId = Text::random();
 }
開發者ID:sergeytkachenko,項目名稱:phalcon-rest-jpa,代碼行數:4,代碼來源:Manager.php

示例10: random

 public static function random($type = 0, $length = 8)
 {
     return parent::random($type, $length);
 }
開發者ID:lisong,項目名稱:cphalcon,代碼行數:4,代碼來源:Text.php

示例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;
 }
開發者ID:skybird,項目名稱:phalcon,代碼行數:63,代碼來源:Upload.php

示例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);
     }
 }
開發者ID:lisong,項目名稱:cphalcon,代碼行數:9,代碼來源:UnitTest.php

示例13: testRandomDefaultLength

 public function testRandomDefaultLength()
 {
     $generated = \Phalcon\Text::random(\Phalcon\Text::RANDOM_NOZERO);
     $this->assertEquals(strlen($generated), 8);
 }
開發者ID:aisuhua,項目名稱:phalcon-php,代碼行數:5,代碼來源:TextTest.php

示例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);
 }
開發者ID:marceloandrader,項目名稱:phalcon-json-api-package,代碼行數:10,代碼來源:UserProfile.php

示例15: beforeValidationOnCreate

 public function beforeValidationOnCreate()
 {
     $this->createdAt = time();
     $this->apikey = \Phalcon\Text::random(\Phalcon\Text::RANDOM_ALNUM, 8);
 }
開發者ID:skybird,項目名稱:phalcon,代碼行數:5,代碼來源:Apikey.php


注:本文中的Phalcon\Text::random方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。