ltsecurityinc安防产品在线商城代码
This commit is contained in:
@@ -0,0 +1,202 @@
|
||||
<?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\Model\Extension\Information;
|
||||
|
||||
use Magento\Framework\DataObject;
|
||||
use Plumrocket\Base\Api\Data\ExtensionInformationInterface;
|
||||
use Plumrocket\Base\Api\GetModuleVersionInterface;
|
||||
|
||||
/**
|
||||
* Container for information about extension that parsed from "pr_extensions.xml"
|
||||
*
|
||||
* Can be used for old extension which has not xml file
|
||||
* and does not realize \Plumrocket\Base\Api\ModuleInformationInterface
|
||||
*
|
||||
* @since 2.5.0
|
||||
*/
|
||||
class Container extends DataObject implements ExtensionInformationInterface
|
||||
{
|
||||
/**
|
||||
* @var \Plumrocket\Base\Api\GetModuleVersionInterface
|
||||
*/
|
||||
private $getModuleVersion;
|
||||
|
||||
/**
|
||||
* @param \Plumrocket\Base\Api\GetModuleVersionInterface $getModuleVersion
|
||||
* @param array $data
|
||||
*/
|
||||
public function __construct(
|
||||
GetModuleVersionInterface $getModuleVersion,
|
||||
array $data = []
|
||||
) {
|
||||
parent::__construct($data);
|
||||
$this->getModuleVersion = $getModuleVersion;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function isService(): bool
|
||||
{
|
||||
return (bool) $this->_getData(self::FIELD_IS_SERVICE);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getTitle(): string
|
||||
{
|
||||
return (string) $this->_getData(self::FIELD_TITLE);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getDocumentationLink(): string
|
||||
{
|
||||
return (string) ($this->_getData(self::FIELD_DOCUMENTATION) ?: $this->_getData(self::FIELD_WIKI));
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getWikiLink(): string
|
||||
{
|
||||
return $this->getDocumentationLink();
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getUrl(): string
|
||||
{
|
||||
return (string) $this->_getData(self::FIELD_URL);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getMarketplaceUrl(): string
|
||||
{
|
||||
return (string) $this->_getData(self::FIELD_MARKETPLACE_URL);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getConfigSection(): string
|
||||
{
|
||||
return (string) $this->_getData(self::FIELD_CONFIG_SECTION);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getIsEnabledFieldConfigPath(): string
|
||||
{
|
||||
return (string) $this->_getData(self::FIELD_IS_ENABLED_PATH);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getModuleName(): string
|
||||
{
|
||||
return (string) $this->_getData(self::FIELD_MODULE_NAME);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getVendorAndModuleName(): string
|
||||
{
|
||||
return "Plumrocket_{$this->getModuleName()}";
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getInstalledVersion(): string
|
||||
{
|
||||
return $this->getModuleVersion->execute($this->getVendorAndModuleName());
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function setIsService(bool $isService): ExtensionInformationInterface
|
||||
{
|
||||
return $this->setData(self::FIELD_IS_SERVICE, $isService);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function setTitle(string $title): ExtensionInformationInterface
|
||||
{
|
||||
return $this->setData(self::FIELD_TITLE, $title);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function setConfigSection(string $configSection): ExtensionInformationInterface
|
||||
{
|
||||
return $this->setData(self::FIELD_CONFIG_SECTION, $configSection);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function setDocumentationLink(string $documentationLink): ExtensionInformationInterface
|
||||
{
|
||||
return $this->setData(self::FIELD_DOCUMENTATION, $documentationLink);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function setWikiLink(string $wikiLink): ExtensionInformationInterface
|
||||
{
|
||||
return $this->setDocumentationLink($wikiLink);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function setUrl(string $extensionUrl): ExtensionInformationInterface
|
||||
{
|
||||
return $this->setData(self::FIELD_URL, $extensionUrl);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function setMarketplaceUrl(string $extensionMarketplaceUrl): ExtensionInformationInterface
|
||||
{
|
||||
return $this->setData(self::FIELD_MARKETPLACE_URL, $extensionMarketplaceUrl);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function setModuleName(string $moduleName): ExtensionInformationInterface
|
||||
{
|
||||
return $this->setData(self::FIELD_MODULE_NAME, $moduleName);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function setIsEnabledFieldConfigPath(string $configPath): ExtensionInformationInterface
|
||||
{
|
||||
return $this->setData(self::FIELD_IS_ENABLED_PATH, $configPath);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,113 @@
|
||||
<?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\Model\Extension\Information;
|
||||
|
||||
use Magento\Framework\Config\DataInterface;
|
||||
use Magento\Framework\Module\ModuleListInterface;
|
||||
use Plumrocket\Base\Api\Data\ExtensionInformationInterface;
|
||||
use Plumrocket\Base\Api\GetExtensionInformationInterface;
|
||||
use Plumrocket\Base\Model\Extension\GetModuleName;
|
||||
use Plumrocket\Base\Model\Extension\Information\ContainerFactory;
|
||||
|
||||
/**
|
||||
* @since 2.3.0
|
||||
*/
|
||||
class Get implements GetExtensionInformationInterface
|
||||
{
|
||||
/**
|
||||
* @var string[]
|
||||
*/
|
||||
private $services = [
|
||||
'Base',
|
||||
'Token',
|
||||
'AmpEmailApi',
|
||||
];
|
||||
|
||||
/**
|
||||
* @var \Plumrocket\Base\Api\Data\ExtensionInformationInterface[]
|
||||
*/
|
||||
private $extensions;
|
||||
|
||||
/**
|
||||
* @var \Plumrocket\Base\Model\Extension\Information\ContainerFactory
|
||||
*/
|
||||
private $informationContainerFactory;
|
||||
|
||||
/**
|
||||
* @var \Plumrocket\Base\Model\Extension\GetModuleName
|
||||
*/
|
||||
private $getExtensionName;
|
||||
|
||||
/**
|
||||
* @var \Magento\Framework\Config\DataInterface
|
||||
*/
|
||||
private $extensionsConfig;
|
||||
|
||||
/**
|
||||
* @var \Magento\Framework\Module\ModuleListInterface
|
||||
*/
|
||||
private $moduleList;
|
||||
|
||||
/**
|
||||
* @param \Plumrocket\Base\Model\Extension\Information\ContainerFactory $informationContainerFactory
|
||||
* @param \Plumrocket\Base\Model\Extension\GetModuleName $getExtensionName
|
||||
* @param \Magento\Framework\Config\DataInterface $extensionsConfig
|
||||
* @param \Magento\Framework\Module\ModuleListInterface $moduleList
|
||||
* @param array $extensions
|
||||
*/
|
||||
public function __construct(
|
||||
ContainerFactory $informationContainerFactory,
|
||||
GetModuleName $getExtensionName,
|
||||
DataInterface $extensionsConfig,
|
||||
ModuleListInterface $moduleList,
|
||||
array $extensions = []
|
||||
) {
|
||||
$this->extensions = $extensions;
|
||||
$this->informationContainerFactory = $informationContainerFactory;
|
||||
$this->getExtensionName = $getExtensionName;
|
||||
$this->extensionsConfig = $extensionsConfig;
|
||||
$this->moduleList = $moduleList;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function execute(string $moduleName): ExtensionInformationInterface
|
||||
{
|
||||
$moduleName = $this->getExtensionName->execute($moduleName);
|
||||
|
||||
if (! isset($this->extensions[$moduleName])) {
|
||||
/** @var \Plumrocket\Base\Model\Extension\Information\Container $infoContainer */
|
||||
$infoContainer = $this->informationContainerFactory->create();
|
||||
$infoContainer->setModuleName($moduleName);
|
||||
|
||||
if ($extensionConfig = $this->extensionsConfig->get($moduleName)) {
|
||||
$infoContainer->setIsService($extensionConfig[ExtensionInformationInterface::FIELD_IS_SERVICE])
|
||||
->setModuleName($extensionConfig['name'])
|
||||
->setTitle($extensionConfig['title'])
|
||||
->setConfigSection($extensionConfig['config_section'])
|
||||
->setIsEnabledFieldConfigPath($extensionConfig['is_enabled_path'])
|
||||
->setDocumentationLink($extensionConfig['documentation'] ?: $extensionConfig['wiki'])
|
||||
->setUrl($extensionConfig[ExtensionInformationInterface::FIELD_URL] ?? '')
|
||||
->setMarketplaceUrl(
|
||||
$extensionConfig[ExtensionInformationInterface::FIELD_MARKETPLACE_URL] ?? ''
|
||||
);
|
||||
} else {
|
||||
if ($this->moduleList->has("Plumrocket_$moduleName")) {
|
||||
$infoContainer->setIsService(in_array($moduleName, $this->services, true));
|
||||
}
|
||||
}
|
||||
|
||||
$this->extensions[$moduleName] = $infoContainer;
|
||||
}
|
||||
|
||||
return $this->extensions[$moduleName];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
<?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\Model\Extension\Information;
|
||||
|
||||
use Magento\Framework\Api\SearchCriteriaBuilder;
|
||||
use Magento\Framework\Api\SearchCriteriaInterface;
|
||||
use Magento\Framework\Api\SearchResultsInterface;
|
||||
use Plumrocket\Base\Api\Data\ExtensionInformationSearchResultsInterfaceFactory;
|
||||
use Plumrocket\Base\Api\ExtensionInformationListInterface;
|
||||
use Plumrocket\Base\Api\GetExtensionInformationInterface;
|
||||
use Plumrocket\Base\Model\Extension\GetListOfInstalled;
|
||||
|
||||
/**
|
||||
* @since 2.5.0
|
||||
*/
|
||||
class ListProvider implements ExtensionInformationListInterface
|
||||
{
|
||||
/**
|
||||
* @var \Magento\Framework\Api\SearchCriteriaBuilder
|
||||
*/
|
||||
private $searchCriteriaBuilder;
|
||||
|
||||
/**
|
||||
* @var \Plumrocket\Base\Api\Data\ExtensionInformationSearchResultsInterfaceFactory
|
||||
*/
|
||||
private $searchResultsFactory;
|
||||
|
||||
/**
|
||||
* @var \Plumrocket\Base\Model\Extension\GetListOfInstalled
|
||||
*/
|
||||
private $getListOfInstalledExtensions;
|
||||
|
||||
/**
|
||||
* @var \Plumrocket\Base\Api\GetExtensionInformationInterface
|
||||
*/
|
||||
private $getExtensionInformation;
|
||||
|
||||
/**
|
||||
* @param \Magento\Framework\Api\SearchCriteriaBuilder $searchCriteriaBuilder
|
||||
* @param \Plumrocket\Base\Api\Data\ExtensionInformationSearchResultsInterfaceFactory $searchResultsFactory
|
||||
* @param \Plumrocket\Base\Model\Extension\GetListOfInstalled $getListOfInstalledExtensions
|
||||
* @param \Plumrocket\Base\Api\GetExtensionInformationInterface $getExtensionInformation
|
||||
*/
|
||||
public function __construct(
|
||||
SearchCriteriaBuilder $searchCriteriaBuilder,
|
||||
ExtensionInformationSearchResultsInterfaceFactory $searchResultsFactory,
|
||||
GetListOfInstalled $getListOfInstalledExtensions,
|
||||
GetExtensionInformationInterface $getExtensionInformation
|
||||
) {
|
||||
$this->searchCriteriaBuilder = $searchCriteriaBuilder;
|
||||
$this->searchResultsFactory = $searchResultsFactory;
|
||||
$this->getListOfInstalledExtensions = $getListOfInstalledExtensions;
|
||||
$this->getExtensionInformation = $getExtensionInformation;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getList(?SearchCriteriaInterface $searchCriteria = null): SearchResultsInterface
|
||||
{
|
||||
if (null === $searchCriteria) {
|
||||
$searchCriteria = $this->searchCriteriaBuilder->create();
|
||||
}
|
||||
|
||||
$extensionsNames = $this->getListOfInstalledExtensions->execute();
|
||||
|
||||
$informationList = [];
|
||||
foreach ($extensionsNames as $extensionsName) {
|
||||
$informationList[] = $this->getExtensionInformation->execute($extensionsName);
|
||||
}
|
||||
|
||||
/** @var \Plumrocket\Base\Api\Data\ExtensionInformationSearchResultsInterface $searchResults */
|
||||
$searchResults = $this->searchResultsFactory->create();
|
||||
|
||||
$searchResults->setItems($informationList);
|
||||
$searchResults->setTotalCount(count($informationList));
|
||||
$searchResults->setSearchCriteria($searchCriteria);
|
||||
|
||||
return $searchResults;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user