|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +namespace SpeedPuzzling\Web\Doctrine; |
| 6 | + |
| 7 | +use Doctrine\DBAL\Schema\AbstractAsset; |
| 8 | +use Doctrine\DBAL\Schema\NamedObject; |
| 9 | +use Doctrine\DBAL\Schema\OptionallyNamedObject; |
| 10 | + |
| 11 | +use function preg_match; |
| 12 | + |
| 13 | +/** |
| 14 | + * Custom implementation of RegexSchemaAssetFilter that uses the new DBAL API |
| 15 | + * instead of the deprecated getName() method. |
| 16 | + * |
| 17 | + * This replaces Doctrine\Bundle\DoctrineBundle\Dbal\RegexSchemaAssetFilter |
| 18 | + * to avoid deprecation warnings. |
| 19 | + */ |
| 20 | +final readonly class RegexSchemaAssetFilter |
| 21 | +{ |
| 22 | + public function __construct( |
| 23 | + private string $filterExpression, |
| 24 | + ) { |
| 25 | + } |
| 26 | + |
| 27 | + /** @phpstan-ignore missingType.generics, parameter.internalClass */ |
| 28 | + public function __invoke(string|AbstractAsset $assetName): bool |
| 29 | + { |
| 30 | + if ($assetName instanceof AbstractAsset) { // @phpstan-ignore instanceof.internalClass |
| 31 | + if ($assetName instanceof NamedObject) { |
| 32 | + $assetName = $assetName->getObjectName()->toString(); |
| 33 | + } elseif ($assetName instanceof OptionallyNamedObject) { |
| 34 | + $name = $assetName->getObjectName(); |
| 35 | + $assetName = $name?->toString() ?? ''; |
| 36 | + } else { |
| 37 | + // Fallback for any other case - use deprecated method as last resort |
| 38 | + $assetName = $assetName->getName(); // @phpstan-ignore method.internalClass |
| 39 | + } |
| 40 | + } |
| 41 | + |
| 42 | + return (bool) preg_match($this->filterExpression, $assetName); |
| 43 | + } |
| 44 | +} |
0 commit comments