2022-12-30 23:05:33 +01:00
|
|
|
<?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);
|
|
|
|
|
2022-12-30 23:05:33 +01:00
|
|
|
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
|
|
|
|
2022-12-30 23:05:33 +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 => [],
|
2022-12-30 23:05:33 +01:00
|
|
|
];
|
|
|
|
|
2023-11-23 15:01:44 +01:00
|
|
|
protected array $allowedTypes = [
|
2024-01-31 21:17:51 +01:00
|
|
|
self::TYPE_YAML,
|
2022-12-30 23:05:33 +01:00
|
|
|
];
|
|
|
|
|
|
|
|
public function __construct()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2023-11-23 15:01:44 +01:00
|
|
|
/**
|
2024-01-31 21:56:19 +01:00
|
|
|
* @param string $definitionFile
|
|
|
|
* @param string $type
|
2023-11-23 15:01:44 +01:00
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2024-01-31 21:56:19 +01:00
|
|
|
public function addDefinitions(string $definitionFile, string $type): void
|
2022-12-30 23:05:33 +01:00
|
|
|
{
|
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');
|
2022-12-30 23:05:33 +01:00
|
|
|
|
|
|
|
$this->definitionFiles[$type][md5($definitionFile)] = $definitionFile;
|
|
|
|
}
|
|
|
|
|
2024-01-31 21:56:19 +01:00
|
|
|
/**
|
|
|
|
* @param string $definitionFile
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function addYamlDefinitions(string $definitionFile): void
|
2022-12-30 23:05:33 +01:00
|
|
|
{
|
|
|
|
$this->addDefinitions($definitionFile, self::TYPE_YAML);
|
|
|
|
}
|
|
|
|
|
2023-11-23 15:01:44 +01:00
|
|
|
/**
|
2024-01-31 21:56:19 +01:00
|
|
|
* @param string $type
|
2023-11-23 15:01:44 +01:00
|
|
|
*
|
|
|
|
* @return array
|
|
|
|
*/
|
2024-01-31 21:56:19 +01:00
|
|
|
public function getDefinitions(string $type): array
|
2022-12-30 23:05:33 +01:00
|
|
|
{
|
2024-01-31 19:25:06 +01:00
|
|
|
Assert::that($type)->inArray($this->allowedTypes, 'invalid definition file type');
|
2022-12-30 23:05:33 +01:00
|
|
|
|
|
|
|
return $this->definitionFiles[$type];
|
|
|
|
}
|
|
|
|
|
2023-11-23 15:01:44 +01:00
|
|
|
/**
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function getYamlDefinitions(): array
|
2022-12-30 23:05:33 +01:00
|
|
|
{
|
|
|
|
return $this->getDefinitions(self::TYPE_YAML);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2024-01-31 19:25:06 +01:00
|
|
|
* @return array[]
|
2022-12-30 23:05:33 +01:00
|
|
|
*/
|
2023-11-23 15:01:44 +01:00
|
|
|
public function getAll(): array
|
2022-12-30 23:05:33 +01:00
|
|
|
{
|
|
|
|
return $this->definitionFiles;
|
|
|
|
}
|
|
|
|
|
2023-11-23 15:01:44 +01:00
|
|
|
public function clear(): void
|
2022-12-30 23:05:33 +01:00
|
|
|
{
|
|
|
|
$this->definitionFiles = [];
|
|
|
|
}
|
2024-01-31 21:17:51 +01:00
|
|
|
}
|