8
0
DIContainer/definitionFileContainer.php

75 Zeilen
1.7 KiB
PHP

<?php
2023-01-03 10:49:19 +01:00
/**
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* https://www.d3data.de
*
* @copyright (C) D3 Data Development (Inh. Thomas Dartsch)
* @author D3 Data Development - Daniel Seifert <support@shopmodule.com>
* @link https://www.oxidmodule.com
*/
declare(strict_types=1);
namespace D3\DIContainerHandler;
2024-01-31 19:25:06 +01:00
use Assert\Assert;
use Assert\InvalidArgumentException;
2023-11-23 15:01:44 +01:00
class definitionFileContainer
{
public const TYPE_YAML = 'yml';
2023-11-23 15:01:44 +01:00
protected array $definitionFiles = [
2024-01-31 21:17:51 +01:00
self::TYPE_YAML => [],
];
2023-11-23 15:01:44 +01:00
protected array $allowedTypes = [
2024-01-31 21:17:51 +01:00
self::TYPE_YAML,
];
public function __construct()
{
}
2024-01-31 21:56:19 +01:00
public function addDefinitions(string $definitionFile, string $type): void
{
2024-01-31 19:25:06 +01:00
Assert::that($type)->inArray($this->allowedTypes, 'invalid definition file type');
Assert::that(rtrim(dirname(__FILE__, 3).'/').$definitionFile)->file('invalid definition file');
$this->definitionFiles[$type][md5($definitionFile)] = $definitionFile;
}
2024-01-31 21:56:19 +01:00
public function addYamlDefinitions(string $definitionFile): void
{
$this->addDefinitions($definitionFile, self::TYPE_YAML);
}
2024-01-31 21:56:19 +01:00
public function getDefinitions(string $type): array
{
2024-01-31 19:25:06 +01:00
Assert::that($type)->inArray($this->allowedTypes, 'invalid definition file type');
return $this->definitionFiles[$type];
}
2023-11-23 15:01:44 +01:00
public function getYamlDefinitions(): array
{
return $this->getDefinitions(self::TYPE_YAML);
}
/**
2024-01-31 19:25:06 +01:00
* @return array[]
*/
2023-11-23 15:01:44 +01:00
public function getAll(): array
{
return $this->definitionFiles;
}
2023-11-23 15:01:44 +01:00
public function clear(): void
{
$this->definitionFiles = [];
}
2024-01-31 21:17:51 +01:00
}