28 lines
681 B
PHP
28 lines
681 B
PHP
<?php
|
|
|
|
namespace App\Framework\DI;
|
|
|
|
use App\Framework\Attributes\Singleton;
|
|
use App\Framework\Reflection\ReflectionProvider;
|
|
|
|
/**
|
|
* Erkennt ob eine Klasse als Singleton markiert ist
|
|
*/
|
|
final readonly class SingletonDetector
|
|
{
|
|
public function __construct(
|
|
private ReflectionProvider $reflectionProvider,
|
|
private InstanceRegistry $instanceRegistry
|
|
) {}
|
|
|
|
public function isSingleton(string $class): bool
|
|
{
|
|
if ($this->instanceRegistry->hasSingleton($class)) {
|
|
return true;
|
|
}
|
|
|
|
$reflection = $this->reflectionProvider->getClass($class);
|
|
return count($reflection->getAttributes(Singleton::class)) > 0;
|
|
}
|
|
}
|