当前位置: 首页>>代码示例>>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;未经允许,请勿转载。