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

Using/Provide another approach to validate the url #2

Open
peter279k opened this issue Dec 2, 2018 · 0 comments
Open

Using/Provide another approach to validate the url #2

peter279k opened this issue Dec 2, 2018 · 0 comments

Comments

@peter279k
Copy link
Contributor

peter279k commented Dec 2, 2018

Firstly, take a look at this line of code on UrlValidator class:

protected function validate(string $value) : void
{
        $parts = parse_url($value);
        if ($parts === false) {
            $this->addFailureMessage('validator.url.invalid');
        }
        if (! isset($parts['scheme'])) {
            $this->addFailureMessage('validator.url.invalid');
        }
        if (! isset($parts['host'])) {
            $this->addFailureMessage('validator.url.invalid');
        }
}

How about using the filter_var function to validate url?

I think it can be quicker than using the parse_url function.

$result = filter_var($value, FILTER_VALIDATE_URL);
if ($result === false) {
    $this->addFailureMessage('validator.url.invalid');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant