本文整理汇总了PHP中Magento\Framework\Math\Random::getRandomString方法的典型用法代码示例。如果您正苦于以下问题:PHP Random::getRandomString方法的具体用法?PHP Random::getRandomString怎么用?PHP Random::getRandomString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Magento\Framework\Math\Random
的用法示例。
在下文中一共展示了Random::getRandomString方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getFormKey
/**
* Retrieve Session Form Key
*
* @return string A 16 bit unique key for forms
*/
public function getFormKey()
{
if (!$this->isPresent()) {
$this->set($this->mathRandom->getRandomString(16));
}
return $this->escaper->escapeHtmlAttr($this->session->getData(self::FORM_KEY));
}
示例2: changeEncryptionKey
/**
* Change encryption key
*
* @param string|null $key
* @return null|string
* @throws \Exception
*/
public function changeEncryptionKey($key = null)
{
// prepare new key, encryptor and new configuration segment
if (!$this->writer->checkIfWritable()) {
throw new \Exception(__('Deployment configuration file is not writable.'));
}
if (null === $key) {
$key = md5($this->random->getRandomString(ConfigOptionsListConstants::STORE_KEY_RANDOM_STRING_SIZE));
}
$this->encryptor->setNewKey($key);
$encryptSegment = new ConfigData(ConfigFilePool::APP_ENV);
$encryptSegment->set(ConfigOptionsListConstants::CONFIG_PATH_CRYPT_KEY, $this->encryptor->exportKeys());
$configData = [$encryptSegment->getFileKey() => $encryptSegment->getData()];
// update database and config.php
$this->beginTransaction();
try {
$this->_reEncryptSystemConfigurationValues();
$this->_reEncryptCreditCardNumbers();
$this->writer->saveConfig($configData);
$this->commit();
return $key;
} catch (\Exception $e) {
$this->rollBack();
throw $e;
}
}
示例3: getPaymentDetailsId
/**
* @return string
*/
public function getPaymentDetailsId()
{
if ($this->isInMiniCart()) {
return 'braintree_paypal_payment_details_minicart';
} else {
return 'braintree_paypal_payment_details' . $this->mathRandom->getRandomString(5);
}
}
示例4: createCryptConfig
/**
* Creates encryption key config data
* @param array $data
* @return ConfigData
*/
public function createCryptConfig(array $data)
{
$currentKey = $this->deploymentConfig->get(ConfigOptionsListConstants::CONFIG_PATH_CRYPT_KEY);
$configData = new ConfigData(ConfigFilePool::APP_ENV);
if (isset($data[ConfigOptionsListConstants::INPUT_KEY_ENCRYPTION_KEY])) {
if ($currentKey !== null) {
$key = $currentKey . "\n" . $data[ConfigOptionsListConstants::INPUT_KEY_ENCRYPTION_KEY];
} else {
$key = $data[ConfigOptionsListConstants::INPUT_KEY_ENCRYPTION_KEY];
}
$configData->set(ConfigOptionsListConstants::CONFIG_PATH_CRYPT_KEY, $key);
} else {
if ($currentKey === null) {
$configData->set(ConfigOptionsListConstants::CONFIG_PATH_CRYPT_KEY, md5($this->random->getRandomString(ConfigOptionsListConstants::STORE_KEY_RANDOM_STRING_SIZE)));
}
}
return $configData;
}
示例5: indexAction
/**
* @return JsonModel
*/
public function indexAction()
{
$this->logger->clear();
$data = Json::decode($this->getRequest()->getContent(), Json::TYPE_ARRAY);
$this->config->setConfigData($data);
$this->config->install();
$this->setupFactory->setConfig($this->config->getConfigData());
$moduleNames = array_keys($this->moduleList);
foreach ($moduleNames as $moduleName) {
$setup = $this->setupFactory->create($moduleName);
$setup->applyUpdates();
$this->logger->logSuccess($moduleName);
}
$this->logger->logSuccess('Artifact');
// Set data to config
$setup->addConfigData('web/seo/use_rewrites', isset($data['config']['rewrites']['allowed']) ? $data['config']['rewrites']['allowed'] : 0);
$setup->addConfigData('web/unsecure/base_url', isset($data['config']['address']['web']) ? $data['config']['address']['web'] : '{{unsecure_base_url}}');
$setup->addConfigData('web/secure/use_in_frontend', isset($data['config']['https']['front']) ? $data['config']['https']['front'] : 0);
$setup->addConfigData('web/secure/base_url', isset($data['config']['address']['web']) ? $data['config']['address']['web'] : '{{secure_base_url}}');
$setup->addConfigData('web/secure/use_in_adminhtml', isset($data['config']['https']['admin']) ? $data['config']['https']['admin'] : 0);
$setup->addConfigData('general/locale/code', isset($data['store']['language']) ? $data['store']['language'] : 'en_US');
$setup->addConfigData('general/locale/timezone', isset($data['store']['timezone']) ? $data['store']['timezone'] : 'America/Los_Angeles');
$currencyCode = isset($data['store']['currency']) ? $data['store']['currency'] : 'USD';
$setup->addConfigData('currency/options/base', $currencyCode);
$setup->addConfigData('currency/options/default', $currencyCode);
$setup->addConfigData('currency/options/allow', $currencyCode);
// Create administrator account
$this->adminAccountFactory->setConfig($this->config->getConfigData());
$adminAccount = $this->adminAccountFactory->create($setup);
$adminAccount->save();
$this->logger->logSuccess('Admin User');
if ($data['config']['encrypt']['type'] == 'magento') {
$key = md5($this->random->getRandomString(10));
} else {
$key = $data['config']['encrypt']['key'];
}
$this->config->replaceTmpEncryptKey($key);
$this->config->replaceTmpInstallDate(date('r'));
$phpPath = $this->phpExecutablePath();
exec($phpPath . 'php -f ' . escapeshellarg($this->systemConfig->create()->getMagentoBasePath() . '/dev/shell/run_data_fixtures.php'), $output, $exitCode);
if ($exitCode !== 0) {
$outputMsg = implode(PHP_EOL, $output);
$this->logger->logError(new \Exception('Data Update Failed with Exit Code: ' . $exitCode . PHP_EOL . $outputMsg));
$this->json->setVariable('success', false);
} else {
$this->logger->logSuccess('Data Updates');
$this->json->setVariable('success', true);
}
$this->json->setVariable('key', $key);
return $this->json;
}
示例6: beforeSave
/**
* Processing object before save data
*
* @return $this
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
* @SuppressWarnings(PHPMD.NPathComplexity)
*/
public function beforeSave()
{
$pageGroupIds = [];
$tmpPageGroups = [];
$pageGroups = $this->getData('page_groups');
if ($pageGroups) {
foreach ($pageGroups as $pageGroup) {
if (isset($pageGroup[$pageGroup['page_group']])) {
$pageGroupData = $pageGroup[$pageGroup['page_group']];
if ($pageGroupData['page_id']) {
$pageGroupIds[] = $pageGroupData['page_id'];
}
if (in_array($pageGroup['page_group'], ['pages', 'page_layouts'])) {
$layoutHandle = $pageGroupData['layout_handle'];
} else {
$layoutHandle = $this->_layoutHandles[$pageGroup['page_group']];
}
if (!isset($pageGroupData['template'])) {
$pageGroupData['template'] = '';
}
$tmpPageGroup = ['page_id' => $pageGroupData['page_id'], 'group' => $pageGroup['page_group'], 'layout_handle' => $layoutHandle, 'for' => $pageGroupData['for'], 'block_reference' => $pageGroupData['block'], 'entities' => '', 'layout_handle_updates' => [$layoutHandle], 'template' => $pageGroupData['template'] ? $pageGroupData['template'] : ''];
if ($pageGroupData['for'] == self::SPECIFIC_ENTITIES) {
$layoutHandleUpdates = [];
foreach (explode(',', $pageGroupData['entities']) as $entity) {
$layoutHandleUpdates[] = str_replace('{{ID}}', $entity, $this->_specificEntitiesLayoutHandles[$pageGroup['page_group']]);
}
$tmpPageGroup['entities'] = $pageGroupData['entities'];
$tmpPageGroup['layout_handle_updates'] = $layoutHandleUpdates;
}
$tmpPageGroups[] = $tmpPageGroup;
}
}
}
if (is_array($this->getData('store_ids'))) {
$this->setData('store_ids', implode(',', $this->getData('store_ids')));
}
$parameters = $this->getData('widget_parameters');
if (is_array($parameters)) {
if (array_key_exists('show_pager', $parameters) && !array_key_exists('page_var_name', $parameters)) {
$parameters['page_var_name'] = 'p' . $this->mathRandom->getRandomString(5, \Magento\Framework\Math\Random::CHARS_LOWERS);
}
$this->setData('widget_parameters', serialize($parameters));
}
$this->setData('page_groups', $tmpPageGroups);
$this->setData('page_group_ids', $pageGroupIds);
return parent::beforeSave();
}
示例7: beforeSave
/**
* Serialize info for Resource Model to save
* For new model check and set available cookie key
*
* @return $this
*/
public function beforeSave()
{
parent::beforeSave();
// Setting info
$info = [];
foreach ($this->getData() as $index => $value) {
if (!in_array($index, $this->_unserializableFields)) {
$info[$index] = $value;
}
}
$this->setInfo($this->jsonHelper->jsonEncode($info));
if ($this->isObjectNew()) {
$this->setWebsiteId($this->_storeManager->getStore()->getWebsiteId());
// Setting cookie key
do {
$this->setKey($this->mathRandom->getRandomString(self::KEY_LENGTH));
} while (!$this->getResource()->isKeyAllowed($this->getKey()));
}
return $this;
}
示例8: createCustomer
/**
* {@inheritdoc}
*/
public function createCustomer(Data\CustomerDetails $customerDetails, $password = null, $redirectUrl = '')
{
//Generate password hash
$password = $password ? $password : $this->mathRandom->getRandomString(self::DEFAULT_PASSWORD_LENGTH);
$hash = $this->getPasswordHash($password);
return $this->createCustomerWithPasswordHash($customerDetails, $hash, $redirectUrl);
}
示例9: generate
/**
* Generate new login credentials
* @param int $adminId
* @return $this
*/
public function generate($adminId)
{
return $this->setData(['customer_id' => $this->getCustomerId(), 'admin_id' => $adminId, 'secret' => $this->_random->getRandomString(64), 'used' => 0, 'created_at' => $this->_dateTime->gmtTimestamp()])->save();
}
示例10: _generateSecureSilentPostHash
/**
* Generate end return new secure hash value
*
* @param \Magento\Sales\Model\Order\Payment $payment
* @return string
*/
protected function _generateSecureSilentPostHash($payment)
{
$secureHash = md5($this->mathRandom->getRandomString(10));
$payment->setAdditionalInformation($this->_secureSilentPostHashKey, $secureHash);
return $secureHash;
}
示例11: createAccount
/**
* {@inheritdoc}
*/
public function createAccount(CustomerInterface $customer, $password = null, $redirectUrl = '')
{
if (!is_null($password)) {
$this->checkPasswordStrength($password);
} else {
$password = $this->mathRandom->getRandomString(self::MIN_PASSWORD_LENGTH);
}
$hash = $this->createPasswordHash($password);
return $this->createAccountWithPasswordHash($customer, $hash, $redirectUrl);
}
示例12: getRandomString
/**
* Get random string
*
* @param int $length
* @param string|null $chars
* @return string
*/
public function getRandomString($length, $chars = null)
{
return $this->mathRandom->getRandomString($length, $chars);
}
示例13: getValidEncryptionKey
/**
* Return a validated encryption key, generating a random one, if no value was initially provided
*
* @param string|null $key
* @return string
*/
public function getValidEncryptionKey($key = null)
{
if (!$key) {
$key = md5($this->mathRandom->getRandomString(10));
}
$this->_encryptor->validateKey($key);
return $key;
}
示例14: generatePassword
/**
* Generate password string
*
* @return string
*/
protected function generatePassword()
{
$salt = $this->random->getRandomString(32);
return md5($salt . $this->config['admin_password']) . ':' . $salt;
}
示例15: generateRandomString
/**
* Generate random string for token or secret or verifier
*
* @param int $length String length
* @return string
*/
public function generateRandomString($length)
{
return $this->_mathRandom->getRandomString($length, \Magento\Framework\Math\Random::CHARS_DIGITS . \Magento\Framework\Math\Random::CHARS_LOWERS);
}