2024-02-09 23:30:47 +00:00
|
|
|
<?php
|
|
|
|
|
namespace Targets\TargetDescriptionFiles;
|
|
|
|
|
|
2024-10-12 16:25:11 +01:00
|
|
|
require_once __DIR__ . "/PropertyGroup.php";
|
|
|
|
|
|
2024-02-09 23:30:47 +00:00
|
|
|
class Variant
|
|
|
|
|
{
|
2024-08-13 22:17:49 +01:00
|
|
|
public ?string $key = null;
|
2024-02-09 23:30:47 +00:00
|
|
|
public ?string $name = null;
|
|
|
|
|
public ?string $pinoutKey = null;
|
|
|
|
|
|
2024-10-12 16:25:11 +01:00
|
|
|
/** @var PropertyGroup[] */
|
|
|
|
|
public array $propertyGroups = [];
|
|
|
|
|
|
|
|
|
|
public function __construct(?string $key, ?string $name, ?string $pinoutKey, array $propertyGroups)
|
2024-02-09 23:30:47 +00:00
|
|
|
{
|
2024-08-13 22:17:49 +01:00
|
|
|
$this->key = $key;
|
2024-02-09 23:30:47 +00:00
|
|
|
$this->name = $name;
|
|
|
|
|
$this->pinoutKey = $pinoutKey;
|
2024-10-12 16:25:11 +01:00
|
|
|
$this->propertyGroups = $propertyGroups;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function getPropertyGroup(array|string $keys): ?PropertyGroup
|
|
|
|
|
{
|
|
|
|
|
if (is_string($keys)) {
|
|
|
|
|
$keys = explode('.', $keys);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$firstLevelGroupKey = array_shift($keys);
|
|
|
|
|
foreach ($this->propertyGroups as $propertyGroup) {
|
|
|
|
|
if ($propertyGroup->key === $firstLevelGroupKey) {
|
|
|
|
|
return !empty($keys) ? $propertyGroup->getSubgroup($keys) : $propertyGroup;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function getProperty(array|string $propertyGroupKeys, $propertyKey): ?Property
|
|
|
|
|
{
|
|
|
|
|
return ($propertyGroup = $this->getPropertyGroup($propertyGroupKeys)) instanceof PropertyGroup
|
|
|
|
|
? $propertyGroup->getProperty($propertyKey)
|
|
|
|
|
: null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function getPropertyValue(array|string $propertyGroupKeys, $propertyKey): ?string
|
|
|
|
|
{
|
|
|
|
|
return ($property = $this->getProperty($propertyGroupKeys, $propertyKey)) instanceof Property
|
|
|
|
|
? $property->value
|
|
|
|
|
: null;
|
2024-02-09 23:30:47 +00:00
|
|
|
}
|
|
|
|
|
}
|