本文整理汇总了PHP中Zend\Math\Rand::getString方法的典型用法代码示例。如果您正苦于以下问题:PHP Rand::getString方法的具体用法?PHP Rand::getString怎么用?PHP Rand::getString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend\Math\Rand
的用法示例。
在下文中一共展示了Rand::getString方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: createAction
/**
*
*/
public function createAction()
{
$isPublic = (bool) ($this->params('public') ?: $this->showPrompt('public'));
$description = $this->params('description') ?: $this->showPrompt('description');
$grantTypes = $this->params('grant-types') ?: $this->showPrompt('grant-types');
$redirectUri = $this->params('redirect-uri') ?: $this->showPrompt('redirect-uri');
$secret = null;
$encryptedSecret = null;
if (!$isPublic) {
$secret = Rand::getString(32);
$encryptedSecret = $this->password->create($secret);
}
if ($grantTypes) {
$grantTypes = explode(',', $grantTypes);
array_walk($grantTypes, function (&$grant) {
$grant = trim($grant);
});
}
$client = new Client(null, $encryptedSecret, null, $grantTypes, $redirectUri, $description);
$this->clientMapper->save($client);
$this->getConsole()->writeLine();
$this->getConsole()->writeLine('* Client created *', Color::GREEN);
if (!$isPublic) {
$this->getConsole()->writeLine('The client secret was auto-generated and encrypted. Please store it safely.');
$this->getConsole()->writeLine("Don't ever disclose the client secret publicly", Color::YELLOW);
$this->getConsole()->writeLine();
}
$this->getConsole()->writeLine("UUID: \t\t" . $client->getUuid());
if (!$isPublic) {
$this->getConsole()->writeLine("Secret: \t" . $secret);
}
$this->getConsole()->writeLine("Grant types: \t" . implode(', ', $client->getGrantTypes()));
$this->getConsole()->writeLine("Description: \t" . $client->getDescription());
$this->getConsole()->writeLine("Redirect URI: \t" . $client->getRedirectUri());
}
示例2: provider
/**
* @return array
*/
public function provider()
{
$dateTime = new \DateTime();
$dateStart = $dateTime->sub(new \DateInterval('P1Y'));
$dateEnd = $dateTime->add(new \DateInterval('P4Y'));
$dateTime = new \DateTime();
$dateStartActual = $dateTime->sub(new \DateInterval('P6M'));
$dateEndActual = $dateTime->add(new \DateInterval('P3Y'));
$contactTest = new ContactTest();
$callTest = new CallTest();
$project = new Project();
$project->setCall($callTest->provider()[0][0]);
$project->setDateStart($dateStart);
$project->setDateEnd($dateEnd);
$project->setDateStartActual($dateStartActual);
$project->setDateEndActual($dateEndActual);
$project->setNumber(Rand::getString(4));
$project->setContact($contactTest->provider()[0][0]);
$project->setSummary('This is the summary');
$project->setDescription('This is the description');
$versionType = new Type();
$versionType->setType('Type');
$versionType->setId(1);
return [[$project, $versionType]];
}
示例3: indexAction
public function indexAction()
{
$this->requireLogin();
$keyRepo = $this->getEntityManager()->getRepository('Frontend\\Api\\Entity\\Key');
$userKey = $keyRepo->findOneBy(array('user' => $this->identity()));
if ($this->getRequest()->getQuery('getKey') == 1 && !$userKey) {
// add to api
$keyChars = array_merge(range(0, 9), range('A', 'Z'), range('a', 'z'));
$apiKey = Rand::getString(50, implode('', $keyChars));
$userKey = new Key();
$userKey->setKey($apiKey);
$userKey->setLimit($userKey->getDefaultRateLimit());
$userKey->setUser($this->getEntityManager()->getReference('Auth\\Entity\\Benutzer', $this->identity()->getId()));
$userKey->setRequests(0);
$userKey->setStatus(1);
try {
$this->getEntityManager()->persist($userKey);
$this->getEntityManager()->flush();
$this->flashMessenger()->addSuccessMessage('Nice! Subscribe to API successfully. Can\'t wait to hear about your application');
} catch (\Exception $e) {
$this->flashMessenger()->addErrorMessage('Balls...something went wrong :/');
}
}
$viewModel = new ViewModel();
$viewModel->setTemplate('/api/index.phtml');
$viewModel->setVariable('userKey', $userKey);
return $viewModel;
}
示例4: passwordAction
public function passwordAction()
{
$request = $this->getRequest();
// Make sure that we are running in a console and the user has not
// tricked our
// application into running this action from a public web server.
if (!$request instanceof ConsoleRequest) {
throw new \RuntimeException('You can only use this action from a console!');
}
// Get user email from console and check if the user used --verbose or
// -v flag
$userEmail = $request->getParam('userEmail');
$verbose = $request->getParam('verbose');
// reset new password
$newPassword = Rand::getString(16);
$console = Console::getInstance();
if (Confirm::prompt('Is this the correct answer? [y/n]', 'y', 'n')) {
$console->write("You chose YES\n");
} else {
$console->write("You chose NO\n");
}
if (!$verbose) {
return "Done! {$userEmail} has received an email with his new password.\n";
} else {
return "Done! New password for user {$userEmail} is '{$newPassword}'. It has also been emailed to him. \n";
}
}
示例5: generateRandomSlug
/**
* Generate a random slug
*
* @param integer $slugLength
* @param string $slugChars
* @return string
*/
public static function generateRandomSlug($slugLength = 10, $slugChars = null)
{
if (!$slugChars) {
$slugChars = 'abcdefghijklmnopqrstuvwxyz';
}
return Rand::getString($slugLength, $slugChars, true);
}
示例6: testRoleSynchronisation
/**
* Test role synchronisation
*/
public function testRoleSynchronisation()
{
// create a first test ACL role
$query = $this->model->insert()->into('acl_role')->values(['name' => 'test role 1']);
$statement = $this->model->prepareStatementForSqlObject($query);
$statement->execute();
$this->aclRolesIds[] = $this->model->getAdapter()->getDriver()->getLastGeneratedValue();
// create a test user
$query = $this->model->insert()->into('user_list')->values(['nick_name' => Rand::getString(32), 'email' => Rand::getString(32), 'role' => $this->aclRolesIds[0]]);
$statement = $this->model->prepareStatementForSqlObject($query);
$statement->execute();
$this->usersIds[] = $this->model->getAdapter()->getDriver()->getLastGeneratedValue();
// delete the created ACL role
$query = $this->model->delete()->from('acl_role')->where(['id' => $this->aclRolesIds[0]]);
$statement = $this->model->prepareStatementForSqlObject($query);
$statement->execute();
// fire the delete ACL role event
AclEvent::fireDeleteAclRoleEvent($this->aclRolesIds[0]);
// check the created test user's role
$select = $this->model->select();
$select->from('user_list')->columns(['role'])->where(['user_id' => $this->usersIds[0]]);
$statement = $this->model->prepareStatementForSqlObject($select);
$resultSet = new ResultSet();
$result = $resultSet->initialize($statement->execute());
// user must be a default member
$this->assertEquals($result->current()['role'], AclBaseModel::DEFAULT_ROLE_MEMBER);
}
示例7: populateGeneral
private function populateGeneral(AbstractContact $contact)
{
$contact->setNotes('This is a note for this contact.');
if (Rand::getFloat(true) < 0.8) {
$contact->setDisplayName(Rand::getString(32));
}
}
示例8: addAclResources
/**
* Add acl resources
*
* @param array $resources
* @param boolean $createConnections
* @param integer $userRole
*/
protected function addAclResources($resources, $createConnections = true, $userRole = AclModelBase::DEFAULT_ROLE_MEMBER)
{
// create a test user
$userData = ['nick_name' => Rand::getString(32), 'email' => Rand::getString(32), 'role' => $userRole];
// add member
$query = $this->aclModelBase->insert()->into('user_list')->values($userData);
$statement = $this->aclModelBase->prepareStatementForSqlObject($query);
$statement->execute();
$this->userId = $this->aclModelBase->getAdapter()->getDriver()->getLastGeneratedValue();
// create new resources
foreach ($resources as $resource) {
// add new test resource
$query = $this->aclModelBase->insert()->into('acl_resource')->values(['resource' => $resource, 'module' => 1, 'description' => '']);
$statement = $this->aclModelBase->prepareStatementForSqlObject($query);
$statement->execute();
$resourceId = $this->aclModelBase->getAdapter()->getDriver()->getLastGeneratedValue();
$this->aclResourcesIds[] = $resourceId;
if ($createConnections) {
$query = $this->aclModelBase->insert()->into('acl_resource_connection')->values(['role' => $userRole, 'resource' => $resourceId]);
$statement = $this->aclModelBase->prepareStatementForSqlObject($query);
$statement->execute();
$this->aclResourcesConnections[] = $this->aclModelBase->getAdapter()->getDriver()->getLastGeneratedValue();
}
}
}
示例9: runAction
public function runAction()
{
$em = $this->getEntityManager();
$console = $this->getServiceLocator()->get('console');
$schemaTool = new \Doctrine\ORM\Tools\SchemaTool($em);
$console->writeLine('建立資料表中, 請稍待!!', ColorInterface::GREEN);
$classes = $em->getMetadataFactory()->getAllMetadata();
if ($this->params()->fromRoute('re-create-database')) {
$schemaTool->dropSchema($classes);
}
$schemaTool->createSchema($classes);
// 安裝預設管理人員及選單
$username = 'admin';
$password = \Zend\Math\Rand::getString(8, null, true);
$user = new \Base\Entity\User();
$user->setUsername($username);
$user->setPassword(\Zend\Ldap\Attribute::createPassword($password));
$user->setDisplayName('管理者');
$user->setRole('admin');
$em->persist($user);
$em->flush();
$menu = new \Base\Entity\Menu();
$menu->setName('首頁');
$menu->setUser($user);
$params = ['max_records' => 10, 'order_kind' => 'desc', 'term' => ''];
$menu->setParams(serialize($params));
$em->persist($menu);
$em->flush();
$console->writeLine('建立完成!!', ColorInterface::GREEN);
$console->writeLine('預設帳號 ' . $username . ', 密碼 ' . $password, ColorInterface::GREEN);
}
示例10: provider
/**
* @return array
*/
public function provider()
{
$contentType = new ContentType();
$contentType->setContentType('test/' . Rand::getString(12));
$contentType->setDescription('This is the description ' . Rand::getString(12));
$contentType->setExtension(Rand::getString(4));
return [[$contentType]];
}
示例11: generate
/**
* @param int $len
* @return string
* @throws \InvalidArgumentException
*/
public static function generate($len = 32)
{
if ($len > 255) {
throw new \InvalidArgumentException(sprintf("assoc handle len must be lower or equal to 255(%d)", $len));
}
$new_assoc_handle = Rand::getString($len, self::PrintableNonWhitespaceCharacters, true);
return $new_assoc_handle;
}
示例12: provider
/**
* @return array
*/
public function provider()
{
$gender = new Gender();
$gender->setName(Rand::getString(4));
$gender->setAttention('attention:' . Rand::getString(4));
$gender->setSalutation('This is the salutation');
return [[$gender]];
}
示例13: provider
/**
* @return array
*/
public function provider()
{
$title = new Title();
$title->setName(Rand::getString(4));
$title->setAttention('attention:' . Rand::getString(4));
$title->setSalutation('This is the salutation');
return [[$title]];
}
示例14: getGuestId
/**
* Get guest id
*
* @return string
*/
public function getGuestId()
{
$container = new SessionContainer('comment');
// generate custom guest id
if (empty($container->guestId)) {
$container->guestId = Rand::getString(self::COMMENT_GUEST_ID_LENGTH, 'abcdefghijklmnopqrstuvwxyz', true);
}
return $container->guestId;
}
示例15: formBigInteger
public function formBigInteger()
{
$bigInt = BigInteger::factory('bcmath');
$x = Rand::getString(100, '0123456789');
$y = Rand::getString(100, '0123456789');
$sum = $bigInt->add($x, $y);
$len = strlen($sum);
$this->data->bigint = "{$x} + {$y} = {$sum}";
$this->render();
}