-
Notifications
You must be signed in to change notification settings - Fork 11.2k
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
[11.x] Add fluent RegExp validation class rule #54521
Conversation
I like this suggestion! I have a few comments that I feel like will help it be inline with the usual Laravel code that I will add in a review/comments. |
@AndrewMast Sure, feedback is always welcome 👍🏻 |
':', | ||
$this->regExp, | ||
) | ||
->when($this->flags, function (SupportStringable $str) { |
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.
What if we get all of the flags from the expression when we create the instance? This way if we call ->flags('i', 'g', ...)
(which current replaces all flags with the flags provided), it will not keep any of the flags originally in the expression. Then we can just add implode('', $this->flags)
to the ->append(...)
here.
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.
Maybe we could do something like this for the constructor:
public function __construct(string $expression, array|Arrayable $extraFlags = [])
{
$currentFlags = str_split(Str::of($expression)->afterLast('/'));
if ($extraFlags instanceof Arrayable) {
$extraFlags = $extraFlags->toArray();
}
$this->expression = Str::of($expression)->beforeLast('/')->append('/')->toString();
$this->flags = array_unique([...$currentFlags, ...$extraFlags]);
}
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.
which current replaces all flags with the flags provided
That was the idea. The class has essentially two methods for this:
setFlags()
: Entirely replaces the flags (namedflags()
due to naming conventions)addFlag()
: Adds a flag to the list of flags without replacing them (namedflag()
due to naming conventions
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.
That's what I assumed! Now with the updated constructor code, it makes much more sense to me. Good work!
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.
Good work!
Primarily due to your feedback 👍🏻 Thanks a lot!
Based on https://github.com/laravel/framework/pull/54521/files/daffcc29b48dcc7aa083e10e803a4242eb5ed5de#r1947924894 Co-authored-by: Andrew Mast <andrew@andrewmast.com>
see https://github.com/laravel/framework/pull/54521/files/daffcc29b48dcc7aa083e10e803a4242eb5ed5de#r1947921675 Co-authored-by: Andrew Mast andrew@andrewmast.com
see laravel#54521 (comment) Co-authored-by: Andrew Mast <andrew@andrewmast.com>
see laravel#54521 (comment) Co-authored-by: Andrew Mast <andrew@andrewmast.com>
Follow-up to 4e18d64
Thanks for your pull request to Laravel! Unfortunately, I'm going to delay merging this code for now. To preserve our ability to adequately maintain the framework, we need to be very careful regarding the amount of code we include. If applicable, please consider releasing your code as a package so that the community can still take advantage of your contributions! |
Similar to #54488, #53465, #54425, #54517, and #54519
Examples
Simplest case
Negation
Flags
Modify flags