Skip to content
This repository was archived by the owner on Mar 1, 2026. It is now read-only.
This repository was archived by the owner on Mar 1, 2026. It is now read-only.

Using/Provide another approach to validate the url #2

@peter279k

Description

@peter279k

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');
}

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