コード例 #1
0
 /**
  * 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
0
ファイル: Xen.php プロジェクト: sircamp/xenapi
 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
0
ファイル: Valid.php プロジェクト: tourze/base
 /**
  * 是否为合格的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);
 }