File tree Expand file tree Collapse file tree 2 files changed +40
-1
lines changed Expand file tree Collapse file tree 2 files changed +40
-1
lines changed Original file line number Diff line number Diff line change @@ -24,6 +24,28 @@ public function __construct($headers = null, $options = [])
24
24
}
25
25
}
26
26
27
+ /**
28
+ * Create a new Parser instance from a user agent string
29
+ *
30
+ * @param string $agent Required, a string containing the raw User-Agent
31
+ * @param array $options Optional, an array with configuration options
32
+ */
33
+ public static function fromUserAgent ($ agent , array $ options = [])
34
+ {
35
+ return new static ($ agent , $ options );
36
+ }
37
+
38
+ /**
39
+ * Create a new Parser instance from a user agent string
40
+ *
41
+ * @param array $headers Required, an array with all of the headers
42
+ * @param array $options Optional, an array with configuration options
43
+ */
44
+ public static function fromHeaders (array $ headers , array $ options = [])
45
+ {
46
+ return new static ($ headers , $ options );
47
+ }
48
+
27
49
/**
28
50
* Analyse the provided headers or User-Agent string
29
51
*
Original file line number Diff line number Diff line change @@ -40,10 +40,27 @@ public function testCreatingParserWithoutArgumentsAndCallAnalyse()
40
40
{
41
41
$ parser = new Parser ();
42
42
$ parser ->analyse ("Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0; InfoPath.1) " );
43
-
43
+
44
+ $ this ->assertTrue ($ parser ->isBrowser ('Internet Explorer ' , '= ' , '6.0 ' ));
45
+ }
46
+
47
+ public function testCreatingParserFromUserAgent ()
48
+ {
49
+ $ parser = Parser::fromUserAgent ('Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0; InfoPath.1) ' );
50
+
44
51
$ this ->assertTrue ($ parser instanceof \WhichBrowser \Parser);
45
52
46
53
$ this ->assertTrue ($ parser ->isBrowser ('Internet Explorer ' , '= ' , '6.0 ' ));
47
54
}
48
55
56
+ public function testCreatingParserFromHeaderArray ()
57
+ {
58
+ $ parser = Parser::fromHeaders ([
59
+ 'User-Agent ' => 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0; InfoPath.1) '
60
+ ]);
61
+
62
+ $ this ->assertTrue ($ parser instanceof \WhichBrowser \Parser);
63
+
64
+ $ this ->assertTrue ($ parser ->isBrowser ('Internet Explorer ' , '= ' , '6.0 ' ));
65
+ }
49
66
}
You can’t perform that action at this time.
0 commit comments