mirror of
https://github.com/Combodo/iTop.git
synced 2026-04-23 10:38:45 +02:00
Add ModelReflection Service as dependency injection + tests
This commit is contained in:
@@ -2,16 +2,26 @@
|
||||
|
||||
namespace Combodo\iTop\Forms\IO\Format;
|
||||
|
||||
use JsonSerializable;
|
||||
use Combodo\iTop\DependencyInjection\DIService;
|
||||
use Combodo\iTop\Forms\IO\FormBlockIOException;
|
||||
|
||||
class ClassIOFormat implements JsonSerializable
|
||||
class ClassIOFormat extends AbstractIOFormat
|
||||
{
|
||||
public string $sClassName;
|
||||
|
||||
/**
|
||||
* @throws \Combodo\iTop\DependencyInjection\DIException
|
||||
* @throws \Combodo\iTop\Forms\IO\FormBlockIOException
|
||||
*/
|
||||
public function __construct(string $sClassName)
|
||||
{
|
||||
// Check class validity
|
||||
/** @var \ModelReflection $oModelReflection */
|
||||
$oModelReflection = DIService::GetInstance()->GetService('ModelReflection');
|
||||
if (!$oModelReflection->IsValidClass($sClassName)) {
|
||||
throw new FormBlockIOException("Class ".json_encode($sClassName)." is not valid");
|
||||
}
|
||||
$this->sClassName = $sClassName;
|
||||
// validation du format sinon exception
|
||||
}
|
||||
|
||||
public function __toString(): string
|
||||
@@ -23,4 +33,9 @@ class ClassIOFormat implements JsonSerializable
|
||||
{
|
||||
return $this->sClassName;
|
||||
}
|
||||
|
||||
public static function IsCompatible(string $sOtherFormatClass): bool
|
||||
{
|
||||
return is_a($sOtherFormatClass, ClassIOFormat::class, true) || is_a($sOtherFormatClass, RawFormat::class, true);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user