N°7847 - Extensions via interface not recognized

N°7803 - MTP from itophub/designer failing in itop 3.2.0
This commit is contained in:
Eric Espie
2024-10-11 10:02:03 +02:00
parent 75520bfaf9
commit 6c8388ea5e
4 changed files with 19 additions and 23 deletions

View File

@@ -7477,6 +7477,8 @@ abstract class MetaModel
* @param string|null $sFilterInstanceOf [optional] if given, only instance of this string will be returned
*
* @return array classes=>instance implementing the given interface
*
* @see \Combodo\iTop\Service\InterfaceDiscovery\InterfaceDiscovery::FindItopClasses() to add extensibility to modules
*/
public static function EnumPlugins($sInterface, $sFilterInstanceOf = null)
{

View File

@@ -161,7 +161,7 @@ class DataModelDependantCache
/**
* for test purpose
*
* @param string $sStorageRootDir
* @param string|null $sStorageRootDir if null the current cache path is used
*/
public function SetStorageRootDir(?string $sStorageRootDir): void
{

View File

@@ -10,6 +10,13 @@ use MetaModel;
use ReflectionClass;
use utils;
/**
* Enumerate classes implementing given interfaces
*
* @api
*
* @since 3.2.0
*/
class InterfaceDiscovery
{
private static InterfaceDiscovery $oInstance;
@@ -17,8 +24,8 @@ class InterfaceDiscovery
private ?array $aForcedClassMap = null; // For testing purposes
const CACHE_NONE = 'CACHE_NONE';
const CACHE_DYNAMIC = 'CACHE_DYNAMIC';
const CACHE_STATIC = 'CACHE_STATIC';
const CACHE_DYNAMIC = 'CACHE_DYNAMIC'; // rebuild cache when files changes
const CACHE_STATIC = 'CACHE_STATIC'; // Built once at setup
private function __construct()
{
@@ -38,20 +45,20 @@ class InterfaceDiscovery
* Find the ITOP classes implementing a given interface. The returned classes have the following properties:
* - They can be instantiated
* - They are not aliases
* - Their path relative to iTop does not contain /lib/, /node_modules/, /test/ or /tests/
*
* @param string $sInterface Fully qualified interface name
* @param array|null $aAdditionalExcludedPaths Optional list of paths to exclude from the search (partial names allowed, case sensitive, use / as separator)
*
* @return array of fully qualified class names
* @throws \ReflectionException when $sInterface is not an interface
*
* @api
*
* @since 3.2.0
*/
public function FindItopClasses(string $sInterface, ?array $aAdditionalExcludedPaths = null): array
public function FindItopClasses(string $sInterface): array
{
if (is_null($aAdditionalExcludedPaths)) {
return $this->FindClasses($sInterface, ['/lib/', '/node_modules/', '/test/', '/tests/']);
}
$aExcludedPaths = array_merge(['/lib/', '/node_modules/', '/test/', '/tests/'], $aAdditionalExcludedPaths);
$aExcludedPaths = ['/lib/', '/node_modules/', '/test/', '/tests/'];
return $this->FindClasses($sInterface, $aExcludedPaths);
}

View File

@@ -49,19 +49,6 @@ class InterfaceDiscoveryTest extends ItopDataTestCase
);
}
public function testShouldExcludeSpecifiedDirectories()
{
$this->GivenClassMap([
'Combodo\iTop\Application\UI\Base\Component\Alert\AlertUIBlockFactory' => APPROOT . '/sources/Application/UI/Base/Component/Alert/AlertUIBlockFactory.php',
'Combodo\iTop\Application\UI\Base\Component\ButtonGroup\ButtonGroupUIBlockFactory' => APPROOT . '/sources/Application/UI/Base/Component/ButtonGroup/ButtonGroupUIBlockFactory.php',
]);
$this->AssertArraysHaveSameItems(
[],
$this->oInterfaceDiscovery->FindItopClasses(iUIBlockFactory::class, ['Component/ButtonGroup', '/Alert/'])
);
}
public function testShouldExcludeAliases()
{
$this->GivenClassMap([