Ubiquity
2.5.2
php rapid development framework
Loading...
Searching...
No Matches
UrlValidator.php
Go to the documentation of this file.
1
<?php
2
3
namespace
Ubiquity\contents\validation\validators\strings
;
4
12
class
UrlValidator
extends
RegexValidator
{
13
14
protected
$protocols
=[
"http"
,
"https"
,
"ftp"
];
15
protected
$relative
=
false
;
16
17
public
function
__construct
(){
18
$this->message=
"{value} is not a valid url"
;
19
$this->ref=
'~^
20
(%s):// # protocol
21
(([\.\pL\pN-]+:)?([\.\pL\pN-]+)@)? # basic auth
22
(
23
([\pL\pN\pS\-\.])+(\.?([\pL\pN]|xn\-\-[\pL\pN-]+)+\.?) # a domain name
24
| # or
25
\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3} # an IP address
26
| # or
27
\[
28
(?:(?:(?:(?:(?:(?:(?:[0-9a-f]{1,4})):){6})(?:(?:(?:(?:(?:[0-9a-f]{1,4})):(?:(?:[0-9a-f]{1,4})))|(?:(?:(?:(?:(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9]))\.){3}(?:(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9])))))))|(?:(?:::(?:(?:(?:[0-9a-f]{1,4})):){5})(?:(?:(?:(?:(?:[0-9a-f]{1,4})):(?:(?:[0-9a-f]{1,4})))|(?:(?:(?:(?:(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9]))\.){3}(?:(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9])))))))|(?:(?:(?:(?:(?:[0-9a-f]{1,4})))?::(?:(?:(?:[0-9a-f]{1,4})):){4})(?:(?:(?:(?:(?:[0-9a-f]{1,4})):(?:(?:[0-9a-f]{1,4})))|(?:(?:(?:(?:(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9]))\.){3}(?:(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9])))))))|(?:(?:(?:(?:(?:(?:[0-9a-f]{1,4})):){0,1}(?:(?:[0-9a-f]{1,4})))?::(?:(?:(?:[0-9a-f]{1,4})):){3})(?:(?:(?:(?:(?:[0-9a-f]{1,4})):(?:(?:[0-9a-f]{1,4})))|(?:(?:(?:(?:(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9]))\.){3}(?:(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9])))))))|(?:(?:(?:(?:(?:(?:[0-9a-f]{1,4})):){0,2}(?:(?:[0-9a-f]{1,4})))?::(?:(?:(?:[0-9a-f]{1,4})):){2})(?:(?:(?:(?:(?:[0-9a-f]{1,4})):(?:(?:[0-9a-f]{1,4})))|(?:(?:(?:(?:(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9]))\.){3}(?:(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9])))))))|(?:(?:(?:(?:(?:(?:[0-9a-f]{1,4})):){0,3}(?:(?:[0-9a-f]{1,4})))?::(?:(?:[0-9a-f]{1,4})):)(?:(?:(?:(?:(?:[0-9a-f]{1,4})):(?:(?:[0-9a-f]{1,4})))|(?:(?:(?:(?:(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9]))\.){3}(?:(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9])))))))|(?:(?:(?:(?:(?:(?:[0-9a-f]{1,4})):){0,4}(?:(?:[0-9a-f]{1,4})))?::)(?:(?:(?:(?:(?:[0-9a-f]{1,4})):(?:(?:[0-9a-f]{1,4})))|(?:(?:(?:(?:(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9]))\.){3}(?:(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9])))))))|(?:(?:(?:(?:(?:(?:[0-9a-f]{1,4})):){0,5}(?:(?:[0-9a-f]{1,4})))?::)(?:(?:[0-9a-f]{1,4})))|(?:(?:(?:(?:(?:(?:[0-9a-f]{1,4})):){0,6}(?:(?:[0-9a-f]{1,4})))?::))))
29
\] # an IPv6 address
30
)
31
(:[0-9]+)? # a port (optional)
32
(?:/ (?:[\pL\pN\-._\~!$&\'()*+,;=:@]|%%[0-9A-Fa-f]{2})* )* # a path
33
(?:\? (?:[\pL\pN\-._\~!$&\'()*+,;=:@/?]|%%[0-9A-Fa-f]{2})* )? # a query (optional)
34
(?:\# (?:[\pL\pN\-._\~!$&\'()*+,;=:@/?]|%%[0-9A-Fa-f]{2})* )? # a fragment (optional)
35
$~ixu'
;
36
$this->match=
true
;
37
}
42
protected
function
setParams
(array $params) {
43
parent::setParams($params);
44
$ref
= $this->relative ? str_replace(
'(%s)://'
,
'(?:(%s)://)?'
, $this->ref) :
$this->ref
;
45
$this->ref = sprintf(
$ref
, implode(
'|'
, $this->protocols));
46
}
52
public
function
asUI
(): array {
53
return [
'inputType'
=>
'url'
]+\array_merge_recursive(parent::
asUI
() , [
'rules'
=> [ [
'type'
=>
'url'
,
'prompt'
=>$this->
_getMessage
()] ]]);
54
}
55
56
}
57
Ubiquity\contents\validation\validators\Validator\_getMessage
_getMessage()
Definition
Validator.php:81
Ubiquity\contents\validation\validators\strings\RegexValidator
Validates a string with a regex Usage @validator("regex",pattern)
Definition
RegexValidator.php:14
Ubiquity\contents\validation\validators\strings\RegexValidator\$ref
$ref
Definition
RegexValidator.php:15
Ubiquity\contents\validation\validators\strings\UrlValidator
Validates an URL Usage @validator("url","constraints"=>["relative"=>false,"protocols"=>["http",...
Definition
UrlValidator.php:12
Ubiquity\contents\validation\validators\strings\UrlValidator\__construct
__construct()
Definition
UrlValidator.php:17
Ubiquity\contents\validation\validators\strings\UrlValidator\setParams
setParams(array $params)
Definition
UrlValidator.php:42
Ubiquity\contents\validation\validators\strings\UrlValidator\$protocols
$protocols
Definition
UrlValidator.php:14
Ubiquity\contents\validation\validators\strings\UrlValidator\$relative
$relative
Definition
UrlValidator.php:15
Ubiquity\contents\validation\validators\strings\UrlValidator\asUI
asUI()
{{}\Ubiquity\contents\validation\validators\ValidatorasUI()}
Definition
UrlValidator.php:52
Ubiquity\contents\validation\validators\strings
Definition
EmailValidator.php:3
C:
Users
myadd
Documents
GitHub
ubiquity-doc-api
vendor
phpmv
ubiquity
src
Ubiquity
contents
validation
validators
strings
UrlValidator.php
Generated on Sun Dec 10 2023 15:04:16 for
Ubiquity
by
doxygen
1.9.8