diff --git a/CHANGELOG.md b/CHANGELOG.md index c5a6aca8..5e0408af 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - An `AssetEnqueuer` destroyed after its application, as in a test, no longer throws while it reports a failure of its deferred enqueue - The typed meta classes that will leave for `pollora/meta` no longer reach for Laravel: `MetaUiDrivers` and `MetaAccessor::extend()` take a PSR-11 `ContainerInterface` (the Laravel container is one, a driver closure receives the same object), and the key of a data object's property is derived by `Pollora\Attributes\Support\Naming` instead of `Str::snake()`. What needs Laravel moved to `Pollora\Meta\Infrastructure\Laravel`: `MetaServiceProvider`, `LaravelMetaValidator`, `TypedMetaCheck`, `MetaListCommand` and `MetaAuditCommand`. The rendered pages, the REST responses and the output of the `pollora:meta:*`, `pollora:binding:list`, `pollora:roles:*` and `pollora:doctor` commands of a Pollora site are unchanged - The roles classes that will leave for `pollora/roles` no longer reach for Laravel: the label of a `#[Role]` without one comes from `Naming::headline()` (the same words as `Str::headline()`) and `Naming::classBasename()`. What needs Laravel moved to `Pollora\Role\Infrastructure\Laravel`: `RoleServiceProvider`, the `role` middleware `EnsureUserHasRole`, the `@role` directive `RoleDirective`, the `RolesCheck` of `pollora:doctor` and the `pollora:roles:*` and `pollora:make:role` commands with their stubs. Roles, capabilities and command outputs of a Pollora site are unchanged +- The Block Bindings classes that will leave for `pollora/block-bindings` no longer reach for Laravel: the resolver takes a PSR-11 container, and three contracts carry what Laravel did for it, `MethodInvokerInterface` (the method of a `#[BlockBinding]` source gets the services its typed parameters name; `LaravelMethodInvoker` calls through Laravel's container, `ReflectionMethodInvoker` by reflection) `BindingEventsInterface` (`BindingResolved` reaches Laravel's dispatcher through `LaravelBindingEvents`) and `PostFinderInterface` (`BindingContext::post()` loads the framework's `Pollora\Models\Post` through `LaravelPostFinder`, Colt's `Post` without it, and is typed as Colt's `Post`, which the framework's extends). The options a project lists in `block-bindings.options` reach `OptionSource` and the editor data as an array, read from the config by the provider. Labels and names come from `Naming`, as `Str` writes them. What needs Laravel moved to `Pollora\BlockBinding\Infrastructure\Laravel`: the provider, the doctor check, `pollora:binding:list` and `pollora:make:binding` with their stub. Pages, REST responses and command outputs of a Pollora site are unchanged ## [v13.36.0](https://github.com/Pollora/framework/compare/v13.35.6...v13.36.0) - 2026-10-14 diff --git a/src/BlockBinding/Application/Services/BindingResolver.php b/src/BlockBinding/Application/Services/BindingResolver.php index 021ef28a..7c99af7e 100644 --- a/src/BlockBinding/Application/Services/BindingResolver.php +++ b/src/BlockBinding/Application/Services/BindingResolver.php @@ -4,16 +4,19 @@ namespace Pollora\BlockBinding\Application\Services; -use Illuminate\Contracts\Container\Container; -use Illuminate\Contracts\Support\Htmlable; +use Pollora\BlockBinding\Domain\Contracts\BindingEventsInterface; use Pollora\BlockBinding\Domain\Contracts\ContentVisibilityInterface; +use Pollora\BlockBinding\Domain\Contracts\MethodInvokerInterface; +use Pollora\BlockBinding\Domain\Contracts\PostFinderInterface; use Pollora\BlockBinding\Domain\Contracts\ValuePresenterInterface; use Pollora\BlockBinding\Domain\Enums\BindingFieldType; use Pollora\BlockBinding\Domain\Events\BindingResolved; use Pollora\BlockBinding\Domain\Models\BindingContext; use Pollora\BlockBinding\Domain\Models\BindingFieldDefinition; use Pollora\BlockBinding\Domain\Models\BindingSource; +use Pollora\BlockBinding\Infrastructure\Adapters\ReflectionMethodInvoker; use Pollora\Meta\Application\Services\MetaAccessor; +use Psr\Container\ContainerInterface; use Psr\Log\LoggerInterface; use Stringable; use Throwable; @@ -54,14 +57,21 @@ final class BindingResolver */ private array $instances = []; + private readonly MethodInvokerInterface $invoker; + public function __construct( - private readonly Container $container, + private readonly ContainerInterface $container, private readonly ContentVisibilityInterface $visibility, private readonly ValuePresenterInterface $presenter, private readonly ?MetaAccessor $metaAccessor = null, private readonly bool $debug = false, private readonly ?LoggerInterface $logger = null, - ) {} + ?MethodInvokerInterface $invoker = null, + private readonly ?BindingEventsInterface $events = null, + private readonly ?PostFinderInterface $posts = null, + ) { + $this->invoker = $invoker ?? new ReflectionMethodInvoker($container); + } /** * The value of a bound attribute, or null to keep what the block holds. @@ -133,17 +143,11 @@ private function resolveIn(BindingSource $source, array $args, array $blockConte */ private function announce(BindingSource $source, BindingFieldDefinition $field, BindingContext $context, float $milliseconds, bool $cached, bool $hasValue): void { - if (! $this->container->bound('events')) { - return; - } - - $events = $this->container->make('events'); - - if (! $events->hasListeners(BindingResolved::class)) { + if (! $this->events instanceof BindingEventsInterface || ! $this->events->isListening()) { return; } - $events->dispatch(new BindingResolved( + $this->events->dispatch(new BindingResolved( source: $source->name, field: $field->name, attribute: $context->attribute, @@ -169,6 +173,7 @@ private function context(array $args, array $blockContext, ?\WP_Block $block, st taxonomy: is_string($blockContext['taxonomy'] ?? null) ? $blockContext['taxonomy'] : null, block: $block, metaAccessor: $this->metaAccessor, + postFinder: $this->posts, ); } @@ -184,14 +189,14 @@ private function isVisible(BindingContext $context): bool private function call(BindingSource $source, BindingFieldDefinition $field, BindingContext $context): mixed { try { - $instance = $this->instances[$source->class] ??= $this->container->make($source->class); + $instance = $this->instances[$source->class] ??= $this->container->get($source->class); if (! $this->debug) { - return $this->container->call([$instance, $field->method], [BindingContext::class => $context, 'context' => $context]); + return $this->invoker->call($instance, $field->method, [BindingContext::class => $context, 'context' => $context]); } $start = hrtime(true); - $value = $this->container->call([$instance, $field->method], [BindingContext::class => $context, 'context' => $context]); + $value = $this->invoker->call($instance, $field->method, [BindingContext::class => $context, 'context' => $context]); $this->reportSlow($source, $field, $context, (hrtime(true) - $start) / 1_000_000); return $value; @@ -239,8 +244,8 @@ private function present(mixed $value, BindingFieldType $type, ?string $attribut $inHtml = in_array($attributeSource, self::HTML_SOURCES, true); - if ($value instanceof Htmlable) { - return $this->presenter->richText($value->toHtml()); + if (is_object($value) && method_exists($value, 'toHtml')) { + return $this->presenter->richText((string) $value->toHtml()); } if (is_bool($value)) { diff --git a/src/BlockBinding/Application/Services/BindingSourceBuilder.php b/src/BlockBinding/Application/Services/BindingSourceBuilder.php index d4968d66..94472f40 100644 --- a/src/BlockBinding/Application/Services/BindingSourceBuilder.php +++ b/src/BlockBinding/Application/Services/BindingSourceBuilder.php @@ -4,9 +4,9 @@ namespace Pollora\BlockBinding\Application\Services; -use Illuminate\Support\Str; use Pollora\Attributes\BlockBinding; use Pollora\Attributes\BlockBinding\BindingField; +use Pollora\Attributes\Support\Naming; use Pollora\BlockBinding\Domain\Enums\BindingFieldType; use Pollora\BlockBinding\Domain\Exceptions\InvalidBindingSourceException; use Pollora\BlockBinding\Domain\Models\BindingFieldDefinition; @@ -75,7 +75,7 @@ public function build(string $class): BindingSource return new BindingSource( name: $attribute->name, - label: $attribute->label ?? Str::headline($reflection->getShortName()), + label: $attribute->label ?? Naming::headline($reflection->getShortName()), class: $class, usesContext: $attribute->usesContext, postTypes: $attribute->postTypes, @@ -105,7 +105,7 @@ private function buildFields(ReflectionClass $reflection): array $this->assertReturnType($class, $method); - $name = $attribute->name ?? Str::snake($method->getName()); + $name = $attribute->name ?? Naming::snake($method->getName()); if (isset($fields[$name])) { throw InvalidBindingSourceException::forField($class, $method->getName(), sprintf( @@ -126,7 +126,7 @@ private function buildFields(ReflectionClass $reflection): array $fields[$name] = new BindingFieldDefinition( name: $name, - label: $attribute->label ?? Str::headline($method->getName()), + label: $attribute->label ?? Naming::headline($method->getName()), type: $type, method: $method->getName(), ); diff --git a/src/BlockBinding/Domain/Contracts/BindingEventsInterface.php b/src/BlockBinding/Domain/Contracts/BindingEventsInterface.php new file mode 100644 index 00000000..de2bc567 --- /dev/null +++ b/src/BlockBinding/Domain/Contracts/BindingEventsInterface.php @@ -0,0 +1,21 @@ + $parameters Values given by parameter name or by class name + */ + public function call(object $instance, string $method, array $parameters): mixed; +} diff --git a/src/BlockBinding/Domain/Contracts/PostFinderInterface.php b/src/BlockBinding/Domain/Contracts/PostFinderInterface.php new file mode 100644 index 00000000..21292293 --- /dev/null +++ b/src/BlockBinding/Domain/Contracts/PostFinderInterface.php @@ -0,0 +1,18 @@ +post ??= $this->postId === null ? false : (Post::query()->find($this->postId) ?? false); + $this->post ??= $this->postId === null ? false : (($this->postFinder instanceof PostFinderInterface ? $this->postFinder->find($this->postId) : Post::query()->find($this->postId)) ?? false); return $this->post ?: null; } @@ -84,7 +86,7 @@ private function objectIdFor(MetaObjectType $objectType): ?int private function authorId(): ?int { - $author = (int) $this->post()?->post_author; + $author = (int) $this->post()?->getAttribute('post_author'); return $author > 0 ? $author : null; } diff --git a/src/BlockBinding/Infrastructure/Adapters/ReflectionMethodInvoker.php b/src/BlockBinding/Infrastructure/Adapters/ReflectionMethodInvoker.php new file mode 100644 index 00000000..6f121ecd --- /dev/null +++ b/src/BlockBinding/Infrastructure/Adapters/ReflectionMethodInvoker.php @@ -0,0 +1,68 @@ +getParameters() as $parameter) { + $type = $parameter->getType(); + $class = $type instanceof ReflectionNamedType && ! $type->isBuiltin() ? $type->getName() : null; + + $arguments[] = match (true) { + array_key_exists($parameter->getName(), $parameters) => $parameters[$parameter->getName()], + $class !== null && array_key_exists($class, $parameters) => $parameters[$class], + $class !== null && ($service = $this->service($class)) !== null => $service, + $parameter->isDefaultValueAvailable() => $parameter->getDefaultValue(), + $type?->allowsNull() === true => null, + default => throw new InvalidArgumentException(sprintf('Unable to resolve the parameter $%s of %s::%s().', $parameter->getName(), $instance::class, $method)), + }; + } + + return $reflection->invokeArgs($instance, $arguments); + } + + /** + * A service the container gives, or an instance of a class that needs + * nothing to be built. + */ + private function service(string $class): ?object + { + if ($this->container?->has($class) === true) { + return $this->container->get($class); + } + + try { + return $this->container?->get($class); + } catch (ContainerExceptionInterface) { + // not a service of this container: a class with no required argument is built below + } + + $constructor = class_exists($class) ? (new ReflectionClass($class))->getConstructor() : null; + + return class_exists($class) && ($constructor === null || $constructor->getNumberOfRequiredParameters() === 0) ? new $class : null; + } +} diff --git a/src/BlockBinding/Infrastructure/Providers/BlockBindingServiceProvider.php b/src/BlockBinding/Infrastructure/Laravel/BlockBindingServiceProvider.php similarity index 83% rename from src/BlockBinding/Infrastructure/Providers/BlockBindingServiceProvider.php rename to src/BlockBinding/Infrastructure/Laravel/BlockBindingServiceProvider.php index fe8b3330..219a9482 100644 --- a/src/BlockBinding/Infrastructure/Providers/BlockBindingServiceProvider.php +++ b/src/BlockBinding/Infrastructure/Laravel/BlockBindingServiceProvider.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace Pollora\BlockBinding\Infrastructure\Providers; +namespace Pollora\BlockBinding\Infrastructure\Laravel; use Illuminate\Contracts\Foundation\Application; use Illuminate\Support\ServiceProvider; @@ -16,7 +16,8 @@ use Pollora\BlockBinding\Infrastructure\Adapters\WordPressBindingRegistry; use Pollora\BlockBinding\Infrastructure\Adapters\WordPressContentVisibility; use Pollora\BlockBinding\Infrastructure\Adapters\WordPressValuePresenter; -use Pollora\BlockBinding\Infrastructure\Checks\BlockBindingsCheck; +use Pollora\BlockBinding\Infrastructure\Laravel\Console\BindingListCommand; +use Pollora\BlockBinding\Infrastructure\Laravel\Console\MakeBindingCommand; use Pollora\BlockBinding\Infrastructure\Services\BindingEditorData; use Pollora\BlockBinding\Infrastructure\Services\BindingFormatter; use Pollora\BlockBinding\Infrastructure\Services\BlockBindingDiscovery; @@ -25,8 +26,6 @@ use Pollora\BlockBinding\Infrastructure\Sources\PostMetaSource; use Pollora\BlockBinding\Infrastructure\Sources\TermMetaSource; use Pollora\BlockBinding\Infrastructure\Sources\TypedMetaReader; -use Pollora\BlockBinding\UI\Console\BindingListCommand; -use Pollora\BlockBinding\UI\Console\MakeBindingCommand; use Pollora\BlockBinding\UI\Http\ResolveBindingsController; use Pollora\Doctor\Infrastructure\Providers\DoctorServiceProvider; use Pollora\Hook\Domain\Contract\Action; @@ -63,14 +62,19 @@ public function register(): void $this->app->singleton(ValuePresenterInterface::class, WordPressValuePresenter::class); $this->app->singleton(BindingFormatter::class); $this->app->singleton(TypedMetaReader::class); - $this->app->singleton(BindingEditorData::class); + $this->app->singleton(BindingEditorData::class, fn (Application $app): BindingEditorData => new BindingEditorData( + $app->make(BindingSourceRegistry::class), + $app->make(MetaSchemaRepository::class), + $this->options(), + )); + $this->app->singleton(OptionSource::class, fn (): OptionSource => new OptionSource($this->options())); $this->app->singleton(WordPressBindingEditorScript::class); $this->app->singleton(ResolveBindingsController::class); $this->app->singleton(BindingReferenceInspector::class, fn (Application $app): BindingReferenceInspector => new BindingReferenceInspector( $app->make(BindingSourceRegistry::class), $app->make(MetaSchemaRepository::class), - array_values(array_filter((array) $app->make('config')->get('block-bindings.options', []), is_string(...))), + $this->options(), )); $this->app->singleton(BindingResolver::class, fn (Application $app): BindingResolver => new BindingResolver( @@ -80,6 +84,9 @@ public function register(): void $app->make(MetaAccessor::class), (bool) $app->make('config')->get('app.debug', false), $app->make(LoggerInterface::class), + $app->make(LaravelMethodInvoker::class), + $app->make(LaravelBindingEvents::class), + $app->make(LaravelPostFinder::class), )); $this->app->singleton(WordPressBindingRegistry::class, fn (Application $app): WordPressBindingRegistry => new WordPressBindingRegistry( @@ -118,4 +125,14 @@ public function boot(): void $action->add('enqueue_block_editor_assets', fn () => $this->app->make(WordPressBindingEditorScript::class)->enqueue()); $action->add('rest_api_init', fn () => $this->app->make(ResolveBindingsController::class)->register()); } + + /** + * The options a project lists as bindable. + * + * @return list + */ + private function options(): array + { + return array_values(array_filter((array) $this->app->make('config')->get('block-bindings.options', []), is_string(...))); + } } diff --git a/src/BlockBinding/Infrastructure/Checks/BlockBindingsCheck.php b/src/BlockBinding/Infrastructure/Laravel/BlockBindingsCheck.php similarity index 99% rename from src/BlockBinding/Infrastructure/Checks/BlockBindingsCheck.php rename to src/BlockBinding/Infrastructure/Laravel/BlockBindingsCheck.php index fabb888c..14809b46 100644 --- a/src/BlockBinding/Infrastructure/Checks/BlockBindingsCheck.php +++ b/src/BlockBinding/Infrastructure/Laravel/BlockBindingsCheck.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace Pollora\BlockBinding\Infrastructure\Checks; +namespace Pollora\BlockBinding\Infrastructure\Laravel; use Pollora\BlockBinding\Application\Services\BindingReferenceInspector; use Pollora\Doctor\Domain\Contracts\CheckInterface; diff --git a/src/BlockBinding/UI/Console/BindingListCommand.php b/src/BlockBinding/Infrastructure/Laravel/Console/BindingListCommand.php similarity index 98% rename from src/BlockBinding/UI/Console/BindingListCommand.php rename to src/BlockBinding/Infrastructure/Laravel/Console/BindingListCommand.php index e2fa84f0..76641406 100644 --- a/src/BlockBinding/UI/Console/BindingListCommand.php +++ b/src/BlockBinding/Infrastructure/Laravel/Console/BindingListCommand.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace Pollora\BlockBinding\UI\Console; +namespace Pollora\BlockBinding\Infrastructure\Laravel\Console; use Illuminate\Console\Attributes\Description; use Illuminate\Console\Attributes\Signature; diff --git a/src/BlockBinding/UI/Console/MakeBindingCommand.php b/src/BlockBinding/Infrastructure/Laravel/Console/MakeBindingCommand.php similarity index 96% rename from src/BlockBinding/UI/Console/MakeBindingCommand.php rename to src/BlockBinding/Infrastructure/Laravel/Console/MakeBindingCommand.php index 50030145..3b9c5308 100644 --- a/src/BlockBinding/UI/Console/MakeBindingCommand.php +++ b/src/BlockBinding/Infrastructure/Laravel/Console/MakeBindingCommand.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace Pollora\BlockBinding\UI\Console; +namespace Pollora\BlockBinding\Infrastructure\Laravel\Console; use Illuminate\Console\Attributes\Description; use Illuminate\Support\Str; diff --git a/src/BlockBinding/UI/Console/stubs/binding.stub b/src/BlockBinding/Infrastructure/Laravel/Console/stubs/binding.stub similarity index 100% rename from src/BlockBinding/UI/Console/stubs/binding.stub rename to src/BlockBinding/Infrastructure/Laravel/Console/stubs/binding.stub diff --git a/src/BlockBinding/Infrastructure/Laravel/LaravelBindingEvents.php b/src/BlockBinding/Infrastructure/Laravel/LaravelBindingEvents.php new file mode 100644 index 00000000..0d6dc47a --- /dev/null +++ b/src/BlockBinding/Infrastructure/Laravel/LaravelBindingEvents.php @@ -0,0 +1,28 @@ +container->bound('events') && $this->container->make('events')->hasListeners(BindingResolved::class); + } + + public function dispatch(BindingResolved $event): void + { + $this->container->make('events')->dispatch($event); + } +} diff --git a/src/BlockBinding/Infrastructure/Laravel/LaravelMethodInvoker.php b/src/BlockBinding/Infrastructure/Laravel/LaravelMethodInvoker.php new file mode 100644 index 00000000..c609f446 --- /dev/null +++ b/src/BlockBinding/Infrastructure/Laravel/LaravelMethodInvoker.php @@ -0,0 +1,22 @@ +container->call([$instance, $method], $parameters); + } +} diff --git a/src/BlockBinding/Infrastructure/Laravel/LaravelPostFinder.php b/src/BlockBinding/Infrastructure/Laravel/LaravelPostFinder.php new file mode 100644 index 00000000..34991c65 --- /dev/null +++ b/src/BlockBinding/Infrastructure/Laravel/LaravelPostFinder.php @@ -0,0 +1,22 @@ +find($postId); + + return $post; + } +} diff --git a/src/BlockBinding/Infrastructure/Services/BindingEditorData.php b/src/BlockBinding/Infrastructure/Services/BindingEditorData.php index 485cb1d5..b8036b0d 100644 --- a/src/BlockBinding/Infrastructure/Services/BindingEditorData.php +++ b/src/BlockBinding/Infrastructure/Services/BindingEditorData.php @@ -4,8 +4,7 @@ namespace Pollora\BlockBinding\Infrastructure\Services; -use Illuminate\Contracts\Config\Repository; -use Illuminate\Support\Str; +use Pollora\Attributes\Support\Naming; use Pollora\BlockBinding\Application\Services\BindingSourceRegistry; use Pollora\BlockBinding\Domain\Models\BindingSource; use Pollora\BlockBinding\Infrastructure\Sources\TypedMetaReader; @@ -28,10 +27,13 @@ public const string REST_ROUTE = '/block-bindings/resolve'; + /** + * @param list $options The options a project lists as bindable (`block-bindings.options`) + */ public function __construct( private BindingSourceRegistry $sources, private MetaSchemaRepository $schemas, - private Repository $config, + private array $options, ) {} /** @@ -88,7 +90,7 @@ private function metaFields(MetaObjectType $objectType, \Closure $readable): arr continue; } - $label = $definition->label ?? Str::headline($definition->property); + $label = $definition->label ?? Naming::headline($definition->property); foreach ($schema->subtypes === [] ? [''] : $schema->subtypes as $subtype) { $fields[$subtype][] = ['label' => $label, 'args' => ['key' => $definition->key], 'type' => 'string']; @@ -110,9 +112,9 @@ private function optionFields(): array { $fields = []; - foreach ((array) $this->config->get('block-bindings.options', []) as $name) { + foreach ($this->options as $name) { if (is_string($name)) { - $fields[] = ['label' => Str::headline($name), 'args' => ['name' => $name], 'type' => 'string']; + $fields[] = ['label' => Naming::headline($name), 'args' => ['name' => $name], 'type' => 'string']; } } diff --git a/src/BlockBinding/Infrastructure/Sources/OptionSource.php b/src/BlockBinding/Infrastructure/Sources/OptionSource.php index ac93e81a..40b1e391 100644 --- a/src/BlockBinding/Infrastructure/Sources/OptionSource.php +++ b/src/BlockBinding/Infrastructure/Sources/OptionSource.php @@ -4,7 +4,6 @@ namespace Pollora\BlockBinding\Infrastructure\Sources; -use Illuminate\Contracts\Config\Repository; use Pollora\Attributes\BlockBinding; use Pollora\BlockBinding\Domain\Models\BindingContext; @@ -17,8 +16,11 @@ #[BlockBinding('pollora/option', label: 'Site option (Pollora)', usesContext: [])] final readonly class OptionSource { + /** + * @param list $options The options a project lists as bindable (`block-bindings.options`) + */ public function __construct( - private Repository $config, + private array $options, ) {} public function __invoke(BindingContext $context): ?string @@ -27,7 +29,7 @@ public function __invoke(BindingContext $context): ?string $fallback = $context->arg('fallback'); $fallback = is_scalar($fallback) ? (string) $fallback : null; - if (! is_string($name) || ! in_array($name, (array) $this->config->get('block-bindings.options', []), true)) { + if (! is_string($name) || ! in_array($name, $this->options, true)) { return null; } diff --git a/src/Providers/PolloraServiceProvider.php b/src/Providers/PolloraServiceProvider.php index 70120f93..7c355907 100755 --- a/src/Providers/PolloraServiceProvider.php +++ b/src/Providers/PolloraServiceProvider.php @@ -12,7 +12,7 @@ use Pollora\Asset\Infrastructure\Providers\AssetServiceProvider; use Pollora\Auth\AuthServiceProvider; use Pollora\Block\Infrastructure\Providers\BlockServiceProvider; -use Pollora\BlockBinding\Infrastructure\Providers\BlockBindingServiceProvider; +use Pollora\BlockBinding\Infrastructure\Laravel\BlockBindingServiceProvider; use Pollora\Collection\Infrastructure\Providers\CollectionServiceProvider; use Pollora\Config\Infrastructure\Providers\ConfigServiceProvider; use Pollora\Dashboard\Infrastructure\Providers\DashboardServiceProvider; diff --git a/tests/Feature/Extraction/BlockBindingsContractTest.php b/tests/Feature/Extraction/BlockBindingsContractTest.php index 962d970c..769d4c2c 100644 --- a/tests/Feature/Extraction/BlockBindingsContractTest.php +++ b/tests/Feature/Extraction/BlockBindingsContractTest.php @@ -13,7 +13,7 @@ use Pollora\BlockBinding\Domain\Contracts\ContentVisibilityInterface; use Pollora\BlockBinding\Domain\Contracts\ValuePresenterInterface; use Pollora\BlockBinding\Domain\Models\BindingContext; -use Pollora\BlockBinding\Infrastructure\Providers\BlockBindingServiceProvider; +use Pollora\BlockBinding\Infrastructure\Laravel\BlockBindingServiceProvider; use Pollora\BlockBinding\Infrastructure\Services\BindingEditorData; use Pollora\BlockBinding\Infrastructure\Sources\OptionSource; use Pollora\Hook\Domain\Contract\Action; diff --git a/tests/Feature/Extraction/surface.json b/tests/Feature/Extraction/surface.json index f009580b..abfeb970 100644 --- a/tests/Feature/Extraction/surface.json +++ b/tests/Feature/Extraction/surface.json @@ -18,7 +18,7 @@ "SLOW_FIELD_MS": "const" }, "methods": { - "__construct": "public (Illuminate\\Contracts\\Container\\Container $container, Pollora\\BlockBinding\\Domain\\Contracts\\ContentVisibilityInterface $visibility, Pollora\\BlockBinding\\Domain\\Contracts\\ValuePresenterInterface $presenter, ?Pollora\\Meta\\Application\\Services\\MetaAccessor $metaAccessor = ?, bool $debug = ?, ?Psr\\Log\\LoggerInterface $logger = ?): mixed", + "__construct": "public (Psr\\Container\\ContainerInterface $container, Pollora\\BlockBinding\\Domain\\Contracts\\ContentVisibilityInterface $visibility, Pollora\\BlockBinding\\Domain\\Contracts\\ValuePresenterInterface $presenter, ?Pollora\\Meta\\Application\\Services\\MetaAccessor $metaAccessor = ?, bool $debug = ?, ?Psr\\Log\\LoggerInterface $logger = ?, ?Pollora\\BlockBinding\\Domain\\Contracts\\MethodInvokerInterface $invoker = ?, ?Pollora\\BlockBinding\\Domain\\Contracts\\BindingEventsInterface $events = ?, ?Pollora\\BlockBinding\\Domain\\Contracts\\PostFinderInterface $posts = ?): mixed", "preview": "public (Pollora\\BlockBinding\\Domain\\Models\\BindingSource $source, array $args, array $blockContext, string $attribute, ?string $attributeSource = ?): mixed", "resolve": "public (Pollora\\BlockBinding\\Domain\\Models\\BindingSource $source, array $args, ?WP_Block $block, string $attribute): mixed" } @@ -43,6 +43,16 @@ "find": "public (string $name): ?Pollora\\BlockBinding\\Domain\\Models\\BindingSource" } }, + "Pollora\\BlockBinding\\Domain\\Contracts\\BindingEventsInterface": { + "kind": "interface", + "extends": null, + "implements": [], + "constants": [], + "methods": { + "dispatch": "public abstract (Pollora\\BlockBinding\\Domain\\Events\\BindingResolved $event): void", + "isListening": "public abstract (): bool" + } + }, "Pollora\\BlockBinding\\Domain\\Contracts\\ContentVisibilityInterface": { "kind": "interface", "extends": null, @@ -53,6 +63,24 @@ "canShowTerm": "public abstract (int $termId, string $taxonomy): bool" } }, + "Pollora\\BlockBinding\\Domain\\Contracts\\MethodInvokerInterface": { + "kind": "interface", + "extends": null, + "implements": [], + "constants": [], + "methods": { + "call": "public abstract (object $instance, string $method, array $parameters): mixed" + } + }, + "Pollora\\BlockBinding\\Domain\\Contracts\\PostFinderInterface": { + "kind": "interface", + "extends": null, + "implements": [], + "constants": [], + "methods": { + "find": "public abstract (int $postId): ?Pollora\\Colt\\Model\\Post" + } + }, "Pollora\\BlockBinding\\Domain\\Contracts\\ValuePresenterInterface": { "kind": "interface", "extends": null, @@ -91,10 +119,10 @@ "implements": [], "constants": [], "methods": { - "__construct": "public (array $args = ?, string $attribute = ?, ?int $postId = ?, ?string $postType = ?, ?int $termId = ?, ?string $taxonomy = ?, ?WP_Block $block = ?, ?Pollora\\Meta\\Application\\Services\\MetaAccessor $metaAccessor = ?): mixed", + "__construct": "public (array $args = ?, string $attribute = ?, ?int $postId = ?, ?string $postType = ?, ?int $termId = ?, ?string $taxonomy = ?, ?WP_Block $block = ?, ?Pollora\\Meta\\Application\\Services\\MetaAccessor $metaAccessor = ?, ?Pollora\\BlockBinding\\Domain\\Contracts\\PostFinderInterface $postFinder = ?): mixed", "arg": "public (string $name, mixed $default = ?): mixed", "meta": "public (string $class): ?Pollora\\Meta\\Domain\\Models\\MetaRecord", - "post": "public (): ?Pollora\\Models\\Post" + "post": "public (): ?Pollora\\Colt\\Model\\Post" } }, "Pollora\\BlockBinding\\Domain\\Models\\BindingFieldDefinition": { @@ -118,6 +146,18 @@ "isInvokable": "public (): bool" } }, + "Pollora\\BlockBinding\\Infrastructure\\Adapters\\ReflectionMethodInvoker": { + "kind": "final readonly class", + "extends": null, + "implements": [ + "Pollora\\BlockBinding\\Domain\\Contracts\\MethodInvokerInterface" + ], + "constants": [], + "methods": { + "__construct": "public (?Psr\\Container\\ContainerInterface $container = ?): mixed", + "call": "public (object $instance, string $method, array $parameters): mixed" + } + }, "Pollora\\BlockBinding\\Infrastructure\\Adapters\\WordPressBindingEditorScript": { "kind": "final readonly class", "extends": null, @@ -166,7 +206,19 @@ "url": "public (string $value): string" } }, - "Pollora\\BlockBinding\\Infrastructure\\Checks\\BlockBindingsCheck": { + "Pollora\\BlockBinding\\Infrastructure\\Laravel\\BlockBindingServiceProvider": { + "kind": "class", + "extends": "Illuminate\\Support\\ServiceProvider", + "implements": [], + "constants": { + "SOURCES": "const" + }, + "methods": { + "boot": "public (): void", + "register": "public (): void" + } + }, + "Pollora\\BlockBinding\\Infrastructure\\Laravel\\BlockBindingsCheck": { "kind": "final readonly class", "extends": null, "implements": [ @@ -181,16 +233,61 @@ "runsIn": "public (): array" } }, - "Pollora\\BlockBinding\\Infrastructure\\Providers\\BlockBindingServiceProvider": { + "Pollora\\BlockBinding\\Infrastructure\\Laravel\\Console\\BindingListCommand": { "kind": "class", - "extends": "Illuminate\\Support\\ServiceProvider", + "extends": "Illuminate\\Console\\Command", "implements": [], - "constants": { - "SOURCES": "const" - }, + "constants": [], "methods": { - "boot": "public (): void", - "register": "public (): void" + "bindableBlocks": "protected (): ?array", + "handle": "public (Pollora\\BlockBinding\\Application\\Services\\BindingSourceRegistry $sources, Pollora\\BlockBinding\\Infrastructure\\Services\\BindingEditorData $editorData): int" + } + }, + "Pollora\\BlockBinding\\Infrastructure\\Laravel\\Console\\MakeBindingCommand": { + "kind": "class", + "extends": "Pollora\\Console\\AbstractGeneratorCommand", + "implements": [], + "constants": [], + "methods": { + "getArguments": "protected (): array", + "getStub": "protected (): string", + "replaceClass": "protected (mixed $stub, mixed $name): string" + } + }, + "Pollora\\BlockBinding\\Infrastructure\\Laravel\\LaravelBindingEvents": { + "kind": "final readonly class", + "extends": null, + "implements": [ + "Pollora\\BlockBinding\\Domain\\Contracts\\BindingEventsInterface" + ], + "constants": [], + "methods": { + "__construct": "public (Illuminate\\Contracts\\Container\\Container $container): mixed", + "dispatch": "public (Pollora\\BlockBinding\\Domain\\Events\\BindingResolved $event): void", + "isListening": "public (): bool" + } + }, + "Pollora\\BlockBinding\\Infrastructure\\Laravel\\LaravelMethodInvoker": { + "kind": "final readonly class", + "extends": null, + "implements": [ + "Pollora\\BlockBinding\\Domain\\Contracts\\MethodInvokerInterface" + ], + "constants": [], + "methods": { + "__construct": "public (Illuminate\\Contracts\\Container\\Container $container): mixed", + "call": "public (object $instance, string $method, array $parameters): mixed" + } + }, + "Pollora\\BlockBinding\\Infrastructure\\Laravel\\LaravelPostFinder": { + "kind": "final class", + "extends": null, + "implements": [ + "Pollora\\BlockBinding\\Domain\\Contracts\\PostFinderInterface" + ], + "constants": [], + "methods": { + "find": "public (int $postId): ?Pollora\\Models\\Post" } }, "Pollora\\BlockBinding\\Infrastructure\\Services\\BindingEditorData": { @@ -202,7 +299,7 @@ "REST_ROUTE": "const" }, "methods": { - "__construct": "public (Pollora\\BlockBinding\\Application\\Services\\BindingSourceRegistry $sources, Pollora\\Meta\\Application\\Services\\MetaSchemaRepository $schemas, Illuminate\\Contracts\\Config\\Repository $config): mixed", + "__construct": "public (Pollora\\BlockBinding\\Application\\Services\\BindingSourceRegistry $sources, Pollora\\Meta\\Application\\Services\\MetaSchemaRepository $schemas, array $options): mixed", "toArray": "public (): array" } }, @@ -248,7 +345,7 @@ "implements": [], "constants": [], "methods": { - "__construct": "public (Illuminate\\Contracts\\Config\\Repository $config): mixed", + "__construct": "public (array $options): mixed", "__invoke": "public (Pollora\\BlockBinding\\Domain\\Models\\BindingContext $context): ?string" } }, @@ -283,27 +380,6 @@ "read": "public (Pollora\\Meta\\Domain\\Enums\\MetaObjectType $objectType, ?string $subtype, int $objectId, string $key, Closure $readable): ?array" } }, - "Pollora\\BlockBinding\\UI\\Console\\BindingListCommand": { - "kind": "class", - "extends": "Illuminate\\Console\\Command", - "implements": [], - "constants": [], - "methods": { - "bindableBlocks": "protected (): ?array", - "handle": "public (Pollora\\BlockBinding\\Application\\Services\\BindingSourceRegistry $sources, Pollora\\BlockBinding\\Infrastructure\\Services\\BindingEditorData $editorData): int" - } - }, - "Pollora\\BlockBinding\\UI\\Console\\MakeBindingCommand": { - "kind": "class", - "extends": "Pollora\\Console\\AbstractGeneratorCommand", - "implements": [], - "constants": [], - "methods": { - "getArguments": "protected (): array", - "getStub": "protected (): string", - "replaceClass": "protected (mixed $stub, mixed $name): string" - } - }, "Pollora\\BlockBinding\\UI\\Http\\ResolveBindingsController": { "kind": "final readonly class", "extends": null, @@ -318,310 +394,6 @@ "register": "public (): void" } }, - "Pollora\\Meta\\Application\\Services\\MetaAccessor": { - "kind": "final readonly class", - "extends": null, - "implements": [], - "constants": [], - "methods": { - "__construct": "public (Pollora\\Meta\\Application\\Services\\MetaSchemaRepository $schemas, Pollora\\Meta\\Application\\Services\\MetaSchemaBuilder $builder, Pollora\\Meta\\Domain\\Contracts\\MetaStoreInterface $store, Pollora\\Meta\\Domain\\Services\\MetaValueCaster $caster, bool $debug = ?, ?Psr\\Log\\LoggerInterface $logger = ?, ?Pollora\\Meta\\Domain\\Contracts\\MetaValidatorInterface $validator = ?, ?Pollora\\Meta\\Application\\Services\\MetaUiDrivers $drivers = ?): mixed", - "extend": "public (string $name, Closure|string $driver): void", - "of": "public (string $class, int $objectId): Pollora\\Meta\\Domain\\Models\\MetaRecord", - "record": "public (Pollora\\Meta\\Domain\\Models\\MetaSchema $schema, int $objectId): Pollora\\Meta\\Domain\\Models\\MetaRecord", - "schema": "public (string $class): Pollora\\Meta\\Domain\\Models\\MetaSchema", - "schemaFor": "public (Pollora\\Meta\\Domain\\Enums\\MetaObjectType|string $objectType, ?string $subtype = ?): array", - "schemas": "public (): array" - } - }, - "Pollora\\Meta\\Application\\Services\\MetaAuditor": { - "kind": "final readonly class", - "extends": null, - "implements": [], - "constants": [], - "methods": { - "__construct": "public (Pollora\\Meta\\Application\\Services\\MetaSchemaRepository $schemas, Pollora\\Meta\\Domain\\Contracts\\MetaInventoryInterface $inventory, Pollora\\Meta\\Domain\\Services\\MetaValueCaster $caster): mixed", - "undeclared": "public (int $limit): array", - "unreadable": "public (int $limit): array" - } - }, - "Pollora\\Meta\\Application\\Services\\MetaSchemaBuilder": { - "kind": "final class", - "extends": null, - "implements": [], - "constants": [], - "methods": { - "build": "public (string $class): Pollora\\Meta\\Domain\\Models\\MetaSchema" - } - }, - "Pollora\\Meta\\Application\\Services\\MetaSchemaRepository": { - "kind": "final class", - "extends": null, - "implements": [], - "constants": [], - "methods": { - "add": "public (Pollora\\Meta\\Domain\\Models\\MetaSchema $schema): void", - "all": "public (): array", - "declares": "public (Pollora\\Meta\\Domain\\Enums\\MetaObjectType $objectType, string $propertyOrKey): bool", - "fail": "public (string $class, string $reason): void", - "failures": "public (): array", - "forClass": "public (string $class): ?Pollora\\Meta\\Domain\\Models\\MetaSchema", - "forObject": "public (Pollora\\Meta\\Domain\\Enums\\MetaObjectType $objectType, ?string $subtype): array" - } - }, - "Pollora\\Meta\\Application\\Services\\MetaUiDrivers": { - "kind": "final class", - "extends": null, - "implements": [], - "constants": [], - "methods": { - "__construct": "public (Psr\\Container\\ContainerInterface $container): mixed", - "build": "public (Pollora\\Meta\\Domain\\Contracts\\MetaUiDriver $driver, array $schemas): void", - "driver": "public (string $name): Pollora\\Meta\\Domain\\Contracts\\MetaUiDriver", - "extend": "public (string $name, Closure|string $driver): void", - "has": "public (string $name): bool" - } - }, - "Pollora\\Meta\\Domain\\Contracts\\MetaInventoryInterface": { - "kind": "interface", - "extends": null, - "implements": [], - "constants": [], - "methods": { - "keys": "public abstract (Pollora\\Meta\\Domain\\Enums\\MetaObjectType $objectType, array $subtypes, int $limit): array", - "values": "public abstract (Pollora\\Meta\\Domain\\Enums\\MetaObjectType $objectType, array $subtypes, string $key, int $limit): array" - } - }, - "Pollora\\Meta\\Domain\\Contracts\\MetaRegistryInterface": { - "kind": "interface", - "extends": null, - "implements": [], - "constants": [], - "methods": { - "register": "public abstract (Pollora\\Meta\\Domain\\Models\\MetaSchema $schema): void" - } - }, - "Pollora\\Meta\\Domain\\Contracts\\MetaStoreInterface": { - "kind": "interface", - "extends": null, - "implements": [], - "constants": [], - "methods": { - "delete": "public abstract (Pollora\\Meta\\Domain\\Enums\\MetaObjectType $objectType, int $objectId, string $key): void", - "get": "public abstract (Pollora\\Meta\\Domain\\Enums\\MetaObjectType $objectType, int $objectId, string $key): mixed", - "getAll": "public abstract (Pollora\\Meta\\Domain\\Enums\\MetaObjectType $objectType, int $objectId, string $key): array", - "replaceAll": "public abstract (Pollora\\Meta\\Domain\\Enums\\MetaObjectType $objectType, int $objectId, string $key, array $values): void", - "update": "public abstract (Pollora\\Meta\\Domain\\Enums\\MetaObjectType $objectType, int $objectId, string $key, array|string $value): void" - } - }, - "Pollora\\Meta\\Domain\\Contracts\\MetaUiDriver": { - "kind": "interface", - "extends": null, - "implements": [], - "constants": [], - "methods": { - "register": "public abstract (Pollora\\Meta\\Domain\\Models\\MetaSchema $schema): void", - "supports": "public abstract (Pollora\\Meta\\Domain\\Models\\MetaDefinition $definition): bool" - } - }, - "Pollora\\Meta\\Domain\\Contracts\\MetaValidatorInterface": { - "kind": "interface", - "extends": null, - "implements": [], - "constants": [], - "methods": { - "validate": "public abstract (Pollora\\Meta\\Domain\\Models\\MetaDefinition $definition, mixed $value): void" - } - }, - "Pollora\\Meta\\Domain\\Enums\\MetaObjectType": { - "kind": "enum", - "extends": null, - "implements": [ - "BackedEnum", - "UnitEnum" - ], - "constants": { - "Comment": "case", - "Post": "case", - "Term": "case", - "User": "case" - }, - "methods": { - "cases": "public static (): array", - "from": "public static (string|int $value): static", - "tryFrom": "public static (string|int $value): ?static" - } - }, - "Pollora\\Meta\\Domain\\Enums\\MetaValueType": { - "kind": "enum", - "extends": null, - "implements": [ - "UnitEnum" - ], - "constants": { - "ArrayOf": "case", - "Boolean": "case", - "DataObject": "case", - "DateTime": "case", - "Enum": "case", - "Integer": "case", - "Number": "case", - "String": "case" - }, - "methods": { - "cases": "public static (): array" - } - }, - "Pollora\\Meta\\Domain\\Events\\MetaSchemasRegistered": { - "kind": "final readonly class", - "extends": null, - "implements": [], - "constants": [], - "methods": { - "__construct": "public (array $schemas): mixed" - } - }, - "Pollora\\Meta\\Domain\\Exceptions\\InvalidMetaDefinitionException": { - "kind": "final class", - "extends": "LogicException", - "implements": [], - "constants": [], - "methods": { - "duplicateKey": "public static (string $key, string $owner, string $firstClass, string $secondClass): self", - "forProperty": "public static (string $class, string $property, string $reason): self", - "notADeclaration": "public static (string $class): self" - } - }, - "Pollora\\Meta\\Domain\\Exceptions\\InvalidMetaValueException": { - "kind": "final class", - "extends": "InvalidArgumentException", - "implements": [], - "constants": [], - "methods": { - "forRead": "public static (Pollora\\Meta\\Domain\\Models\\MetaDefinition $definition, mixed $raw): self", - "forWrite": "public static (Pollora\\Meta\\Domain\\Models\\MetaDefinition $definition, mixed $value): self" - } - }, - "Pollora\\Meta\\Domain\\Exceptions\\MetaValidationException": { - "kind": "final class", - "extends": "InvalidArgumentException", - "implements": [], - "constants": [], - "methods": { - "__construct": "public (Pollora\\Meta\\Domain\\Models\\MetaDefinition $definition, array $messages): mixed" - } - }, - "Pollora\\Meta\\Domain\\Models\\MetaDefinition": { - "kind": "final readonly class", - "extends": null, - "implements": [], - "constants": [], - "methods": { - "__construct": "public (string $property, string $key, Pollora\\Meta\\Domain\\Enums\\MetaValueType $valueType, ?string $valueClass, bool $nullable, mixed $default, bool $showInRest = ?, ?string $label = ?, ?string $description = ?, array|string|null $sanitize = ?, ?string $capability = ?, bool $revisions = ?, array $rules = ?, bool $single = ?, ?Pollora\\Meta\\Domain\\Models\\MetaDefinition $items = ?, array $properties = ?, ?Pollora\\Meta\\Domain\\Enums\\Control $control = ?, ?string $group = ?, array $hints = ?, bool $media = ?, bool $public = ?): mixed", - "isProtected": "public (): bool", - "isStructured": "public (): bool", - "item": "public (): Pollora\\Meta\\Domain\\Models\\MetaDefinition", - "restSchema": "public (): array", - "wordPressType": "public (): string" - } - }, - "Pollora\\Meta\\Domain\\Models\\MetaRecord": { - "kind": "final class", - "extends": null, - "implements": [], - "constants": [], - "methods": { - "__construct": "public (Pollora\\Meta\\Domain\\Models\\MetaSchema $schema, int $objectId, Pollora\\Meta\\Domain\\Contracts\\MetaStoreInterface $store, Pollora\\Meta\\Domain\\Services\\MetaValueCaster $caster, Closure $onUnreadable, ?Pollora\\Meta\\Domain\\Contracts\\MetaValidatorInterface $validator = ?): mixed", - "__get": "public (string $name): mixed", - "__isset": "public (string $name): bool", - "__set": "public (string $name, mixed $value): void", - "fill": "public (array $values): static", - "get": "public (string $name): mixed", - "objectId": "public (): int", - "save": "public (): static", - "set": "public (string $name, mixed $value): static", - "toArray": "public (): array" - } - }, - "Pollora\\Meta\\Domain\\Models\\MetaSchema": { - "kind": "final readonly class", - "extends": null, - "implements": [], - "constants": [], - "methods": { - "__construct": "public (string $declaringClass, Pollora\\Meta\\Domain\\Enums\\MetaObjectType $objectType, array $subtypes, array $definitions, bool $declaresSubtypes = ?): mixed", - "exposesInRest": "public (): bool", - "find": "public (string $propertyOrKey): ?Pollora\\Meta\\Domain\\Models\\MetaDefinition", - "isEmpty": "public (): bool", - "overlaps": "public (self $other): bool", - "ownerName": "public (): string", - "withDefinitions": "public (array $definitions): self" - } - }, - "Pollora\\Meta\\Domain\\Services\\MetaValueCaster": { - "kind": "final class", - "extends": null, - "implements": [], - "constants": [], - "methods": { - "absentValue": "public (Pollora\\Meta\\Domain\\Models\\MetaDefinition $definition): mixed", - "sanitize": "public (Pollora\\Meta\\Domain\\Models\\MetaDefinition $definition, mixed $value): mixed", - "toJson": "public (Pollora\\Meta\\Domain\\Models\\MetaDefinition $definition, mixed $value): mixed", - "toPhp": "public (Pollora\\Meta\\Domain\\Models\\MetaDefinition $definition, mixed $raw): mixed", - "toRestDefault": "public (Pollora\\Meta\\Domain\\Models\\MetaDefinition $definition): mixed", - "toStorage": "public (Pollora\\Meta\\Domain\\Models\\MetaDefinition $definition, mixed $value): array|string|null" - } - }, - "Pollora\\Meta\\Infrastructure\\Adapters\\WordPressMetaInventory": { - "kind": "final readonly class", - "extends": null, - "implements": [ - "Pollora\\Meta\\Domain\\Contracts\\MetaInventoryInterface" - ], - "constants": [], - "methods": { - "keys": "public (Pollora\\Meta\\Domain\\Enums\\MetaObjectType $objectType, array $subtypes, int $limit): array", - "values": "public (Pollora\\Meta\\Domain\\Enums\\MetaObjectType $objectType, array $subtypes, string $key, int $limit): array" - } - }, - "Pollora\\Meta\\Infrastructure\\Adapters\\WordPressMetaRegistry": { - "kind": "final readonly class", - "extends": null, - "implements": [ - "Pollora\\Meta\\Domain\\Contracts\\MetaRegistryInterface" - ], - "constants": { - "INIT_PRIORITY": "const" - }, - "methods": { - "__construct": "public (Pollora\\Hook\\Domain\\Contract\\Action $action, Pollora\\Meta\\Domain\\Services\\MetaValueCaster $caster): mixed", - "register": "public (Pollora\\Meta\\Domain\\Models\\MetaSchema $schema): void" - } - }, - "Pollora\\Meta\\Infrastructure\\Adapters\\WordPressMetaStore": { - "kind": "final class", - "extends": null, - "implements": [ - "Pollora\\Meta\\Domain\\Contracts\\MetaStoreInterface" - ], - "constants": [], - "methods": { - "delete": "public (Pollora\\Meta\\Domain\\Enums\\MetaObjectType $objectType, int $objectId, string $key): void", - "get": "public (Pollora\\Meta\\Domain\\Enums\\MetaObjectType $objectType, int $objectId, string $key): mixed", - "getAll": "public (Pollora\\Meta\\Domain\\Enums\\MetaObjectType $objectType, int $objectId, string $key): array", - "replaceAll": "public (Pollora\\Meta\\Domain\\Enums\\MetaObjectType $objectType, int $objectId, string $key, array $values): void", - "update": "public (Pollora\\Meta\\Domain\\Enums\\MetaObjectType $objectType, int $objectId, string $key, array|string $value): void" - } - }, - "Pollora\\Meta\\Infrastructure\\Adapters\\WordPressRestMetaValidation": { - "kind": "final readonly class", - "extends": null, - "implements": [], - "constants": [], - "methods": { - "__construct": "public (Pollora\\Meta\\Application\\Services\\MetaSchemaRepository $schemas, Pollora\\Meta\\Domain\\Services\\MetaValueCaster $caster, Pollora\\Meta\\Domain\\Contracts\\MetaValidatorInterface $validator): mixed", - "validate": "public (mixed $response, array $handler, WP_REST_Request $request): mixed" - } - }, "Pollora\\Meta\\Infrastructure\\Laravel\\Console\\MetaAuditCommand": { "kind": "class", "extends": "Illuminate\\Console\\Command", @@ -677,250 +449,6 @@ "runsIn": "public (): array" } }, - "Pollora\\Meta\\Infrastructure\\Services\\MetaDiscovery": { - "kind": "final class", - "extends": null, - "implements": [ - "Pollora\\Discovery\\Domain\\Contracts\\DiscoveryInterface" - ], - "constants": [], - "methods": { - "__construct": "public (Pollora\\Meta\\Application\\Services\\MetaSchemaBuilder $builder, Pollora\\Meta\\Application\\Services\\MetaSchemaRepository $schemas, Pollora\\Meta\\Domain\\Contracts\\MetaRegistryInterface $registry, ?Psr\\Log\\LoggerInterface $logger = ?): mixed", - "apply": "public (): void", - "discover": "public (Pollora\\Discovery\\Domain\\Contracts\\DiscoveryLocationInterface $location, Spatie\\StructureDiscoverer\\Data\\DiscoveredStructure $structure, ?Pollora\\Discovery\\Domain\\Contracts\\ReflectionCacheInterface $reflectionCache = ?): void", - "getIdentifier": "public (): string", - "getItems": "public (): Pollora\\Discovery\\Domain\\Contracts\\DiscoveryItemsInterface", - "setItems": "public (Pollora\\Discovery\\Domain\\Contracts\\DiscoveryItemsInterface $items): void" - } - }, - "Pollora\\Meta\\Testing\\Fixtures\\EveryMetaKind": { - "kind": "final class", - "extends": null, - "implements": [], - "constants": [], - "methods": [] - }, - "Pollora\\Meta\\Testing\\InstantiatingContainer": { - "kind": "final class", - "extends": null, - "implements": [ - "Psr\\Container\\ContainerInterface" - ], - "constants": [], - "methods": { - "get": "public (string $id): mixed", - "has": "public (string $id): bool" - } - }, - "Pollora\\Meta\\Testing\\MetaUiDriverConformance": { - "kind": "final class", - "extends": null, - "implements": [], - "constants": [], - "methods": { - "check": "public static (Pollora\\Meta\\Domain\\Contracts\\MetaUiDriver $driver): array", - "schema": "public static (): Pollora\\Meta\\Domain\\Models\\MetaSchema" - } - }, - "Pollora\\Role\\Application\\Services\\CapabilityOwnerReader": { - "kind": "final class", - "extends": null, - "implements": [], - "constants": { - "TERM_CAPABILITIES": "const" - }, - "methods": { - "postType": "public (string $class): ?array", - "taxonomy": "public (string $class): ?array" - } - }, - "Pollora\\Role\\Application\\Services\\RoleDefinitionBuilder": { - "kind": "final readonly class", - "extends": null, - "implements": [], - "constants": { - "CORE_ROLES": "const", - "SENSITIVE_CAPABILITIES": "const" - }, - "methods": { - "__construct": "public (Pollora\\Role\\Application\\Services\\CapabilityOwnerReader $owners, array $superRoles = ?): mixed", - "build": "public (string $class): Pollora\\Role\\Domain\\Models\\RoleDefinition|Pollora\\Role\\Domain\\Models\\RoleModification" - } - }, - "Pollora\\Role\\Application\\Services\\RoleReference": { - "kind": "final class", - "extends": null, - "implements": [], - "constants": [], - "methods": { - "matchesAny": "public static (array $userRoles, array $roles): bool", - "slug": "public static (string $role): string" - } - }, - "Pollora\\Role\\Application\\Services\\RoleRegistry": { - "kind": "final class", - "extends": null, - "implements": [], - "constants": [], - "methods": { - "__construct": "public (Pollora\\Role\\Application\\Services\\CapabilityOwnerReader $owners, Pollora\\Role\\Domain\\Services\\PostTypeCapabilityMap $postTypeCapabilities): mixed", - "addCapabilitySet": "public (array $capabilities): void", - "addModification": "public (Pollora\\Role\\Domain\\Models\\RoleModification $modification): void", - "addPostType": "public (string $class): void", - "addRole": "public (Pollora\\Role\\Domain\\Models\\RoleDefinition $definition): void", - "addTaxonomy": "public (string $class): void", - "declaredCapabilities": "public (): array", - "definitions": "public (?Closure $warn = ?): array", - "isEmpty": "public (): bool", - "labelDomains": "public (): array", - "modifications": "public (?Closure $warn = ?): array" - } - }, - "Pollora\\Role\\Domain\\Contracts\\RoleStoreInterface": { - "kind": "interface", - "extends": null, - "implements": [], - "constants": [], - "methods": { - "addRoleToUser": "public abstract (int $userId, string $role): void", - "removeFromUser": "public abstract (int $userId, string $entry): void", - "rolesOf": "public abstract (int $userId): array", - "saveStoredRoles": "public abstract (array $roles): void", - "storedRoles": "public abstract (): array" - } - }, - "Pollora\\Role\\Domain\\Contracts\\RoleUsageInterface": { - "kind": "interface", - "extends": null, - "implements": [], - "constants": [], - "methods": { - "entries": "public abstract (): array", - "usersWith": "public abstract (string $entry): array" - } - }, - "Pollora\\Role\\Domain\\Exceptions\\InvalidRoleDefinitionException": { - "kind": "final class", - "extends": "LogicException", - "implements": [], - "constants": [], - "methods": { - "forClass": "public static (string $class, string $reason): self" - } - }, - "Pollora\\Role\\Domain\\Models\\RoleChanges": { - "kind": "final readonly class", - "extends": null, - "implements": [], - "constants": [], - "methods": { - "__construct": "public (array $grants = ?, array $removals = ?, array $postTypeGrants = ?, array $taxonomyGrants = ?): mixed", - "withResolvedGrants": "public (array $grants): self" - } - }, - "Pollora\\Role\\Domain\\Models\\RoleDefinition": { - "kind": "final readonly class", - "extends": null, - "implements": [], - "constants": [], - "methods": { - "__construct": "public (string $slug, string $label, ?string $inherits, Pollora\\Role\\Domain\\Models\\RoleChanges $changes, string $declaringClass, ?string $textDomain = ?): mixed", - "withChanges": "public (Pollora\\Role\\Domain\\Models\\RoleChanges $changes): self" - } - }, - "Pollora\\Role\\Domain\\Models\\RoleModification": { - "kind": "final readonly class", - "extends": null, - "implements": [], - "constants": [], - "methods": { - "__construct": "public (string $slug, Pollora\\Role\\Domain\\Models\\RoleChanges $changes, string $declaringClass): mixed", - "withChanges": "public (Pollora\\Role\\Domain\\Models\\RoleChanges $changes): self" - } - }, - "Pollora\\Role\\Domain\\Services\\PostTypeCapabilityMap": { - "kind": "final class", - "extends": null, - "implements": [], - "constants": [], - "methods": { - "capabilities": "public (string $capabilityType, Pollora\\Role\\Domain\\Enums\\Access $access, array $overrides = ?): array" - } - }, - "Pollora\\Role\\Domain\\Services\\RoleCompiler": { - "kind": "final class", - "extends": null, - "implements": [], - "constants": { - "MARKER": "const" - }, - "methods": { - "compile": "public (array $storedRoles, array $definitions, array $modifications, array $superRoles, array $declaredCapabilities, ?Closure $warn = ?): array" - } - }, - "Pollora\\Role\\Domain\\Services\\StoredEntryClassifier": { - "kind": "final class", - "extends": null, - "implements": [], - "constants": { - "CAPABILITY": "const", - "DEAD": "const", - "ROLE": "const" - }, - "methods": { - "classify": "public (string $entry, array $roles): string" - } - }, - "Pollora\\Role\\Infrastructure\\Adapters\\WordPressRoleInjector": { - "kind": "final class", - "extends": null, - "implements": [], - "constants": [], - "methods": { - "__construct": "public (Pollora\\Role\\Application\\Services\\RoleRegistry $registry, Pollora\\Role\\Domain\\Services\\RoleCompiler $compiler, array $superRoles = ?, ?Psr\\Log\\LoggerInterface $logger = ?): mixed", - "inject": "public (WP_Roles $wpRoles): void", - "refresh": "public (): void", - "reportWarnings": "public (): void", - "warnings": "public (): array" - } - }, - "Pollora\\Role\\Infrastructure\\Adapters\\WordPressRoleLabelTranslator": { - "kind": "final readonly class", - "extends": null, - "implements": [], - "constants": [], - "methods": { - "__construct": "public (Pollora\\Role\\Application\\Services\\RoleRegistry $registry): mixed", - "translate": "public (string $translation, string $text, string $context): string" - } - }, - "Pollora\\Role\\Infrastructure\\Adapters\\WordPressRoleStore": { - "kind": "final readonly class", - "extends": null, - "implements": [ - "Pollora\\Role\\Domain\\Contracts\\RoleStoreInterface" - ], - "constants": [], - "methods": { - "addRoleToUser": "public (int $userId, string $role): void", - "removeFromUser": "public (int $userId, string $entry): void", - "rolesOf": "public (int $userId): array", - "saveStoredRoles": "public (array $roles): void", - "storedRoles": "public (): array" - } - }, - "Pollora\\Role\\Infrastructure\\Adapters\\WordPressRoleUsage": { - "kind": "final class", - "extends": null, - "implements": [ - "Pollora\\Role\\Domain\\Contracts\\RoleUsageInterface" - ], - "constants": [], - "methods": { - "entries": "public (): array", - "usersWith": "public (string $entry): array" - } - }, "Pollora\\Role\\Infrastructure\\Laravel\\Console\\RoleDumpCommand": { "kind": "class", "extends": "Illuminate\\Console\\Command", @@ -1026,21 +554,5 @@ "run": "public (Pollora\\Doctor\\Domain\\Enums\\RunContext $context): Pollora\\Doctor\\Domain\\Models\\CheckResult", "runsIn": "public (): array" } - }, - "Pollora\\Role\\Infrastructure\\Services\\RoleDiscovery": { - "kind": "final class", - "extends": null, - "implements": [ - "Pollora\\Discovery\\Domain\\Contracts\\DiscoveryInterface" - ], - "constants": [], - "methods": { - "__construct": "public (Pollora\\Role\\Application\\Services\\RoleDefinitionBuilder $builder, Pollora\\Role\\Application\\Services\\RoleRegistry $registry, Pollora\\Role\\Infrastructure\\Adapters\\WordPressRoleInjector $injector, ?Psr\\Log\\LoggerInterface $logger = ?): mixed", - "apply": "public (): void", - "discover": "public (Pollora\\Discovery\\Domain\\Contracts\\DiscoveryLocationInterface $location, Spatie\\StructureDiscoverer\\Data\\DiscoveredStructure $structure, ?Pollora\\Discovery\\Domain\\Contracts\\ReflectionCacheInterface $reflectionCache = ?): void", - "getIdentifier": "public (): string", - "getItems": "public (): Pollora\\Discovery\\Domain\\Contracts\\DiscoveryItemsInterface", - "setItems": "public (Pollora\\Discovery\\Domain\\Contracts\\DiscoveryItemsInterface $items): void" - } } } diff --git a/tests/Unit/BlockBinding/BindingContextTest.php b/tests/Unit/BlockBinding/BindingContextTest.php index 67c8b204..79226a3c 100644 --- a/tests/Unit/BlockBinding/BindingContextTest.php +++ b/tests/Unit/BlockBinding/BindingContextTest.php @@ -2,7 +2,9 @@ declare(strict_types=1); +use Pollora\BlockBinding\Domain\Contracts\PostFinderInterface; use Pollora\BlockBinding\Domain\Models\BindingContext; +use Pollora\Colt\Model\Post; use Pollora\Meta\Application\Services\MetaAccessor; use Pollora\Meta\Application\Services\MetaSchemaBuilder; use Pollora\Meta\Application\Services\MetaSchemaRepository; @@ -33,3 +35,27 @@ it('has no meta to give without the object', function (): void { expect((new BindingContext(metaAccessor: $this->accessor))->meta(Concert::class))->toBeNull(); }); + +it('loads the post of the block context through the finder it is given, once', function (): void { + $post = new Post; + $finder = new class($post) implements PostFinderInterface + { + public int $calls = 0; + + public function __construct(private readonly Post $post) {} + + public function find(int $postId): ?Post + { + $this->calls++; + + return $postId === 7 ? $this->post : null; + } + }; + $context = new BindingContext(postId: 7, postFinder: $finder); + + expect($context->post())->toBe($post) + ->and($context->post())->toBe($post) + ->and($finder->calls)->toBe(1) + ->and((new BindingContext(postId: 8, postFinder: $finder))->post())->toBeNull() + ->and((new BindingContext)->post())->toBeNull(); +}); diff --git a/tests/Unit/BlockBinding/BindingEditorDataTest.php b/tests/Unit/BlockBinding/BindingEditorDataTest.php index 1a7c95d6..b746c5a0 100644 --- a/tests/Unit/BlockBinding/BindingEditorDataTest.php +++ b/tests/Unit/BlockBinding/BindingEditorDataTest.php @@ -2,10 +2,9 @@ declare(strict_types=1); -use Illuminate\Config\Repository; use Pollora\BlockBinding\Application\Services\BindingSourceBuilder; use Pollora\BlockBinding\Application\Services\BindingSourceRegistry; -use Pollora\BlockBinding\Infrastructure\Providers\BlockBindingServiceProvider; +use Pollora\BlockBinding\Infrastructure\Laravel\BlockBindingServiceProvider; use Pollora\BlockBinding\Infrastructure\Services\BindingEditorData; use Pollora\Meta\Application\Services\MetaSchemaBuilder; use Pollora\Meta\Application\Services\MetaSchemaRepository; @@ -27,7 +26,7 @@ $schemas->add((new MetaSchemaBuilder)->build($class)); } - $this->data = (new BindingEditorData($sources, $schemas, new Repository(['block-bindings' => ['options' => ['blogdescription']]])))->toArray(); + $this->data = (new BindingEditorData($sources, $schemas, ['blogdescription']))->toArray(); }); it('gives the editor the route and the fields of a #[BlockBinding] source', function (): void { diff --git a/tests/Unit/BlockBinding/BindingListCommandTest.php b/tests/Unit/BlockBinding/BindingListCommandTest.php index 8df78d8e..93dfcb2c 100644 --- a/tests/Unit/BlockBinding/BindingListCommandTest.php +++ b/tests/Unit/BlockBinding/BindingListCommandTest.php @@ -2,15 +2,14 @@ declare(strict_types=1); -use Illuminate\Config\Repository; use Illuminate\Console\Attributes\Signature; use Illuminate\Container\Container; use Illuminate\Foundation\Application; use Pollora\BlockBinding\Application\Services\BindingSourceBuilder; use Pollora\BlockBinding\Application\Services\BindingSourceRegistry; -use Pollora\BlockBinding\Infrastructure\Providers\BlockBindingServiceProvider; +use Pollora\BlockBinding\Infrastructure\Laravel\BlockBindingServiceProvider; +use Pollora\BlockBinding\Infrastructure\Laravel\Console\BindingListCommand; use Pollora\BlockBinding\Infrastructure\Services\BindingEditorData; -use Pollora\BlockBinding\UI\Console\BindingListCommand; use Pollora\Meta\Application\Services\MetaSchemaBuilder; use Pollora\Meta\Application\Services\MetaSchemaRepository; use Symfony\Component\Console\Input\ArrayInput; @@ -34,7 +33,7 @@ function runBindingList(array $input = [], ?array $blocks = null): string $schemas->add((new MetaSchemaBuilder)->build(Concert::class)); $app->instance(BindingSourceRegistry::class, $sources); - $app->instance(BindingEditorData::class, new BindingEditorData($sources, $schemas, new Repository(['block-bindings' => ['options' => ['blogname']]]))); + $app->instance(BindingEditorData::class, new BindingEditorData($sources, $schemas, ['blogname'])); $command = new #[Signature('pollora:binding:list {--json}')] class($blocks) extends BindingListCommand { diff --git a/tests/Unit/BlockBinding/BindingReferenceInspectorTest.php b/tests/Unit/BlockBinding/BindingReferenceInspectorTest.php index f41368a2..4eb9103a 100644 --- a/tests/Unit/BlockBinding/BindingReferenceInspectorTest.php +++ b/tests/Unit/BlockBinding/BindingReferenceInspectorTest.php @@ -5,7 +5,7 @@ use Pollora\BlockBinding\Application\Services\BindingReferenceInspector; use Pollora\BlockBinding\Application\Services\BindingSourceBuilder; use Pollora\BlockBinding\Application\Services\BindingSourceRegistry; -use Pollora\BlockBinding\Infrastructure\Providers\BlockBindingServiceProvider; +use Pollora\BlockBinding\Infrastructure\Laravel\BlockBindingServiceProvider; use Pollora\Meta\Application\Services\MetaSchemaBuilder; use Pollora\Meta\Application\Services\MetaSchemaRepository; use Tests\Unit\BlockBinding\Fixtures\ArtistProfile; diff --git a/tests/Unit/BlockBinding/BindingResolverTest.php b/tests/Unit/BlockBinding/BindingResolverTest.php index 8c8ecadf..0ca66717 100644 --- a/tests/Unit/BlockBinding/BindingResolverTest.php +++ b/tests/Unit/BlockBinding/BindingResolverTest.php @@ -7,6 +7,8 @@ use Pollora\BlockBinding\Application\Services\BindingResolver; use Pollora\BlockBinding\Application\Services\BindingSourceBuilder; use Pollora\BlockBinding\Domain\Events\BindingResolved; +use Pollora\BlockBinding\Infrastructure\Laravel\LaravelBindingEvents; +use Pollora\BlockBinding\Infrastructure\Laravel\LaravelMethodInvoker; use Psr\Log\LoggerInterface; use Tests\Unit\BlockBinding\Fixtures\EventBinding; use Tests\Unit\BlockBinding\Fixtures\FakePresenter; @@ -20,7 +22,7 @@ $this->container = new Container; $this->visibility = new FakeVisibility; $this->logger = Mockery::mock(LoggerInterface::class); - $this->resolver = fn (bool $debug = false): BindingResolver => new BindingResolver($this->container, $this->visibility, new FakePresenter, null, $debug, $this->logger); + $this->resolver = fn (bool $debug = false): BindingResolver => new BindingResolver($this->container, $this->visibility, new FakePresenter, null, $debug, $this->logger, new LaravelMethodInvoker($this->container), new LaravelBindingEvents($this->container)); $this->event = (new BindingSourceBuilder)->build(EventBinding::class); }); diff --git a/tests/Unit/BlockBinding/BlockBindingServiceProviderTest.php b/tests/Unit/BlockBinding/BlockBindingServiceProviderTest.php index dc6f4fcc..1de75e1d 100644 --- a/tests/Unit/BlockBinding/BlockBindingServiceProviderTest.php +++ b/tests/Unit/BlockBinding/BlockBindingServiceProviderTest.php @@ -10,9 +10,9 @@ use Illuminate\Foundation\Application; use Pollora\BlockBinding\Application\Services\BindingResolver; use Pollora\BlockBinding\Application\Services\BindingSourceRegistry; -use Pollora\BlockBinding\Infrastructure\Providers\BlockBindingServiceProvider; +use Pollora\BlockBinding\Infrastructure\Laravel\BlockBindingServiceProvider; +use Pollora\BlockBinding\Infrastructure\Laravel\Console\MakeBindingCommand; use Pollora\BlockBinding\Infrastructure\Services\BlockBindingDiscovery; -use Pollora\BlockBinding\UI\Console\MakeBindingCommand; use Pollora\Hook\Domain\Contract\Action; use Pollora\Meta\Application\Services\MetaAccessor; use Pollora\Meta\Application\Services\MetaSchemaBuilder; diff --git a/tests/Unit/BlockBinding/BlockBindingsCheckTest.php b/tests/Unit/BlockBinding/BlockBindingsCheckTest.php index 038cd11e..67df082c 100644 --- a/tests/Unit/BlockBinding/BlockBindingsCheckTest.php +++ b/tests/Unit/BlockBinding/BlockBindingsCheckTest.php @@ -7,7 +7,7 @@ use Pollora\BlockBinding\Application\Services\BindingReferenceInspector; use Pollora\BlockBinding\Application\Services\BindingSourceBuilder; use Pollora\BlockBinding\Application\Services\BindingSourceRegistry; -use Pollora\BlockBinding\Infrastructure\Checks\BlockBindingsCheck; +use Pollora\BlockBinding\Infrastructure\Laravel\BlockBindingsCheck; use Pollora\Doctor\Domain\Enums\CheckStatus; use Pollora\Doctor\Domain\Enums\RunContext; use Pollora\Doctor\Infrastructure\Support\ProjectModule; diff --git a/tests/Unit/BlockBinding/PolloraSourcesTest.php b/tests/Unit/BlockBinding/PolloraSourcesTest.php index ed528b46..eb83ebed 100644 --- a/tests/Unit/BlockBinding/PolloraSourcesTest.php +++ b/tests/Unit/BlockBinding/PolloraSourcesTest.php @@ -3,7 +3,6 @@ declare(strict_types=1); use Brain\Monkey\Functions; -use Illuminate\Config\Repository; use Pollora\BlockBinding\Domain\Models\BindingContext; use Pollora\BlockBinding\Infrastructure\Services\BindingFormatter; use Pollora\BlockBinding\Infrastructure\Sources\AuthorMetaSource; @@ -86,7 +85,7 @@ function concertContext(array $args, ?int $termId = null, ?string $taxonomy = nu it('pollora/option reads only the options the project lists', function (): void { Functions\when('get_option')->alias(fn (string $name): string => $name === 'blogdescription' ? 'Live music' : 'secret'); - $source = new OptionSource(new Repository(['block-bindings' => ['options' => ['blogdescription']]])); + $source = new OptionSource(['blogdescription']); expect($source(new BindingContext(args: ['name' => 'blogdescription'])))->toBe('Live music') ->and($source(new BindingContext(args: ['name' => 'admin_email'])))->toBeNull(); diff --git a/tests/Unit/BlockBinding/WordPressBindingEditorScriptTest.php b/tests/Unit/BlockBinding/WordPressBindingEditorScriptTest.php index e4fd796a..310eb9d3 100644 --- a/tests/Unit/BlockBinding/WordPressBindingEditorScriptTest.php +++ b/tests/Unit/BlockBinding/WordPressBindingEditorScriptTest.php @@ -3,7 +3,6 @@ declare(strict_types=1); use Brain\Monkey\Functions; -use Illuminate\Config\Repository; use Pollora\BlockBinding\Application\Services\BindingSourceRegistry; use Pollora\BlockBinding\Infrastructure\Adapters\WordPressBindingEditorScript; use Pollora\BlockBinding\Infrastructure\Services\BindingEditorData; @@ -26,7 +25,7 @@ $calls[] = ['enqueue', $handle]; }); - (new WordPressBindingEditorScript(new BindingEditorData(new BindingSourceRegistry, new MetaSchemaRepository, new Repository)))->enqueue(); + (new WordPressBindingEditorScript(new BindingEditorData(new BindingSourceRegistry, new MetaSchemaRepository, [])))->enqueue(); expect($calls[0])->toBe(['register', 'pollora-block-bindings', false, ['wp-api-fetch', 'wp-block-editor', 'wp-blocks', 'wp-data']]) ->and($calls[1][1])->toBe('before')