Skip to content
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

[HttpKernel] Create Attributes #[MapQueryString] and #[MapRequestContent] to map Request input to typed objects #49138

Open
wants to merge 1 commit into
base: 6.3
Choose a base branch
from

Conversation

Koc
Copy link
Contributor

@Koc Koc commented Jan 27, 2023

Q A
Branch? 6.3
Bug fix? no
New feature? yes
Deprecations? no
Tickets
License MIT
Doc PR TBD

Yet another variation of #49002 and #49134. We can even build OpenApi Specification based on this DTO classes using NelmioApiDocBundle.

class QueryString
{
    public function __construct(
        public readonly Filter $filter,
    ) {
    }
}

class Filter
{
    public function __construct(
        #[Assert\Choice(['placed', 'shipped', 'delivered'])]
        public readonly string $status,
        #[Assert\LessThan(100)]
        public readonly int $quantity,
    ) {

    }
}

class RequestContent
{
    public function __construct(
        #[Assert\NotBlank]
        #[Assert\Length(min: 10, max: 100)]
        public readonly string $comment,
    ) {
    }
}

class ApiController
{
    public function __invoke(
        #[MapRequestContent] RequestContent $content,
        #[MapQueryString] QueryString $query,
    ): Response {
        // ...
    }
}

@carsonbot carsonbot added this to the 6.3 milestone Jan 27, 2023
@Koc Koc force-pushed the feature/mapped-request branch 5 times, most recently from 87eb66c to a08be6b Compare Jan 27, 2023
@Koc Koc changed the title Create Attributes to map Query String and Request Content to typed objects [HttpKernel] Create Attributes #[MapQueryString and #[MapRequestContent] to map Request input to typed objects Jan 27, 2023
@Koc Koc changed the title [HttpKernel] Create Attributes #[MapQueryString and #[MapRequestContent] to map Request input to typed objects [HttpKernel] Create Attributes #[MapQueryString] and #[MapRequestContent] to map Request input to typed objects Jan 27, 2023
@Koc Koc force-pushed the feature/mapped-request branch 3 times, most recently from 0849026 to 078781e Compare Jan 27, 2023
@Koc Koc force-pushed the feature/mapped-request branch from 078781e to b3bbe43 Compare Jan 27, 2023
@OskarStark
Copy link
Contributor

It looks like your committer email is not associated with your Github account

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants