1 | <?php |
||
2 | |||
3 | declare(strict_types=1); |
||
4 | |||
5 | namespace Umbrellio\Postgres\Extensions; |
||
6 | |||
7 | use Illuminate\Support\Traits\Macroable; |
||
8 | use Umbrellio\Postgres\Extensions\Exceptions\MacroableMissedException; |
||
9 | use Umbrellio\Postgres\Extensions\Exceptions\MixinInvalidException; |
||
10 | |||
11 | /** |
||
12 | * @codeCoverageIgnore |
||
13 | */ |
||
14 | abstract class AbstractExtension extends AbstractComponent |
||
15 | { |
||
16 | abstract public static function getMixins(): array; |
||
17 | |||
18 | abstract public static function getName(): string; |
||
19 | |||
20 | public static function getTypes(): array |
||
21 | { |
||
22 | return []; |
||
23 | } |
||
24 | |||
25 | final public static function register(): void |
||
26 | { |
||
27 | collect(static::getMixins())->each(static function ($extension, $mixin) { |
||
0 ignored issues
–
show
Bug
introduced
by
![]() |
|||
28 | if (! is_subclass_of($mixin, AbstractComponent::class)) { |
||
29 | throw new MixinInvalidException(sprintf( |
||
30 | 'Mixed class %s is not descendant of %s.', |
||
31 | $mixin, |
||
32 | AbstractComponent::class |
||
33 | )); |
||
34 | } |
||
35 | if (! method_exists($extension, 'mixin')) { |
||
36 | throw new MacroableMissedException(sprintf('Class %s doesn’t use Macroable Trait.', $extension)); |
||
37 | } |
||
38 | /** @var Macroable $extension */ |
||
39 | $extension::mixin(new $mixin()); |
||
40 | }); |
||
41 | } |
||
42 | } |
||
43 |