本文整理匯總了PHP中Respect\Validation\Validator::ip方法的典型用法代碼示例。如果您正苦於以下問題:PHP Validator::ip方法的具體用法?PHP Validator::ip怎麽用?PHP Validator::ip使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Respect\Validation\Validator
的用法示例。
在下文中一共展示了Validator::ip方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: __invoke
/**
* RestrictRoute middleware invokable class.
*
* @param \Psr\Http\Message\ServerRequestInterface $request PSR7 request
* @param \Psr\Http\Message\ResponseInterface $response PSR7 response
* @param callable $next Next middleware
*
* @return \Psr\Http\Message\ResponseInterface
*/
public function __invoke($request, $response, $next)
{
$ipAddress = $request->getAttribute('ip_address');
if ($this->options['ip'] && !v::ip($this->options['ip'])->validate($ipAddress)) {
return $response->withStatus(401);
}
return $next($request, $response);
}
示例2: __construct
public function __construct($url, $user, $password)
{
if (!Validator::ip()->validate($url)) {
throw new \InvalidArgumentException("'url' value mast be an ipv4 address", 1);
}
if (!Validator::string()->validate($user)) {
throw new \InvalidArgumentException("'user' value mast be an non empty string", 1);
}
if (!Validator::string()->validate($password)) {
throw new \InvalidArgumentException("'password' value mast be an non empty string", 1);
}
$this->xenconnection = new XenConnection();
try {
$this->xenconnection->_setServer($url, $user, $password);
} catch (Exception $e) {
dd($e->getMessage());
}
}
示例3: ip
/**
* 是否為合格的IP地址
*
* @param string $value IP地址
* @param bool $allowPrivate 是否允許私有IP地址
* @return bool
*/
public static function ip($value, $allowPrivate = true)
{
return $allowPrivate ? Validator::ip()->validate($value) : Validator::ip(FILTER_FLAG_NO_PRIV_RANGE)->validate($value);
}