本文整理汇总了PHP中Magento\Framework\Math\Random::getRandomNumber方法的典型用法代码示例。如果您正苦于以下问题:PHP Random::getRandomNumber方法的具体用法?PHP Random::getRandomNumber怎么用?PHP Random::getRandomNumber使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Magento\Framework\Math\Random
的用法示例。
在下文中一共展示了Random::getRandomNumber方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: _randomSize
/**
* Override function to generate less curly captcha that will not cut off
*
* @see \Zend_Captcha_Image::_randomSize()
* @return int
*/
protected function _randomSize()
{
return \Magento\Framework\Math\Random::getRandomNumber(280, 300) / 100;
}
示例2: isCleanupProbability
/**
* Calculate cleanup possibility for data with lifetime property
*
* @return bool
*/
public function isCleanupProbability()
{
// Safe get cleanup probability value from system configuration
$configValue = (int) $this->_scopeConfig->getValue(self::XML_PATH_CLEANUP_PROBABILITY, \Magento\Store\Model\ScopeInterface::SCOPE_STORE);
return $configValue > 0 ? 1 == \Magento\Framework\Math\Random::getRandomNumber(1, $configValue) : false;
}
示例3: createPdfPageFromImageString
/**
* Create \Zend_Pdf_Page instance with image from $imageString. Supports JPEG, PNG, GIF, WBMP, and GD2 formats.
*
* @param string $imageString
* @return \Zend_Pdf_Page|false
*/
public function createPdfPageFromImageString($imageString)
{
/** @var \Magento\Framework\Filesystem\Directory\Write $directory */
$directory = $this->filesystem->getDirectoryWrite(DirectoryList::TMP);
$directory->create();
$image = @imagecreatefromstring($imageString);
if (!$image) {
return false;
}
$xSize = imagesx($image);
$ySize = imagesy($image);
$page = new \Zend_Pdf_Page($xSize, $ySize);
imageinterlace($image, 0);
$tmpFileName = $directory->getAbsolutePath('shipping_labels_' . uniqid(\Magento\Framework\Math\Random::getRandomNumber()) . time() . '.png');
imagepng($image, $tmpFileName);
$pdfImage = \Zend_Pdf_Image::imageWithPath($tmpFileName);
$page->drawImage($pdfImage, 0, 0, $xSize, $ySize);
$directory->delete($directory->getRelativePath($tmpFileName));
return $page;
}
示例4: _beforeSave
/**
* Processing object before save data
*
* @return $this
*/
protected function _beforeSave()
{
parent::_beforeSave();
$this->_checkState();
if (!$this->getId()) {
$store = $this->getStore();
$name = array($store->getWebsite()->getName(), $store->getGroup()->getName(), $store->getName());
$this->setStoreName(implode("\n", $name));
}
if (!$this->getIncrementId()) {
$incrementId = $this->_eavConfig->getEntityType('order')->fetchNewIncrementId($this->getStoreId());
$this->setIncrementId($incrementId);
}
/**
* Process items dependency for new order
*/
if (!$this->getId()) {
$itemsCount = 0;
foreach ($this->getAllItems() as $item) {
$parent = $item->getQuoteParentItemId();
if ($parent && !$item->getParentItem()) {
$item->setParentItem($this->getItemByQuoteItemId($parent));
} elseif (!$parent) {
$itemsCount++;
}
}
// Set items count
$this->setTotalItemCount($itemsCount);
}
/** TODO refactor getCustomer usage after MAGETWO-20182 and MAGETWO-20258 are done */
$isNewCustomer = !$this->getCustomerId() || $this->getCustomerId() === true;
if ($isNewCustomer && $this->getCustomer()) {
$this->setCustomerId($this->getCustomer()->getId());
}
if ($this->hasBillingAddressId() && $this->getBillingAddressId() === null) {
$this->unsBillingAddressId();
}
if ($this->hasShippingAddressId() && $this->getShippingAddressId() === null) {
$this->unsShippingAddressId();
}
$this->setData('protect_code', substr(md5(uniqid(\Magento\Framework\Math\Random::getRandomNumber(), true) . ':' . microtime(true)), 5, 6));
return $this;
}
示例5: _beforeSave
/**
* @param \Magento\Framework\Model\AbstractModel $object
* @return $this
*/
protected function _beforeSave(\Magento\Framework\Model\AbstractModel $object)
{
if (!$object->getId()) {
/** @var \Magento\Store\Model\Store $store */
$store = $object->getStore();
$name = [$store->getWebsite()->getName(), $store->getGroup()->getName(), $store->getName()];
$object->setStoreName(implode(PHP_EOL, $name));
$object->setTotalItemCount($this->calculateItems($object));
}
$object->setData('protect_code', substr(md5(uniqid(Random::getRandomNumber(), true) . ':' . microtime(true)), 5, 6));
$isNewCustomer = !$object->getCustomerId() || $object->getCustomerId() === true;
if ($isNewCustomer && $object->getCustomer()) {
$object->setCustomerId($object->getCustomer()->getId());
}
return parent::_beforeSave($object);
}
示例6: generateCode
/**
* Generate coupon code
*
* @return string
*/
public function generateCode()
{
$format = $this->getFormat();
if (!$format) {
$format = \Magento\SalesRule\Helper\Coupon::COUPON_FORMAT_ALPHANUMERIC;
}
$length = max(1, (int) $this->getLength());
$split = max(0, (int) $this->getDash());
$suffix = $this->getSuffix();
$prefix = $this->getPrefix();
$splitChar = $this->getDelimiter();
$charset = $this->_salesRuleCoupon->getCharset($format);
$code = '';
$charsetSize = count($charset);
for ($i = 0; $i < $length; $i++) {
$char = $charset[\Magento\Framework\Math\Random::getRandomNumber(0, $charsetSize - 1)];
if ($split > 0 && $i % $split == 0 && $i != 0) {
$char = $splitChar . $char;
}
$code .= $char;
}
$code = $prefix . $code . $suffix;
return $code;
}
示例7: fetchAndSave
/**
* Goes to specified host/path and fetches reports from there.
* Save reports to database.
*
* @param \Magento\Framework\Filesystem\Io\Sftp $connection
* @return int Number of report rows that were fetched and saved successfully
* @throws \Magento\Framework\Exception\LocalizedException
*/
public function fetchAndSave(\Magento\Framework\Filesystem\Io\Sftp $connection)
{
$fetched = 0;
$listing = $this->_filterReportsList($connection->rawls());
foreach ($listing as $filename => $attributes) {
$localCsv = 'PayPal_STL_' . uniqid(\Magento\Framework\Math\Random::getRandomNumber()) . time() . '.csv';
if ($connection->read($filename, $this->_tmpDirectory->getAbsolutePath($localCsv))) {
if (!$this->_tmpDirectory->isWritable($localCsv)) {
throw new \Magento\Framework\Exception\LocalizedException(__('We cannot create a target file for reading reports.'));
}
$encoded = $this->_tmpDirectory->readFile($localCsv);
$csvFormat = 'new';
$fileEncoding = mb_detect_encoding($encoded);
if (self::FILES_OUT_CHARSET != $fileEncoding) {
$decoded = @iconv($fileEncoding, self::FILES_OUT_CHARSET . '//IGNORE', $encoded);
$this->_tmpDirectory->writeFile($localCsv, $decoded);
$csvFormat = 'old';
}
// Set last modified date, this value will be overwritten during parsing
if (isset($attributes['mtime'])) {
$lastModified = new \DateTime($attributes['mtime']);
$this->setReportLastModified($lastModified->format('Y-m-d H:i:s'));
}
$this->setReportDate($this->_fileNameToDate($filename))->setFilename($filename)->parseCsv($localCsv, $csvFormat);
if ($this->getAccountId()) {
$this->save();
}
if ($this->_dataSaveAllowed) {
$fetched += count($this->_rows);
}
// clean object and remove parsed file
$this->unsetData();
$this->_tmpDirectory->delete($localCsv);
}
}
return $fetched;
}
示例8: testGetRandomNumber
/**
* @param $min
* @param $max
*
* @dataProvider testGetRandomNumberProvider
*/
public function testGetRandomNumber($min, $max)
{
$number = \Magento\Framework\Math\Random::getRandomNumber($min, $max);
$this->assertLessThanOrEqual($max, $number);
$this->assertGreaterThanOrEqual($min, $number);
}
示例9: randomSequence
/**
* Returns string of random chars
*
* @param int $length
* @return string
*/
public function randomSequence($length = 32)
{
$id = '';
$par = [];
$char = array_merge(range('a', 'z'), range(0, 9));
$charLen = count($char) - 1;
for ($i = 0; $i < $length; $i++) {
$disc = \Magento\Framework\Math\Random::getRandomNumber(0, $charLen);
$par[$i] = $char[$disc];
$id = $id . $char[$disc];
}
return $id;
}
示例10: generateUniqueIdPath
/**
* Return unique string based on the time in microseconds.
*
* @return string
*/
public function generateUniqueIdPath()
{
return str_replace('.', '_', uniqid(\Magento\Framework\Math\Random::getRandomNumber(), true));
}