default services conflit ?

This commit is contained in:
armansansd
2022-04-27 11:30:43 +02:00
parent 28190a5749
commit 8bb1064a3b
8132 changed files with 900138 additions and 426 deletions

View File

@@ -0,0 +1,25 @@
<?php
/**
* @file
* Contains \Drupal\Console\Extension\Discovery.
*/
namespace Drupal\Console\Extension;
use Drupal\Core\Extension\ExtensionDiscovery;
/*
* @see Remove DrupalExtensionDiscovery subclass once
* https://www.drupal.org/node/2503927 is fixed.
*/
class Discovery extends ExtensionDiscovery
{
/**
* Reset internal static cache.
*/
public static function reset()
{
static::$files = [];
}
}

View File

@@ -0,0 +1,183 @@
<?php
namespace Drupal\Console\Extension;
use Drupal\Core\Extension\Extension as BaseExtension;
/**
* Class Extension
*
* @package Drupal\Console\Extension
*/
class Extension extends BaseExtension
{
/**
* @param $fullPath
* @return string
*/
public function getPath($fullPath = false)
{
if ($fullPath) {
return $this->root . '/' . parent::getPath();
}
return parent::getPath();
}
/**
* @param bool $fullPath
* @return string
*/
public function getControllerPath($fullPath = false)
{
return $this->getSourcePath($fullPath) . '/Controller';
}
/**
* @param bool $fullPath
* @return string
*/
public function getAjaxPath($fullPath = false)
{
return $this->getSourcePath($fullPath) . '/Ajax';
}
/**
* @param bool $fullPath
* @return string
*/
public function getConfigInstallDirectory($fullPath = false)
{
return $this->getPath($fullPath) .'/config/install';
}
/**
* @param bool $fullPath
* @return string
*/
public function getConfigOptionalDirectory($fullPath = false)
{
return $this->getPath($fullPath) .'/config/optional';
}
/**
* @param bool $fullPath
* @return string
*/
public function getSourcePath($fullPath=false)
{
return $this->getPath($fullPath) . '/src';
}
/**
* @param string $authenticationType
* @param boolean $fullPath
* @return string
*/
public function getAuthenticationPath($authenticationType, $fullPath = false)
{
return $this->getSourcePath($fullPath) .'/Authentication/' . $authenticationType;
}
/**
* @param $fullPath
* @return string
*/
public function getFormPath($fullPath = false)
{
return $this->getSourcePath($fullPath) . '/Form';
}
/**
* @param $fullPath
* @return string
*/
public function getRoutingPath($fullPath = false)
{
return $this->getSourcePath($fullPath) . '/Routing';
}
/**
* @param bool $fullPath
* @return string
*/
public function getCommandDirectory($fullPath=false)
{
return $this->getSourcePath($fullPath) . '/Command/';
}
/**
* @param bool $fullPath
* @return string
*/
public function getGeneratorDirectory($fullPath=false)
{
return $this->getSourcePath($fullPath) . '/Generator/';
}
/**
* @param bool $fullPath
* @return string
*/
public function getEntityPath($fullPath = false)
{
return $this->getSourcePath($fullPath) . '/Entity';
}
/**
* @param bool $fullPath
* @return string
*/
public function getTemplatePath($fullPath = false)
{
return $this->getPath($fullPath) . '/templates';
}
/**
* @param string $testType
* @param bool $fullPath
* @return string
*/
public function getTestsPath($testType, $fullPath = false)
{
return $this->getPath($fullPath) . '/tests/' . $testType;
}
/**
* @param bool $fullPath
* @return string
*/
public function getTestsSourcePath($fullPath = false)
{
return $this->getTestsPath($fullPath) . '/src';
}
/**
* @param bool $fullPath
* @return string
*/
public function getJsTestsPath($fullPath = false)
{
return $this->getTestsSourcePath($fullPath) . '/FunctionalJavascript';
}
/**
* @param BaseExtension $extension
*/
function loadFromParentObj(BaseExtension $extension)
{
$objValues = get_object_vars($extension);
foreach($objValues AS $key => $value)
{
$this->$key = $value;
}
}
/**
* @param $root
*/
function setRoot($root) {
$this->root = $root;
}
}

View File

