Weave Code
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

Cqrs Laravel Package

digital-craftsman/cqrs

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.
apiboxsym/user-bundle
apiboxsym/health-check-bundle
jayeshmepani/jpl-moshier-ephemeris-php
elnasnato/laraliveui
labrodev/rest-sdk
sampaui/sampaui
babelqueue/php-sdk
facebook/capi-param-builder-php
babelqueue/symfony
hamzi/corewatch
minionfactory/raw-hydrator
hexters/coinpayment
rjcodes/rjcms
act-training/laravel-permissions-manager
alimarchal/laravel-chart-of-accounts
babenkoivan/elastic-scout-driver
mkwebdesign/filament-watchdog-v5
renatomarinho/laravel-page-speed
zedmagdy/filament-business-hours
renatovdemoura/blade-elements-ui