ltsecurityinc安防产品在线商城代码
This commit is contained in:
+132
@@ -0,0 +1,132 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Plumrocket_Base
|
||||
* @copyright Copyright (c) 2020 Plumrocket Inc. (https://plumrocket.com)
|
||||
* @license https://plumrocket.com/license/ End-user License Agreement
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Plumrocket\Base\Helper;
|
||||
|
||||
use Magento\Framework\App\Helper\Context;
|
||||
use Magento\Framework\App\ObjectManager;
|
||||
use Plumrocket\Base\Api\GetExtensionInformationInterface;
|
||||
|
||||
/**
|
||||
* Base class for extension's Helper/Config
|
||||
*
|
||||
* @since 2.3.0
|
||||
* @deprecated since 2.6.0
|
||||
* @see \Plumrocket\Base\Model\ConfigUtils
|
||||
*/
|
||||
abstract class AbstractConfig extends ConfigUtils
|
||||
{
|
||||
/**
|
||||
* @deprecated since 2.5.0 - it is better to use "XML_PATH_" constants, see our docs
|
||||
*/
|
||||
const SECTION_ID = '';
|
||||
/**
|
||||
* @deprecated since 2.5.0 - it is better to use "XML_PATH_" constants, see our docs
|
||||
*/
|
||||
const GROUP_GENERAL = 'general';
|
||||
|
||||
/**
|
||||
* @var \Plumrocket\Base\Api\GetExtensionInformationInterface
|
||||
*/
|
||||
protected $getExtensionInformation;
|
||||
|
||||
/**
|
||||
* @param \Magento\Framework\App\Helper\Context $context
|
||||
* @param \Plumrocket\Base\Api\GetExtensionInformationInterface|null $getExtensionInformation
|
||||
*/
|
||||
public function __construct(
|
||||
Context $context,
|
||||
?GetExtensionInformationInterface $getExtensionInformation = null
|
||||
) {
|
||||
parent::__construct($context);
|
||||
$this->getExtensionInformation = $getExtensionInformation ?: ObjectManager::getInstance()->get(
|
||||
GetExtensionInformationInterface::class
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* All modules must return his status.
|
||||
*
|
||||
* There are four ways to do this:
|
||||
* 1. Rewrite method and write own logic (recommended)
|
||||
* 3. Rewrite method and return true (recommended for free modules)
|
||||
* 4. Use \Plumrocket\Base\Helper\AbstractConfig::isModuleEnabledInConfig method (not recommended)
|
||||
*
|
||||
* @param null $store
|
||||
* @param null $scope
|
||||
* @return bool
|
||||
*/
|
||||
public function isModuleEnabled($store = null, $scope = null): bool
|
||||
{
|
||||
$configPath = $this->getExtensionInformation->execute($this->_getModuleName())->getIsEnabledFieldConfigPath();
|
||||
if (! $configPath) {
|
||||
throw new \LogicException('You must specify enabled field config path via DI or rewrite method');
|
||||
}
|
||||
|
||||
return (bool) $this->getConfig($configPath, $store, $scope);
|
||||
}
|
||||
|
||||
/**
|
||||
* Can be used for certain modules with config path like "SECTION_ID/general/enabled"
|
||||
* @deprecated since 2.3.7 - it is better to have path to enabled field in one place and it here
|
||||
* @see \Plumrocket\Base\Model\Extensions\Information::IS_ENABLED_FIELD_CONFIG_PATH
|
||||
*
|
||||
* @param null $store
|
||||
* @param null $scope
|
||||
* @return bool
|
||||
*/
|
||||
protected function isModuleEnabledInConfig($store = null, $scope = null): bool
|
||||
{
|
||||
return (bool) $this->getConfig(
|
||||
implode('/', [static::SECTION_ID, static::GROUP_GENERAL, 'enabled']),
|
||||
$store,
|
||||
$scope
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Receive magento config value
|
||||
* @deprecated since 2.3.7 - it is better to use constants, see our docs
|
||||
*
|
||||
* @param string $group second part of the path, e.g. "general"
|
||||
* @param string $path third part of the path, e.g. "enabled"
|
||||
* @param string|int|null $scopeCode
|
||||
* @param string|null $scope
|
||||
* @return mixed
|
||||
*/
|
||||
public function getConfigByGroup($group, $path, $scopeCode = null, $scope = null)
|
||||
{
|
||||
return $this->getConfig(
|
||||
implode('/', [static::SECTION_ID, $group, $path]),
|
||||
$scopeCode,
|
||||
$scope
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Receive magento config value
|
||||
* Used for deep paths, like "pr_base/statistic/usage/enabled"
|
||||
* @deprecated since 2.3.7 - it is better to use constants, see our docs
|
||||
*
|
||||
* @param string $group second part of the path
|
||||
* @param string $subGroup third part of the path
|
||||
* @param string $path fourth part of the path
|
||||
* @param string|int|null $scopeCode
|
||||
* @param string|null $scope
|
||||
* @return mixed
|
||||
*/
|
||||
public function getConfigBySubGroup($group, $subGroup, $path, $scopeCode = null, $scope = null)
|
||||
{
|
||||
return $this->getConfig(
|
||||
implode('/', [static::SECTION_ID, $group, $subGroup, $path]),
|
||||
$scopeCode,
|
||||
$scope
|
||||
);
|
||||
}
|
||||
}
|
||||
Executable
+79
@@ -0,0 +1,79 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Plumrocket_Base
|
||||
* @copyright Copyright (c) 2020 Plumrocket Inc. (https://plumrocket.com)
|
||||
* @license https://plumrocket.com/license/ End-user License Agreement
|
||||
*/
|
||||
|
||||
namespace Plumrocket\Base\Helper;
|
||||
|
||||
use Magento\Framework\App\Helper\AbstractHelper;
|
||||
use Magento\Framework\App\Helper\Context as HelperContext;
|
||||
use Magento\Framework\Exception\NoSuchEntityException;
|
||||
use Magento\Framework\ObjectManagerInterface;
|
||||
use Magento\Store\Model\ScopeInterface;
|
||||
use Plumrocket\Base\Api\ExtensionStatusInterface;
|
||||
|
||||
/**
|
||||
* @since 1.0.0
|
||||
* @deprecated since 2.5.0 - we move logic from this class to others
|
||||
*/
|
||||
class Base extends AbstractHelper
|
||||
{
|
||||
|
||||
/**
|
||||
* @var \Magento\Framework\ObjectManagerInterface
|
||||
*/
|
||||
protected $_objectManager;
|
||||
|
||||
/**
|
||||
* Initialize helper
|
||||
*
|
||||
* @param \Magento\Framework\ObjectManagerInterface $objectManager
|
||||
* @param HelperContext $context
|
||||
*/
|
||||
public function __construct(
|
||||
ObjectManagerInterface $objectManager,
|
||||
HelperContext $context
|
||||
) {
|
||||
$this->_objectManager = $objectManager;
|
||||
parent::__construct($context);
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated since 2.9.0
|
||||
* @see \Plumrocket\Base\Model\Extension\Customer\GetTrueCustomerKey::execute
|
||||
* @param string $customerKey
|
||||
* @return string
|
||||
*/
|
||||
protected function getTrueCustomerKey($customerKey)
|
||||
{
|
||||
$trueKey = '';
|
||||
|
||||
if ($customerKey === '532416486b540ea2a1e50c4070b671611b44f52718') {
|
||||
$data = explode('_', $this->_getModuleName());
|
||||
$modName = $data[1] ?? '';
|
||||
$trueKey = $this->scopeConfig->getValue($modName . '/module/data', ScopeInterface::SCOPE_STORE);
|
||||
}
|
||||
|
||||
return $trueKey ?: $customerKey;
|
||||
}
|
||||
|
||||
/**
|
||||
* Receive magento config value
|
||||
* @deprecated since 2.3.0
|
||||
* @see \Plumrocket\Base\Helper\AbstractConfig::getConfig
|
||||
*
|
||||
* @param string $path
|
||||
* @param string|int $store
|
||||
* @param string|null $scope
|
||||
* @return mixed
|
||||
*/
|
||||
public function getConfig($path, $store = null, $scope = null)
|
||||
{
|
||||
if ($scope === null) {
|
||||
$scope = ScopeInterface::SCOPE_STORE;
|
||||
}
|
||||
return $this->scopeConfig->getValue($path, $scope, $store);
|
||||
}
|
||||
}
|
||||
Executable
+82
@@ -0,0 +1,82 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Plumrocket_Base
|
||||
* @copyright Copyright (c) 2020 Plumrocket Inc. (https://plumrocket.com)
|
||||
* @license https://plumrocket.com/license/ End-user License Agreement
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Plumrocket\Base\Helper;
|
||||
|
||||
use Magento\Framework\App\Helper\AbstractHelper;
|
||||
use Magento\Framework\App\Helper\Context;
|
||||
|
||||
/**
|
||||
* @since 2.3.0
|
||||
*/
|
||||
class Config extends AbstractHelper
|
||||
{
|
||||
public const XML_PATH_NOTIFICATIONS_ENABLED = 'plumbase/notifications/enabled';
|
||||
public const XML_PATH_NOTIFICATION_LISTS = 'plumbase/notifications/subscribed_to';
|
||||
public const XML_PATH_IS_ENABLED_STATISTIC = 'plumbase/system/subscribed_to';
|
||||
|
||||
/**
|
||||
* @var \Plumrocket\Base\Model\ConfigUtils
|
||||
*/
|
||||
private $configUtils;
|
||||
|
||||
/**
|
||||
* @param \Magento\Framework\App\Helper\Context $context
|
||||
* @param \Plumrocket\Base\Model\ConfigUtils $configUtils
|
||||
*/
|
||||
public function __construct(
|
||||
Context $context,
|
||||
\Plumrocket\Base\Model\ConfigUtils $configUtils
|
||||
) {
|
||||
parent::__construct($context);
|
||||
$this->configUtils = $configUtils;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if notifications are enabled.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isEnabledNotifications(): bool
|
||||
{
|
||||
return (bool) $this->configUtils->getConfig(self::XML_PATH_NOTIFICATIONS_ENABLED);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get enabled notification lists.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getEnabledNotificationLists(): array
|
||||
{
|
||||
return $this->configUtils->prepareMultiselectValue(
|
||||
(string) $this->configUtils->getConfig(self::XML_PATH_NOTIFICATION_LISTS)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if statistic is enabled.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isEnabledStatistic(): bool
|
||||
{
|
||||
return (bool) $this->configUtils->getConfig(self::XML_PATH_IS_ENABLED_STATISTIC);
|
||||
}
|
||||
|
||||
/**
|
||||
* Useful for debugging extension authorization.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isDebugMode(): bool
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
+78
@@ -0,0 +1,78 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Plumrocket_Base
|
||||
* @copyright Copyright (c) 2020 Plumrocket Inc. (https://plumrocket.com)
|
||||
* @license https://plumrocket.com/license/ End-user License Agreement
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Plumrocket\Base\Helper;
|
||||
|
||||
use Magento\Framework\App\Helper\AbstractHelper;
|
||||
use Magento\Store\Model\ScopeInterface;
|
||||
|
||||
/**
|
||||
* Provides methods for work with config value
|
||||
*
|
||||
* Generally we create const like this:
|
||||
* public const XML_PATH_IS_ENABLED = 'pr_base/general/enabled';
|
||||
*
|
||||
* We also have a lightweight model as alternative to this helper.
|
||||
* @see \Plumrocket\Base\Model\ConfigUtils
|
||||
*
|
||||
* @since 2.3.1
|
||||
*/
|
||||
class ConfigUtils extends AbstractHelper
|
||||
{
|
||||
|
||||
/**
|
||||
* Receive magento config value
|
||||
*
|
||||
* @param string $path full path, eg: "pr_base/general/enabled"
|
||||
* @param string|int $scopeCode store view code or website code
|
||||
* @param string|null $scopeType
|
||||
* @return mixed
|
||||
*/
|
||||
public function getConfig($path, $scopeCode = null, $scopeType = null)
|
||||
{
|
||||
if ($scopeType === null) {
|
||||
$scopeType = ScopeInterface::SCOPE_STORE;
|
||||
}
|
||||
return $this->scopeConfig->getValue($path, $scopeType, $scopeCode);
|
||||
}
|
||||
|
||||
/**
|
||||
* Split textarea.
|
||||
*
|
||||
* @param string $fieldValue
|
||||
* @return array
|
||||
* @deprecated since 2.6.0 - was moved
|
||||
* @see \Plumrocket\Base\Model\ConfigUtils::splitTextareaValueByLine()
|
||||
*/
|
||||
protected function splitTextareaValueByLine($fieldValue): array
|
||||
{
|
||||
$lines = explode(PHP_EOL, $fieldValue);
|
||||
|
||||
if (empty($lines)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return array_filter(array_map('trim', $lines));
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse multiselect value.
|
||||
*
|
||||
* @param string $value
|
||||
* @param bool $clearEmpty
|
||||
* @return array
|
||||
* @deprecated since 2.6.0 - was moved
|
||||
* @see \Plumrocket\Base\Model\ConfigUtils::prepareMultiselectValue()
|
||||
*/
|
||||
protected function prepareMultiselectValue(string $value, bool $clearEmpty = true): array
|
||||
{
|
||||
$values = explode(',', $value);
|
||||
return $clearEmpty ? array_filter($values) : $values;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user