@@ -0,0 +1,432 @@
<?php
namespace Drupal\Console\Extension;
use Drupal\Console\Utils\Site;
use GuzzleHttp\Client;
use GuzzleHttp\Exception\ClientException;
use Drupal\Core\Extension\ModuleExtensionList;
use Drupal\Core\Extension\ThemeHandler;
use Drupal\Core\Extension\ModuleHandlerInterface;
/**
* Class ExtensionManager
*
* @package Drupal\Console
*/
class Manager
{
/**
* @var Site
*/
protected $site;
/**
* @var Client
*/
protected $httpClient;
/**
* @var string
*/
protected $appRoot;
/**
* @var array
*/
private $extensions = [];
/**
* @var array
*/
private $filters = [];
/**
* @var string
*/
private $extension = null;
/**
* @var Drupal\Core\Extension\ModuleExtensionList
*/
private $extensionList;
/**
* @var ModuleHandlerInterface
*/
protected $moduleHandler;
/**
* @var ThemeHandler
*/
protected $themeHandler;
/**
* ExtensionManager constructor.
*
* @param Site $site
* @param Client $httpClient
* @param string $appRoot
* @param ModuleExtensionList $extensionList
* @param ModuleHandlerInterface $moduleHandler
* @param ThemeHandler $themeHandler
*/
public function __construct(
Site $site,
Client $httpClient,
$appRoot,
ModuleExtensionList $extensionList,
ModuleHandlerInterface $moduleHandler,
ThemeHandler $themeHandler
) {
$this->site = $site;
$this->httpClient = $httpClient;
$this->appRoot = $appRoot;
$this->extensionList = $extensionList;
$this->moduleHandler = $moduleHandler;
$this->themeHandler = $themeHandler;
$this->initialize();
}
/**
* @return $this
*/
public function showInstalled()
{
$this->filters['showInstalled'] = true;
return $this;
}
/**
* @return $this
*/
public function showUninstalled()
{
$this->filters['showUninstalled'] = true;
return $this;
}
/**
* @return $this
*/
public function showCore()
{
$this->filters['showCore'] = true;
return $this;
}
/**
* @return $this
*/
public function showNoCore()
{
$this->filters['showNoCore'] = true;
return $this;
}
/**
* @param boolean $nameOnly
* @return array
*/
public function getList($nameOnly = false)
{
return $this->getExtensions($this->extension, $nameOnly);
}
/**
* @return $this
*/
public function discoverModules()
{
$this->initialize();
$this->discoverExtension('module');
return $this;
}
/**
* @return $this
*/
public function discoverThemes()
{
$this->initialize();
$this->discoverExtension('theme');
return $this;
}
/**
* @return $this
*/
public function discoverProfiles()
{
$this->initialize();
$this->discoverExtension('profile');
return $this;
}
/**
* @param string $extension
*/
private function discoverExtension($extension)
{
$this->extension = $extension;
$this->extensions[$extension] = $this->discoverExtensions($extension);
return $this;
}
/**
* initializeFilters
*/
private function initialize()
{
$this->extension = 'module';
$this->extensions = [
'module' => [],
'theme' => [],
'profile' => [],
];
$this->filters = [
'showInstalled' => false,
'showUninstalled' => false,
'showCore' => false,
'showNoCore' => false
];
}
/**
* @param string $type
* @param bool|false $nameOnly
* @return array
*/
private function getExtensions(
$type = 'module',
$nameOnly = false
) {
$showInstalled = $this->filters['showInstalled'];
$showUninstalled = $this->filters['showUninstalled'];
$showCore = $this->filters['showCore'];
$showNoCore = $this->filters['showNoCore'];
$extensions = [];
if (!array_key_exists($type, $this->extensions)) {
return $extensions;
}
foreach ($this->extensions[$type] as $extension) {
$name = $extension->getName();
$isInstalled = $type=='module' && $this->moduleHandler->moduleExists($name);
if (!$isInstalled && property_exists($extension, 'status')) {
$isInstalled = ($extension->status)?true:false;
}
if (!$showInstalled && $isInstalled) {
continue;
}
if (!$showUninstalled && !$isInstalled) {
continue;
}
if (!$showCore && $extension->origin == 'core') {
continue;
}
if (!$showNoCore && $extension->origin != 'core') {
continue;
}
$extensions[$name] = $extension;
}
return $nameOnly?array_keys($extensions):$extensions;
}
/**
* @param string $type
* @return \Drupal\Core\Extension\Extension[]
*/
private function discoverExtensions($type)
{
if ($type === 'module') {
$this->site->loadLegacyFile('/core/modules/system/system.module');
$this->extensionList->reset()->getList();
}
if ($type === 'theme') {
$this->themeHandler->rebuildThemeData();
}
/*
* @see Remove DrupalExtensionDiscovery subclass once
* https://www.drupal.org/node/2503927 is fixed.
*/
$discovery = new Discovery($this->appRoot);
$discovery->reset();
return $discovery->scan($type);
}
/**
* @param string $name
* @return \Drupal\Console\Extension\Extension
*/
public function getModule($name)
{
if ($extension = $this->getExtension('module', $name)) {
return $this->createExtension($extension);
}
return null;
}
/**
* @param string $name
* @return \Drupal\Console\Extension\Extension
*/
public function getProfile($name)
{
if ($extension = $this->getExtension('profile', $name)) {
return $this->createExtension($extension);
}
return null;
}
/**
* @param string $name
* @return \Drupal\Console\Extension\Extension
*/
public function getTheme($name)
{
if ($extension = $this->getExtension('theme', $name)) {
return $this->createExtension($extension);
}
return null;
}
/**
* @param string $type
* @param string $name
*
* @return \Drupal\Core\Extension\Extension
*/
private function getExtension($type, $name)
{
if (!$this->extensions[$type]) {
$this->discoverExtension($type);
}
if (array_key_exists($name, $this->extensions[$type])) {
return $this->extensions[$type][$name];
}
return null;
}
/**
* @param \Drupal\Core\Extension\Extension $extension
* @return \Drupal\Console\Extension\Extension
*/
private function createExtension($extension)
{
$consoleExtension = new Extension(
$this->appRoot,
$extension->getType(),
$extension->getPathname(),
$extension->getExtensionFilename()
);
$consoleExtension->loadFromParentObj($extension);
$consoleExtension->setRoot($this->appRoot);
return $consoleExtension;
}
/**
* @param string $testType
* @param $fullPath
* @return string
*/
public function getTestPath($testType, $fullPath = false)
{
return $this->getPath($fullPath) . '/Tests/' . $testType;
}
public function validateModuleFunctionExist($moduleName, $function, $moduleFile = null)
{
//Load module file to prevent issue of missing functions used in update
$module = $this->getModule($moduleName);
$modulePath = $module->getPath();
if ($moduleFile) {
$this->site->loadLegacyFile($modulePath . '/' . $moduleFile);
} else {
$this->site->loadLegacyFile($modulePath . '/' . $module->getName() . '.module');
}
if (function_exists($function)) {
return true;
}
return false;
}
/**
* @param string $moduleName
* @param string $pluginType
* @return string
*/
public function getPluginPath($moduleName, $pluginType)
{
$module = $this->getModule($moduleName);
return $module->getPath() . '/src/Plugin/' . $pluginType;
}
public function getDrupalExtension($type, $name)
{
$extension = $this->getExtension($type, $name);
return $this->createExtension($extension);
}
/**
* @param array $extensions
* @param string $type
* @return array
*/
public function checkExtensions(array $extensions, $type = 'module')
{
$checkextensions = [
'local_extensions' => [],
'drupal_extensions' => [],
'no_extensions' => [],
];
$local_extensions = $this->discoverExtension($type)
->showInstalled()
->showUninstalled()
->showCore()
->showNoCore()
->getList(true);
foreach ($extensions as $extension) {
if (in_array($extension, $local_extensions)) {
$checkextensions['local_extensions'][] = $extension;
} else {
try {
$response = $this->httpClient->head('https://www.drupal.org/project/' . $extension);
$header_link = $response->getHeader('link');
if (empty($header_link[0])) {
$checkextensions['no_extensions'][] = $extension;
} else {
$checkextensions['drupal_extensions'][] = $extension;
}
} catch (ClientException $e) {
$checkextensions['no_extensions'][] = $extension;
}
}
}
return $checkextensions;
}
}