Browse Source

dev 2020-11

Max F 5 years ago
parent
commit
2066665737
2 changed files with 50 additions and 11 deletions
  1. 41 10
      src/Http/Request.php
  2. 9 1
      src/Http/UserAgent.php

+ 41 - 10
src/Http/Request.php

@@ -130,16 +130,6 @@ class Request
 		return $this->method;
 	}
 
-	public function isGet()
-	{
-		return ($this->method == 'GET');
-	}
-
-	public function isPost()
-	{
-		return ($this->method == 'POST');
-	}
-
 	public function getServerIp()
 	{
 		return $this->SERVER['SERVER_ADDR'];
@@ -175,6 +165,42 @@ class Request
 		$this->route = $route;
 	}
 
+
+	public function isGet()
+	{
+		return ($this->method == 'GET');
+	}
+
+	public function isPost()
+	{
+		return ($this->method == 'POST');
+	}
+
+	public function isHead()
+	{
+		return ($this->method == 'HEAD');
+	}
+
+	public function isOptions()
+	{
+		return ($this->method == 'OPTIONS');
+	}
+
+	public function isPut()
+	{
+		return ($this->method == 'PUT');
+	}
+
+	public function isDelete()
+	{
+		return ($this->method == 'DELETE');
+	}
+
+	public function isPatch()
+	{
+		return ($this->method == 'PATCH');
+	}
+
 	public function isSecure()
 	{
 		return (! empty($this->SERVER['HTTPS']) && $this->SERVER['HTTPS'] == 'On')
@@ -188,6 +214,11 @@ class Request
 		return UserAgent::isBot($this->user_agent);
 	}
 
+	public function isMobile()
+	{
+		return UserAgent::isMobile($this->user_agent);
+	}
+
 	public function isAjax()
 	{
 		return (! empty($request->SERVER['HTTP_X_REQUESTED_WITH']) && $request->SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest');

+ 9 - 1
src/Http/UserAgent.php

@@ -1140,7 +1140,15 @@ class UserAgent
 
 	public static function isBot($user_agent) 
 	{
-		return in_array($user_agent, self::$bots_users_agents);
+		$ua_infos = self::analyseUserAgent($user_agent);
+		return ! empty($ua_infos['robot']) || in_array($user_agent, self::$bots_users_agents);
+	}
+
+
+	public static function isMobile($user_agent) 
+	{
+		$ua_infos = self::analyseUserAgent($user_agent);
+		return ! empty($ua_infos['mobile']);
 	}