Completed
Push — master ( cde41c...73943a )
by Daniel
21s
created

src/Forms/WildcardDomainField.php (1 issue)

Labels
Severity
1
<?php
2
namespace SilverStripe\Subsites\Forms;
3
4
use SilverStripe\Forms\TextField;
5
6
/**
7
 * A text field that accepts only valid domain names, but allows the wildcard (*) character
8
 */
9
class WildcardDomainField extends TextField
10
{
11
    /**
12
     * Validate this field as a valid hostname
13
     *
14
     * @param Validator $validator
0 ignored issues
show
The type SilverStripe\Subsites\Forms\Validator was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
15
     * @return bool
16
     */
17
    public function validate($validator)
18
    {
19
        if ($this->checkHostname($this->Value())) {
20
            return true;
21
        }
22
23
        $validator->validationError(
24
            $this->getName(),
25
            _t('DomainNameField.INVALID_DOMAIN', 'Invalid domain name'),
26
            'validation'
27
        );
28
        return false;
29
    }
30
31
    /**
32
     * Check if the given hostname is valid.
33
     *
34
     * @param string $hostname
35
     * @return bool True if this hostname is valid
36
     */
37
    public function checkHostname($hostname)
38
    {
39
        return (bool)preg_match('/^([a-z0-9\*]+[\-\.\:])*([a-z0-9\*]+)$/', $hostname);
40
    }
41
42
    public function Type()
43
    {
44
        return 'text wildcarddomain';
45
    }
46
}
47