Implemented changes regarding Component and Directory duplicity in the Configurator. Now it is no longer possible to accidentally load the same component or directory twice.
This commit is contained in:
parent
90b1a6f7aa
commit
53e721f781
|
@ -2,5 +2,4 @@
|
|||
.gitignore export-ignore
|
||||
.gitlab-ci.yml export-ignore
|
||||
.travis.yml export-ignore
|
||||
tests/ export-ignore
|
||||
CI/ export-ignore
|
||||
test/ export-ignore
|
|
@ -126,9 +126,13 @@ class Configurator
|
|||
* @param string $category Optional
|
||||
* @param int $priority
|
||||
* @return $this
|
||||
* @throws InvalidArgumentException
|
||||
*/
|
||||
public function addDirectory(string $directory, string $category, $priority = Priority::NORMAL): Configurator
|
||||
{
|
||||
if (!file_exists($directory))
|
||||
throw new InvalidArgumentException("Could not add directory. Directory does not exist.");
|
||||
|
||||
if (!isset($this->directories[$category]))
|
||||
$this->directories[$category] = [];
|
||||
|
||||
|
@ -151,11 +155,11 @@ class Configurator
|
|||
*/
|
||||
public function addComponent(iComponent $component): Configurator
|
||||
{
|
||||
if (in_array($component, $this->components))
|
||||
if (isset($this->components[get_class($component)]))
|
||||
return $this;
|
||||
|
||||
$component->onAddComponent($this);
|
||||
$this->components[] = $component;
|
||||
$this->components[get_class($component)] = $component;
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
@ -349,7 +353,7 @@ class Configurator
|
|||
Logger::enable();
|
||||
|
||||
// Load components
|
||||
foreach ($this->components as $component)
|
||||
foreach ($this->components as $componentSuperClass => $component)
|
||||
{
|
||||
Logger::logInfo("Adding Component: '" . $component->getName() . "'");
|
||||
foreach ($component->getClasses() as $componentName => $componentClass)
|
||||
|
|
|
@ -240,6 +240,16 @@ class configuratorTest extends CoreTestAbstract
|
|||
$this->assertEquals([vfsStream::url('testAddComponentDirectory')], $container->testaddcomponentdirectory->getComponentPaths());
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends testAddComponentDirectory
|
||||
* @covers ::addDirectory
|
||||
* @expectedException \FuzeWorks\Exception\InvalidArgumentException
|
||||
*/
|
||||
public function testAddComponentDirectoryNotExist()
|
||||
{
|
||||
$this->configurator->addDirectory('not_exist', 'irrelevant');
|
||||
}
|
||||
|
||||
/* ---------------------------------- Deferred Invocation --------------------------------------- */
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue