- Change Traefik local HTTP port from 8080 to 8081 (conflict with cadvisor) - Change Traefik dashboard port to 8093 (conflicts with cadvisor, Hyperion) - Update Gitea SSH service IP from 172.23.0.2 to 172.23.0.3 - Note: Gitea SSH works directly via Docker port mapping in local dev - Traefik TCP routing only needed for production (host network mode)
117 lines
2.7 KiB
PHP
117 lines
2.7 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Framework\Reflection\Collections;
|
|
|
|
use App\Framework\Reflection\WrappedReflectionAttribute;
|
|
use ArrayIterator;
|
|
use Countable;
|
|
use IteratorAggregate;
|
|
|
|
/**
|
|
* @implements IteratorAggregate<int, WrappedReflectionAttribute>
|
|
*/
|
|
final readonly class AttributeCollection implements IteratorAggregate, Countable
|
|
{
|
|
/** @var WrappedReflectionAttribute[] */
|
|
private array $attributes;
|
|
|
|
public function __construct(WrappedReflectionAttribute ...$attributes)
|
|
{
|
|
$this->attributes = $attributes;
|
|
}
|
|
|
|
/**
|
|
* @return ArrayIterator<int, WrappedReflectionAttribute>
|
|
*/
|
|
public function getIterator(): ArrayIterator
|
|
{
|
|
return new ArrayIterator(array_values($this->attributes));
|
|
}
|
|
|
|
public function count(): int
|
|
{
|
|
return count($this->attributes);
|
|
}
|
|
|
|
public function isEmpty(): bool
|
|
{
|
|
return empty($this->attributes);
|
|
}
|
|
|
|
/**
|
|
* @return array<WrappedReflectionAttribute>
|
|
*/
|
|
public function toArray(): array
|
|
{
|
|
return $this->attributes;
|
|
}
|
|
|
|
/**
|
|
* @return array<object|null>
|
|
*/
|
|
public function getInstances(): array
|
|
{
|
|
return array_map(fn (WrappedReflectionAttribute $attr) => $attr->newInstance(), $this->attributes);
|
|
}
|
|
|
|
public function getFirstInstance(): ?object
|
|
{
|
|
$instances = $this->getInstances();
|
|
|
|
return $instances[0] ?? null;
|
|
}
|
|
|
|
public function getByType(string $attributeClass): self
|
|
{
|
|
$filtered = [];
|
|
foreach ($this->attributes as $attribute) {
|
|
if ($attribute->getName() === $attributeClass) {
|
|
$filtered[] = $attribute;
|
|
}
|
|
}
|
|
|
|
return new self(...$filtered);
|
|
}
|
|
|
|
public function hasType(string $attributeClass): bool
|
|
{
|
|
return ! $this->getByType($attributeClass)->isEmpty();
|
|
}
|
|
|
|
public function getFirstByType(string $attributeClass): ?WrappedReflectionAttribute
|
|
{
|
|
foreach ($this->attributes as $attribute) {
|
|
if ($attribute->getName() === $attributeClass) {
|
|
return $attribute;
|
|
}
|
|
}
|
|
|
|
return null;
|
|
}
|
|
|
|
public function getFirstInstanceByType(string $attributeClass): ?object
|
|
{
|
|
$attribute = $this->getFirstByType($attributeClass);
|
|
|
|
return $attribute?->newInstance();
|
|
}
|
|
|
|
/**
|
|
* @return array<string>
|
|
*/
|
|
public function getNames(): array
|
|
{
|
|
return array_map(fn (WrappedReflectionAttribute $attr) => $attr->getName(), $this->attributes);
|
|
}
|
|
|
|
/**
|
|
* @return array<string>
|
|
*/
|
|
public function getUniqueNames(): array
|
|
{
|
|
return array_unique($this->getNames());
|
|
}
|
|
}
|