first commit
This commit is contained in:
51
bundles/KupShop/ComponentsBundle/Utils/ComponentsLocator.php
Normal file
51
bundles/KupShop/ComponentsBundle/Utils/ComponentsLocator.php
Normal file
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace KupShop\ComponentsBundle\Utils;
|
||||
|
||||
class ComponentsLocator
|
||||
{
|
||||
public function __construct(
|
||||
protected array $components,
|
||||
protected array $unusedComponents,
|
||||
) {
|
||||
}
|
||||
|
||||
public function getComponents(): array
|
||||
{
|
||||
return $this->components;
|
||||
}
|
||||
|
||||
public function getComponent(string $class): ?array
|
||||
{
|
||||
return $this->components[$class] ?? null;
|
||||
}
|
||||
|
||||
public function findComponentByName($name): ?array
|
||||
{
|
||||
foreach ($this->components as $component) {
|
||||
if ($component['name'] === $name) {
|
||||
return $component;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public function getUnusedComponents(): array
|
||||
{
|
||||
return $this->unusedComponents;
|
||||
}
|
||||
|
||||
public function findUnusedComponentByName($name): ?array
|
||||
{
|
||||
foreach ($this->unusedComponents as $component) {
|
||||
if ($component['name'] === $name) {
|
||||
return $component;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user