本文整理汇总了PHP中Magento\Framework\Math\Random类的典型用法代码示例。如果您正苦于以下问题:PHP Random类的具体用法?PHP Random怎么用?PHP Random使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Random类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: postRequest
/**
* Post request into gateway
*
* @param DataObject $request
* @param ConfigInterface $config
*
* @return DataObject
* @throws \Zend_Http_Client_Exception
*/
public function postRequest(DataObject $request, ConfigInterface $config)
{
$result = new DataObject();
$clientConfig = ['maxredirects' => 5, 'timeout' => 30, 'verifypeer' => $config->getValue('verify_peer')];
if ($config->getValue('use_proxy')) {
$clientConfig['proxy'] = $config->getValue('proxy_host') . ':' . $config->getValue('proxy_port');
$clientConfig['httpproxytunnel'] = true;
$clientConfig['proxytype'] = CURLPROXY_HTTP;
}
/** @var ZendClient $client */
$client = $this->httpClientFactory->create();
$client->setUri((bool) $config->getValue('sandbox_flag') ? $config->getValue('transaction_url_test_mode') : $config->getValue('transaction_url'));
$client->setConfig($clientConfig);
$client->setMethod(\Zend_Http_Client::POST);
$client->setParameterPost($request->getData());
$client->setHeaders(['X-VPS-VIT-CLIENT-CERTIFICATION-ID' => '33baf5893fc2123d8b191d2d011b7fdc', 'X-VPS-Request-ID' => $this->mathRandom->getUniqueHash(), 'X-VPS-CLIENT-TIMEOUT' => 45]);
$client->setUrlEncodeBody(false);
try {
$response = $client->request();
$responseArray = [];
parse_str(strstr($response->getBody(), 'RESULT'), $responseArray);
$result->setData(array_change_key_case($responseArray, CASE_LOWER));
$result->setData('result_code', $result->getData('result'));
} catch (\Zend_Http_Client_Exception $e) {
$result->addData(['response_code' => -1, 'response_reason_code' => $e->getCode(), 'response_reason_text' => $e->getMessage()]);
throw $e;
} finally {
$this->logger->debug(['request' => $request->getData(), 'result' => $result->getData()], (array) $config->getValue('getDebugReplacePrivateDataKeys'), (bool) $config->getValue('debug'));
}
return $result;
}
示例2: testPrepareElementHtml
/**
* @covers \Magento\Cms\Block\Adminhtml\Block\Widget\Chooser::prepareElementHtml
* @param string $elementValue
* @param integer|null $modelBlockId
*
* @dataProvider prepareElementHtmlDataProvider
*/
public function testPrepareElementHtml($elementValue, $modelBlockId)
{
$elementId = 1;
$uniqId = '126hj4h3j73hk7b347jhkl37gb34';
$sourceUrl = 'cms/block_widget/chooser/126hj4h3j73hk7b347jhkl37gb34';
$config = ['key1' => 'value1'];
$fieldsetId = 2;
$html = 'some html';
$title = 'some title';
$this->this->setConfig($config);
$this->this->setFieldsetId($fieldsetId);
$this->elementMock->expects($this->atLeastOnce())->method('getId')->willReturn($elementId);
$this->mathRandomMock->expects($this->atLeastOnce())->method('getUniqueHash')->with($elementId)->willReturn($uniqId);
$this->urlBuilderMock->expects($this->atLeastOnce())->method('getUrl')->with('cms/block_widget/chooser', ['uniq_id' => $uniqId])->willReturn($sourceUrl);
$this->layoutMock->expects($this->atLeastOnce())->method('createBlock')->with('Magento\\Widget\\Block\\Adminhtml\\Widget\\Chooser')->willReturn($this->chooserMock);
$this->chooserMock->expects($this->atLeastOnce())->method('setElement')->with($this->elementMock)->willReturnSelf();
$this->chooserMock->expects($this->atLeastOnce())->method('setConfig')->with($config)->willReturnSelf();
$this->chooserMock->expects($this->atLeastOnce())->method('setFieldsetId')->with($fieldsetId)->willReturnSelf();
$this->chooserMock->expects($this->atLeastOnce())->method('setSourceUrl')->with($sourceUrl)->willReturnSelf();
$this->chooserMock->expects($this->atLeastOnce())->method('setUniqId')->with($uniqId)->willReturnSelf();
$this->elementMock->expects($this->atLeastOnce())->method('getValue')->willReturn($elementValue);
$this->blockFactoryMock->expects($this->any())->method('create')->willReturn($this->modelBlockMock);
$this->modelBlockMock->expects($this->any())->method('load')->with($elementValue)->willReturnSelf();
$this->modelBlockMock->expects($this->any())->method('getId')->willReturn($modelBlockId);
$this->modelBlockMock->expects($this->any())->method('getTitle')->willReturn($title);
$this->chooserMock->expects($this->any())->method('setLabel')->with($title)->willReturnSelf();
$this->chooserMock->expects($this->atLeastOnce())->method('toHtml')->willReturn($html);
$this->elementMock->expects($this->atLeastOnce())->method('setData')->with('after_element_html', $html)->willReturnSelf();
$this->assertEquals($this->elementMock, $this->this->prepareElementHtml($this->elementMock));
}
示例3: testGetFormKeyExists
public function testGetFormKeyExists()
{
$this->sessionMock->expects($this->exactly(2))->method('getData')->with(FormKey::FORM_KEY)->will($this->returnValue('random_string'));
$this->mathRandomMock->expects($this->never())->method('getRandomString');
$this->sessionMock->expects($this->never())->method('setData');
$this->assertEquals('random_string', $this->formKey->getFormKey());
}
示例4: 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));
}
示例5: encodeArrayFieldValue
/**
* Encode value to be used in \Magento\Config\Block\System\Config\Form\Field\FieldArray\AbstractFieldArray
*
* @param array $value
* @return array
*/
protected function encodeArrayFieldValue(array $value)
{
$result = [];
foreach ($value as $country => $creditCardType) {
$resultId = $this->mathRandom->getUniqueHash('_');
$result[$resultId] = ['country_id' => $country, 'cc_types' => $creditCardType];
}
return $result;
}
示例6: testAfterLoad
/**
* @dataProvider afterLoadDataProvider
*/
public function testAfterLoad($value, $hashData, $expected)
{
$this->model->setValue($value);
$index = 0;
foreach ($hashData as $hash) {
$this->mathRandomMock->expects($this->at($index))->method('getUniqueHash')->willReturn($hash);
$index++;
}
$this->model->afterLoad();
$this->assertEquals($expected, $this->model->getValue());
}
示例7: testGetWidgetOptions
public function testGetWidgetOptions()
{
$rand = rand();
$this->mathRandom->expects($this->any())->method('getUniqueHash')->with('id_')->willReturn('id_' . $rand);
$saveVideoUrl = 'http://host/index.php/admin/catalog/product_gallery/upload/key/';
$saveRemoteVideoUrl = 'http://host/index.php/admin/product_video/product_gallery/retrieveImage/';
$this->urlBuilder->expects($this->exactly(2))->method('getUrl')->willReturnOnConsecutiveCalls($saveVideoUrl, $saveRemoteVideoUrl);
$value = ['saveVideoUrl' => $saveVideoUrl, 'saveRemoteVideoUrl' => $saveRemoteVideoUrl, 'htmlId' => 'id_' . $rand];
$this->jsonEncoderMock->expects($this->once())->method('encode')->with($value)->willReturn(json_encode($value));
$this->block->getWidgetOptions();
}
示例8: setUp
public function setUp()
{
$this->setUpMock = $this->getMock('Magento\\Setup\\Module\\Setup', [], [], '', false);
$this->dbAdapterMock = $this->getMock('Magento\\Framework\\DB\\Adapter\\Pdo\\Mysql', [], [], '', false);
$this->setUpMock->expects($this->any())->method('getConnection')->will($this->returnValue($this->dbAdapterMock));
$this->setUpMock->expects($this->any())->method('getTable')->will($this->returnCallback(function ($table) {
return $table;
}));
$this->randomMock = $this->getMock('Magento\\Framework\\Math\\Random');
$this->randomMock->expects($this->any())->method('getRandomString')->will($this->returnValue('salt'));
$data = [AdminAccount::KEY_FIRST_NAME => 'John', AdminAccount::KEY_LAST_NAME => 'Doe', AdminAccount::KEY_EMAIL => 'john.doe@test.com', AdminAccount::KEY_PASSWORD => '123123q', AdminAccount::KEY_USERNAME => 'admin'];
$this->adminAccount = new AdminAccount($this->setUpMock, $this->randomMock, $data);
}
示例9: testRequestToken
public function testRequestToken()
{
$request = new Object();
$secureTokenID = 'Sdj46hDokds09c8k2klaGJdKLl032ekR';
$this->transparent->expects($this->once())->method('buildBasicRequest')->willReturn($request);
$this->transparent->expects($this->once())->method('fillCustomerContacts');
$this->transparent->expects($this->once())->method('getConfig')->willReturn($this->getMock('Magento\\Paypal\\Model\\PayflowConfig', [], [], '', false));
$this->transparent->expects($this->once())->method('postRequest')->willReturn(new Object());
$this->mathRandom->expects($this->once())->method('getUniqueHash')->willReturn($secureTokenID);
$this->url->expects($this->exactly(3))->method('getUrl');
$quote = $this->getMock('Magento\\Quote\\Model\\Quote', [], [], '', false);
$this->model->requestToken($quote);
$this->assertEquals($secureTokenID, $request->getSecuretokenid());
}
示例10: _toHtml
/**
* Render the chooser HTML
* Target element should be set.
*
* @return string
*/
protected function _toHtml()
{
if (empty($this->_targetElementId)) {
return '';
}
$idSuffix = $this->mathRandom->getUniqueHash();
/** @var \Magento\Framework\Data\Form $form */
$form = $this->_formFactory->create();
$dateFields = array('from' => __('From'), 'to' => __('To'));
foreach ($dateFields as $key => $label) {
$form->addField("{$key}_{$idSuffix}", 'date', array('format' => \Magento\Framework\Stdlib\DateTime::DATE_INTERNAL_FORMAT, 'label' => $label, 'image' => $this->getViewFileUrl('images/grid-cal.gif'), 'onchange' => "dateTimeChoose_{$idSuffix}()", 'value' => $this->_rangeValues[$key]));
}
return $form->toHtml() . "<script type=\"text/javascript\">\n dateTimeChoose_{$idSuffix} = function() {\n \$('{$this->_targetElementId}').value = " . "\$('from_{$idSuffix}').value + '{$this->_rangeDelimiter}' + \$('to_{$idSuffix}').value;\n };\n </script>";
}
示例11: encodeArrayFieldValue
/**
* Encode value to be used in \Magento\Config\Block\System\Config\Form\Field\FieldArray\AbstractFieldArray
*
* @param array $value
* @return array
*/
protected function encodeArrayFieldValue(array $value)
{
$result = [];
// first combine the ccTypes together
$list = [];
foreach ($value as $ccType => $items) {
// sort on amount
ksort($items);
foreach ($items as $amount => $installment) {
if (!isset($list[$installment][$amount])) {
$list[$installment][$amount] = [$ccType];
} else {
$ccTypes = $list[$installment][$amount];
$ccTypes[] = $ccType;
$list[$installment][$amount] = $ccTypes;
}
}
}
// loop through combined ccTypes configuration and pre fill the items
foreach ($list as $installment => $amounts) {
foreach ($amounts as $amount => $ccTypes) {
$resultId = $this->mathRandom->getUniqueHash('_');
$result[$resultId] = ['amount' => $amount, 'cc_types' => $ccTypes, 'installments' => $installment];
}
}
return $result;
}
示例12: _beforeToHtml
/**
* @return \Magento\Framework\View\Element\AbstractBlock
*/
protected function _beforeToHtml()
{
$result = parent::_beforeToHtml();
/** @var \Magento\Paypal\Model\Config $config */
$config = $this->_paypalConfigFactory->create();
$config->setMethod($this->_paymentMethodCode);
$isInCatalog = $this->getIsInCatalogProduct();
if (!$this->_shortcutValidator->validate($this->_paymentMethodCode, $isInCatalog)) {
$this->_shouldRender = false;
return $result;
}
$quote = $isInCatalog || !$this->_checkoutSession ? null : $this->_checkoutSession->getQuote();
// set misc data
$this->setShortcutHtmlId($this->_mathRandom->getUniqueHash('ec_shortcut_'))->setCheckoutUrl($this->getUrl($this->_startAction));
// use static image if in catalog
if ($isInCatalog || null === $quote) {
$this->setImageUrl($config->getExpressCheckoutShortcutImageUrl($this->_localeResolver->getLocale()));
} else {
/**@todo refactor checkout model. Move getCheckoutShortcutImageUrl to helper or separate model */
$parameters = ['params' => ['quote' => $quote, 'config' => $config]];
$checkoutModel = $this->_checkoutFactory->create($this->_checkoutType, $parameters);
$this->setImageUrl($checkoutModel->getCheckoutShortcutImageUrl());
}
// ask whether to create a billing agreement
$customerId = $this->currentCustomer->getCustomerId();
// potential issue for caching
if ($this->_paypalData->shouldAskToCreateBillingAgreement($config, $customerId)) {
$this->setConfirmationUrl($this->getUrl($this->_startAction, [\Magento\Paypal\Model\Express\Checkout::PAYMENT_INFO_TRANSPORT_BILLING_AGREEMENT => 1]));
$this->setConfirmationMessage(__('Would you like to sign a billing agreement to streamline further purchases with PayPal?'));
}
return $result;
}
示例13: generateLayoutUpdateXml
/**
* Generate layout update xml
*
* @param string $container
* @param string $templatePath
* @return string
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
* @SuppressWarnings(PHPMD.NPathComplexity)
*/
public function generateLayoutUpdateXml($container, $templatePath = '')
{
$templateFilename = $this->_viewFileSystem->getTemplateFileName($templatePath, ['area' => $this->getArea(), 'themeId' => $this->getThemeId(), 'module' => \Magento\Framework\View\Element\AbstractBlock::extractModuleName($this->getType())]);
if (!$this->getId() && !$this->isCompleteToCreate() || $templatePath && !is_readable($templateFilename)) {
return '';
}
$parameters = $this->getWidgetParameters();
$xml = '<body><referenceContainer name="' . $container . '">';
$template = '';
if (isset($parameters['template'])) {
unset($parameters['template']);
}
if ($templatePath) {
$template = ' template="' . $templatePath . '"';
}
$hash = $this->mathRandom->getUniqueHash();
$xml .= '<block class="' . $this->getType() . '" name="' . $hash . '"' . $template . '>';
foreach ($parameters as $name => $value) {
if ($name == 'conditions') {
$name = 'conditions_encoded';
$value = $this->conditionsHelper->encode($value);
} elseif (is_array($value)) {
$value = implode(',', $value);
}
if ($name && strlen((string) $value)) {
$xml .= '<action method="setData">' . '<argument name="name" xsi:type="string">' . $name . '</argument>' . '<argument name="value" xsi:type="string">' . $this->_escaper->escapeHtml($value) . '</argument>' . '</action>';
}
}
$xml .= '</block></referenceContainer></body>';
return $xml;
}
示例14: 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;
}
}
示例15: requestToken
/**
* Get the Secure Token from Paypal for TR
*
* @param Quote $quote
*
* @return DataObject
* @throws \Exception
*/
public function requestToken(Quote $quote)
{
$request = $this->transparent->buildBasicRequest();
$request->setTrxtype(Payflowpro::TRXTYPE_AUTH_ONLY);
$request->setVerbosity('HIGH');
$request->setAmt(0);
$request->setCreatesecuretoken('Y');
$request->setSecuretokenid($this->mathRandom->getUniqueHash());
$request->setReturnurl($this->url->getUrl('paypal/transparent/response'));
$request->setErrorurl($this->url->getUrl('paypal/transparent/response'));
$request->setCancelurl($this->url->getUrl('paypal/transparent/cancel'));
$request->setDisablereceipt('TRUE');
$request->setSilenttran('TRUE');
$this->transparent->fillCustomerContacts($quote, $request);
$result = $this->transparent->postRequest($request, $this->transparent->getConfig());
return $result;
}