Weave Code
Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Cqs Routing Laravel Package

digital-craftsman/cqs-routing

View on GitHub
Deep Wiki
Context7

Request validator examples

Interface

interface RequestValidator
{
    /** [@param](https://github.com/param) scalar|array<array-key, scalar|null>|null $parameters */
    public function validateRequest(
        Request $request,
        mixed $parameters,
    ): void;

    /** [@param](https://github.com/param) scalar|array<array-key, scalar|null>|null $parameters */
    public static function areParametersValid(mixed $parameters): bool;
}

See position in process

Scan for viruses in files

You might want to validate files that are uploaded against virus databases before they are given to the business logic. You might have a separate class VirusFreeFile that extends UploadedFile and is constructed as part of the DTO. So you need to do the virus scan process before you construct the command. Your validator might look like the following:

final readonly class VirusFreeFilesRequestValidator implements RequestValidator
{
    public function __construct(
        private VirusScanner $virusScanner,
    ) {
    }

    /** [@param](https://github.com/param) null $parameters */
    public function validateRequest(
        Request $request,
        mixed $parameters,
    ): void {
        foreach ($request->files as $file) {
            // Throws exception if it finds a virus in the file.
            $this->virusScanner->scanFile($file);
        }
    }
    
    /** [@param](https://github.com/param) null $parameters */
    public static function areParametersValid(mixed $parameters): bool
    {
        return $parameters === null;
    }
}

With such a validator in place, there is no way for a file with a virus to reach the business logic. Using such a validator as one of the default validators means you're safe throughout your application.

Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
gmostafa/php-graphql-client
xeviant/paystack
snowsoft/faker
meditationsteps/blogetc
animalyoung/laravel-influxdb
onix-solutions/sms-telera
lonely-lights/prosetta
oxygen/data
oxygen/core
jengo/base
xiloryx/log-collector
a21ns1g4ts/filament-stripe
la-php/laravel-admin
artisan-build/community-prompts
vleroy/smart
ayles-software/laravel-australian-public-holidays
cboxdk/laravel-id-spatie
cboxdk/laravel-id-billing
cboxdk/laravel-id-billing-bridge
simple-as-fuck/php-performance-log