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:
Abel Hoogeveen 2019-03-01 10:51:51 +01:00
parent 90b1a6f7aa
commit 53e721f781
No known key found for this signature in database
GPG Key ID: 96C2234920BF4292
3 changed files with 18 additions and 5 deletions

3
.gitattributes vendored
View File

@ -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

View File

@ -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)

View File

@ -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 --------------------------------------- */
/**