DIContainer/definitionFileContainer.php

77 lines
1.8 KiB
PHP
Raw Permalink Normal View History

<?php
2023-01-03 10:49:19 +01:00
/**
2024-06-15 23:10:49 +02:00
* Copyright (c) D3 Data Development (Inh. Thomas Dartsch)
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
2023-01-03 10:49:19 +01:00
*
* https://www.d3data.de
*
* @copyright (C) D3 Data Development (Inh. Thomas Dartsch)
2024-06-15 23:10:49 +02:00
* @author D3 Data Development - Daniel Seifert <info@shopmodule.com>
2023-01-03 10:49:19 +01:00
* @link https://www.oxidmodule.com
*/
declare(strict_types=1);
namespace D3\DIContainerHandler;
2024-01-31 19:25:06 +01:00
use Assert\Assert;
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-02-19 08:36:41 +01:00
/** keep clear */
}
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');
2024-06-16 01:28:42 +02:00
Assert::that(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
}