Optimized NamespacePathMap

This commit is contained in:
Kevin Frantz
2019-01-06 14:38:28 +01:00
parent 72d0a6ba95
commit 77822b8e56
3 changed files with 91 additions and 8 deletions

View File

@@ -3,6 +3,8 @@
namespace App\Domain\PathManagement;
/**
* Be carefull with the case sensivity.
*
* @author kevinfrantz
*/
final class NamespacePathMap implements NamespacePathMapInterface
@@ -49,6 +51,7 @@ final class NamespacePathMap implements NamespacePathMapInterface
*/
public function setPath(string $path): void
{
$this->setFolders(explode('/', $path));
}
/**
@@ -58,18 +61,32 @@ final class NamespacePathMap implements NamespacePathMapInterface
*/
public function setNamespace(string $namespace): void
{
$this->setFolders(explode('\\', $namespace));
}
/**
* The strtolower function could lead to conflicts in other contextes
* {@inheritdoc}
*
* @see \App\Domain\PathManagement\NamespacePathMapInterface::setFolderArray()
*/
public function setFolders(array $folders): void
{
$this->folders = [];
foreach ($folders as $folder) {
$this->folders[] = strtolower($folder);
}
$this->namespace = implode('\\', $this->folders);
$this->path = implode('/', $this->folders);
}
/**
* {@inheritdoc}
*
* @see \App\Domain\PathManagement\NamespacePathMapInterface::setFolderArray()
* @see \App\Domain\PathManagement\NamespacePathMapInterface::getFolders()
*/
public function setFolderArray(array $folders): void
{
}
public function getFolderArray(): array
public function getFolders(): array
{
return $this->folders;
}
}

View File

@@ -32,10 +32,10 @@ interface NamespacePathMapInterface
/**
* @param array|string[] $folders
*/
public function setFolderArray(array $folders): void;
public function setFolders(array $folders): void;
/**
* @return array|string[]
*/
public function getFolderArray(): array;
public function getFolders(): array;
}