Repository navigation
Complete the Data package API and fix creation, validation and output defects #645
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
caeff93
323096b
3a00a66
b98318c
54956ca
49553a6
a8a7f70
c3cdbb6
0faf52f
3e5b499
1b925a2
db7b4be
9b8fe6a
036bb01
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -1756,6 +1756,55 @@ public function buildWith(Closure|string $concrete, array $parameters = []): mix | |||||||||||||
| } | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| /** | ||||||||||||||
| * Resolve the contextual constructor parameters of a class within its build context. | ||||||||||||||
| * | ||||||||||||||
| * Contextual bindings for the class apply to dependencies the attributes resolve, and each | ||||||||||||||
| * parameter's attribute callbacks fire here. Pass the values to buildWith() as overrides | ||||||||||||||
| * so they are not resolved again. Variadic parameters are skipped, because an override | ||||||||||||||
| * is passed as one argument; the container resolves them when the class is built. | ||||||||||||||
| * | ||||||||||||||
| * @param class-string $concrete | ||||||||||||||
| * @param null|list<string> $names the parameters to resolve, or null for every contextual parameter | ||||||||||||||
| * @return array<string, mixed> | ||||||||||||||
| * | ||||||||||||||
| * @throws BindingResolutionException | ||||||||||||||
| */ | ||||||||||||||
| public function resolveContextualParameters(string $concrete, ?array $names = null): array | ||||||||||||||
| { | ||||||||||||||
| $recipe = $this->getBuildRecipe($concrete); | ||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P2: An unknown class produces an empty recipe here, so this method silently returns Prompt for AI agents
Suggested change
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not changing this. The values are resolved for a class that is then built with |
||||||||||||||
| $resolutionState = $this->getOrCreateResolutionState(); | ||||||||||||||
| $resolutionState->buildStack[] = $concrete; | ||||||||||||||
|
|
||||||||||||||
| try { | ||||||||||||||
| $values = []; | ||||||||||||||
|
|
||||||||||||||
| foreach ($recipe->parameters as $paramRecipe) { | ||||||||||||||
| if ($paramRecipe->contextualAttribute === null | ||||||||||||||
| || $paramRecipe->isVariadic | ||||||||||||||
| || ($names !== null && ! in_array($paramRecipe->name, $names, true)) | ||||||||||||||
| ) { | ||||||||||||||
| continue; | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| $value = $this->resolveFromAttribute( | ||||||||||||||
| $paramRecipe->contextualAttribute, | ||||||||||||||
| $paramRecipe->getReflectionParameter(), | ||||||||||||||
| ); | ||||||||||||||
|
|
||||||||||||||
| if ($paramRecipe->attributes !== []) { | ||||||||||||||
| $this->fireAfterResolvingAttributeCallbacks($paramRecipe->attributes, $value); | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| $values[$paramRecipe->name] = $value; | ||||||||||||||
|
cubic-dev-ai[bot] marked this conversation as resolved.
|
||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| return $values; | ||||||||||||||
| } finally { | ||||||||||||||
| array_pop($resolutionState->buildStack); | ||||||||||||||
| } | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| /** | ||||||||||||||
| * Instantiate a concrete instance of the given type. | ||||||||||||||
| * | ||||||||||||||
|
|
@@ -1824,7 +1873,10 @@ public function build(Closure|string $concrete): mixed | |||||||||||||
| array_pop($resolutionState->buildStack); | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| $instance = new $concrete(...$instances); | ||||||||||||||
| // Arguments go through the native invoker so scalars convert as they do in Laravel. | ||||||||||||||
| $instance = $instances === [] | ||||||||||||||
| ? new $concrete | ||||||||||||||
| : NativeInvoker::construct($concrete, $instances); | ||||||||||||||
|
|
||||||||||||||
| if ($recipe->classAttributes !== []) { | ||||||||||||||
| $this->fireAfterResolvingAttributeCallbacks( | ||||||||||||||
|
|
||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| <?php | ||
|
|
||
| // This file deliberately omits strict_types. Route parameters arrive as strings, and Laravel's | ||
| // dispatchers and container are not strict, so PHP's weak typing turns '123' into 123 for an | ||
| // `int $id` action or constructor parameter. Calling application code from here keeps that | ||
| // Laravel-compatible behavior, including PHP's own TypeError for a value such as 'abc'. | ||
|
|
||
| namespace Hypervel\Container; | ||
|
|
||
| /** | ||
| * @internal | ||
| */ | ||
| final class NativeInvoker | ||
| { | ||
| /** | ||
| * Call application code with PHP's weak scalar conversion. | ||
| * | ||
| * @param list<mixed> $arguments | ||
| */ | ||
| public static function call(callable $callback, array $arguments): mixed | ||
| { | ||
| return $callback(...$arguments); | ||
| } | ||
|
|
||
| /** | ||
| * Construct a class with PHP's weak scalar conversion. | ||
| * | ||
| * @template TClass of object | ||
| * | ||
| * @param class-string<TClass> $class | ||
| * @param list<mixed> $arguments | ||
| * @return TClass | ||
| */ | ||
| public static function construct(string $class, array $arguments): object | ||
| { | ||
| return new $class(...$arguments); | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
P2: This would remove a documented public API, not just change internal normalization:
#[Rule('required|string')]is explicitly supported. Preserve string-rule compatibility at public boundaries and normalize internally, or specify a versioned deprecation and migration.Prompt for AI agents
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not changing this. The entry records a planned breaking change, and this PR doesn't make it. When it's made, callers, tests and documentation change with it, as the entry says.