8
0
Fork 0
DIContainer/definitionFileContainer.php

103 Zeilen
2.2 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;
2023-11-23 15:01:44 +01:00
use InvalidArgumentException;
class definitionFileContainer
{
public const TYPE_YAML = 'yml';
2023-11-23 15:01:44 +01:00
protected array $definitionFiles = [
2023-11-23 15:05:40 +01:00
self::TYPE_YAML => [],
];
2023-11-23 15:01:44 +01:00
protected array $allowedTypes = [
2023-11-23 15:05:40 +01:00
self::TYPE_YAML,
];
public function __construct()
{
$this->addYamlDefinitions('d3/modcfg/Config/services.yaml');
}
2023-11-23 15:01:44 +01:00
/**
* @param string $definitionFile
* @param string $type
*
* @return void
*/
public function addDefinitions(string $definitionFile, string $type): void
{
if (!in_array($type, $this->allowedTypes)) {
2023-11-23 15:05:40 +01:00
throw new InvalidArgumentException('invalid definition file type');
}
$this->definitionFiles[$type][md5($definitionFile)] = $definitionFile;
}
2023-11-23 15:01:44 +01:00
/**
* @param string $definitionFile
*
* @return void
*/
public function addYamlDefinitions(string $definitionFile): void
{
$this->addDefinitions($definitionFile, self::TYPE_YAML);
}
2023-11-23 15:01:44 +01:00
/**
* @param string $type
*
* @return array
*/
public function getDefinitions(string $type): array
{
if (!in_array($type, $this->allowedTypes)) {
2023-11-23 15:05:40 +01:00
throw new InvalidArgumentException('invalid definition file type');
}
return $this->definitionFiles[$type];
}
2023-11-23 15:01:44 +01:00
/**
* @return array
*/
public function getYamlDefinitions(): array
{
return $this->getDefinitions(self::TYPE_YAML);
}
/**
* @param string $definitionFile
* @return bool
*/
2023-11-23 15:01:44 +01:00
public function has(string $definitionFile): bool
{
return isset($this->definitionFiles[md5($definitionFile)]);
}
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 = [];
}
2023-11-23 15:05:40 +01:00
}