Source of file DomainRule.php
Size: 1,734 Bytes - Last Modified: 2021-12-23T10:37:30+00:00
/var/www/docs.ssmods.com/process/src/src/Rules/DomainRule.php
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768 | <?php /** * This file is part of SilverWare. * * PHP version >=5.6.0 * * For full copyright and license information, please view the * LICENSE.md file that was distributed with this source code. * * @package SilverWare\Validator\Rules * @author Colin Tucker <colin@praxis.net.au> * @copyright 2017 Praxis Interactive * @license https://opensource.org/licenses/BSD-3-Clause BSD-3-Clause * @link https://github.com/praxisnetau/silverware-validator */ namespace SilverWare\Validator\Rules; use SilverWare\Validator\Rule; /** * An extension of the rule class for a domain rule. * * @package SilverWare\Validator\Rules * @author Colin Tucker <colin@praxis.net.au> * @copyright 2017 Praxis Interactive * @license https://opensource.org/licenses/BSD-3-Clause BSD-3-Clause * @link https://github.com/praxisnetau/silverware-validator */ class DomainRule extends Rule { /** * Define constants. */ const PATTERN_DOMAIN = '/^((localhost)|((?!\-)(?:[a-zA-Z\d\-]{0,62}[a-zA-Z\d]\.){1,126}(?!\d+)[a-zA-Z\d]{1,63}))$/'; /** * Defines the default type for the rule. * * @var string * @config */ private static $default_type = 'domain'; /** * Answers the test result of the validator rule on the given value. * * @param mixed $value * * @return boolean */ public function test($value) { return $value ? (boolean) preg_match(self::PATTERN_DOMAIN, $value) : true; } /** * Answers the default message for the rule. * * @return string */ public function getDefaultMessage() { return _t(__CLASS__ . '.DEFAULTMESSAGE', 'This value should be a valid domain name.'); } } |