Skip to content

Required with parameter to set to true or false. #15

@josefsabl

Description

@josefsabl

It would be useful if required() method had fingerprint like this:

public function required(bool $required = true): self

Imagine you want to generate the schema programmatically either to require all options or to allow for only partial result. Imagine some create operation versus update operation where either I have to provide all fields or only ones I want to edit.

public static function getSchema(bool $partialAllowed) {
        return Expect::structure(
            [
                'name' => Expect::string()->required(!$partialAllowed),
            ]
        );
}

I am implementing restfull api, particularly post, put and patch methods and this would hugely declutter my code.

I will send PR shortly.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions