11# Browserizr PHP
22
33[ ![ license] ( https://img.shields.io/badge/License-MIT-blue.svg )] ( https://github.com/dutchenkoOleg/node-w3c-validator/blob/master/LICENSE )
4- [ ![ WezomAgency] ( https://img.shields.io/badge/composer-require-orange.svg )] ( https://packagist.org/packages/wezom-agency/browserizr )
4+ [ ![ composer] ( https://img.shields.io/badge/composer-require-orange.svg )] ( https://packagist.org/packages/wezom-agency/browserizr )
5+ [ ![ npm] ( https://img.shields.io/badge/npm-install-orange.svg )] ( https://www.npmjs.com/package/browserizr )
56[ ![ WezomAgency] ( https://img.shields.io/badge/wezom-agency-red.svg )] ( https://github.com/WezomAgency )
67
78> ** Browserizr** is tiny library, that detects your browser
@@ -20,59 +21,45 @@ composer require wezom-agency/browserizr
2021
2122---
2223
23- ## Initalize
24+ ## Prev versions
2425
25- > _ * since 2.x version_
26- > ___ You must initialize the Browserizr before to use it___
26+ > _ please read:_
2727
28- ``` php
29- <?php
30-
31- // your app start code
32- // ...
33- use WezomAgency\Browserizr;
34-
35- // initialize Browserizr
36- Browserizr::detect();
37-
38- // use Browserizr in your app
39- // ...
40- ?>
41- ```
28+ - [ old-versions/README-2.x.md] ( https://github.com/WezomAgency/browserizr-php/blob/master/old-versions/README-2.x.md )
4229
4330---
4431
4532## API
4633
4734### List of built-in tests
4835
49- 1 . ` Browserizr::$is_android `
50- 1 . ` Browserizr::$is_android3 `
51- 1 . ` Browserizr::$is_android4 `
52- 1 . ` Browserizr::$is_android5 `
53- 1 . ` Browserizr::$is_android6 `
54- 1 . ` Browserizr::$is_android7 `
55- 1 . ` Browserizr::$is_android8 `
56- 1 . ` Browserizr::$is_blackberry `
57- 1 . ` Browserizr::$is_blackberry10 `
58- 1 . ` Browserizr::$is_edge `
59- 1 . ` Browserizr::$is_edge_android `
60- 1 . ` Browserizr::$is_edge_ios `
61- 1 . ` Browserizr::$is_ie `
62- 1 . ` Browserizr::$is_ie8 `
63- 1 . ` Browserizr::$is_ie9 `
64- 1 . ` Browserizr::$is_ie10 `
65- 1 . ` Browserizr::$is_ie11 `
66- 1 . ` Browserizr::$is_ipad `
67- 1 . ` Browserizr::$is_ipod `
68- 1 . ` Browserizr::$is_iphone `
69- 1 . ` Browserizr::$is_windows_phone `
70- 1 . ` Browserizr::$is_moz `
71- 1 . ` Browserizr::$is_opera `
72- 1 . ` Browserizr::$is_safari `
73- 1 . ` Browserizr::$is_chrome `
74- 1 . ` Browserizr::$is_mobile `
75- 1 . ` Browserizr::$is_desktop `
36+ 1 . ` Browserizr::detect()->isAndroid() `
37+ 1 . ` Browserizr::detect()->isAndroid3() `
38+ 1 . ` Browserizr::detect()->isAndroid4() `
39+ 1 . ` Browserizr::detect()->isAndroid5() `
40+ 1 . ` Browserizr::detect()->isAndroid6() `
41+ 1 . ` Browserizr::detect()->isAndroid7() `
42+ 1 . ` Browserizr::detect()->isAndroid8() `
43+ 1 . ` Browserizr::detect()->isBlackberry() `
44+ 1 . ` Browserizr::detect()->isBlackberry10() `
45+ 1 . ` Browserizr::detect()->isEdge() `
46+ 1 . ` Browserizr::detect()->isEdgeAndroid() `
47+ 1 . ` Browserizr::detect()->isEdgeIOS() `
48+ 1 . ` Browserizr::detect()->isIE() `
49+ 1 . ` Browserizr::detect()->isIE8() `
50+ 1 . ` Browserizr::detect()->isIE9() `
51+ 1 . ` Browserizr::detect()->isIE10() `
52+ 1 . ` Browserizr::detect()->isIE11() `
53+ 1 . ` Browserizr::detect()->isIPad() `
54+ 1 . ` Browserizr::detect()->isIPod() `
55+ 1 . ` Browserizr::detect()->isIPhone() `
56+ 1 . ` Browserizr::detect()->isWindowsPhone() `
57+ 1 . ` Browserizr::detect()->isMoz() `
58+ 1 . ` Browserizr::detect()->isOpera() `
59+ 1 . ` Browserizr::detect()->isSafari() `
60+ 1 . ` Browserizr::detect()->isChrome() `
61+ 1 . ` Browserizr::detect()->isMobile() `
62+ 1 . ` Browserizr::detect()->isDesktop() `
7663
7764_ Usage examples:_
7865
@@ -82,26 +69,27 @@ _Usage examples:_
8269use WezomAgency\Browserizr;
8370
8471?>
85- <?php if (Browserizr::$is_chrome ) { ?>
72+ <?php if (Browserizr::detect()->isChrome() ) { ?>
8673 <div class =" alert" >Chrome is here, baby!!!</div >
8774<?php } ?>
8875
8976```
9077
9178---
9279
93- ### Static methods
80+ ### Generate css classes
9481
95- #### ` add_classes( $tests, $css_prefix = "") `
82+ #### ` Browserizr::detect()->cssClasses( $tests, $cssPrefix = "", $toString = true): array|string `
9683
9784> Create string with CSS classes
9885
9986_ Parameters:_
10087
10188Name | Data type | Default value | Description
10289 --- | --- | --- | ---
103- ` $tests ` | ` string[] ` | | array of wanted tests
104- ` $css_prefix ` | ` string ` | ` "" ` | custom prefix for CSS class name
90+ ` $tests ` | ` string[] ` | | array of wanted tests, each name - test name without ` is ` prefix
91+ ` $cssPrefix ` | ` string ` | ` "" ` | custom prefix for CSS class name
92+ ` $toString ` | ` bool ` | ` true ` | implode resulted array and return as string;
10593
10694_ Usage examples:_
10795
@@ -112,7 +100,7 @@ use WezomAgency\Browserizr;
112100
113101?>
114102<!DOCTYPE html>
115- <html class =" <?= Browserizr::add_classes(['mobile ', 'desktop ']); ?>" >
103+ <html class =" <?= Browserizr::detect()->cssClasses(['Mobile ', 'Desktop ']); ?>" >
116104 <head >...</head >
117105 <body >...</body >
118106</html >
@@ -130,7 +118,7 @@ use WezomAgency\Browserizr;
130118
131119?>
132120<!DOCTYPE html>
133- <html class =" <?= Browserizr::add_classes(['mobile ', 'desktop '], 'browserizr-'); ?>" >
121+ <html class =" <?= Browserizr::detect()->cssClasses(['Mobile ', 'Desktop '], 'browserizr-'); ?>" >
134122 <head >...</head >
135123 <body >...</body >
136124</html >
@@ -141,29 +129,34 @@ use WezomAgency\Browserizr;
141129
142130```
143131
144- #### ` detect($custom_user_agent = null) `
132+ ``` php
133+ <?php
145134
146- > re-checkout all detections
135+ use WezomAgency\Browserizr;
147136
148- _ Parameters:_
137+ $myCssClasses = Browserizr::detect()->cssClasses(['Mobile', 'Desktop'], '', false);
138+ // ... work with array, e.g. array_push() or array_combine() or whatever you want
149139
150- Name | Data type | Default value | Description
151- --- | --- | --- | ---
152- ` $custom_user_agent ` | ` string ` | ` $_SERVER['HTTP_USER_AGENT'] ` | string for tests
140+ ?>
141+ ```
153142
154- _ Usage examples:_
143+ ### Set custom UserAgent
144+
145+ by default Browserizr use ` $_SERVER['HTTP_USER_AGENT'] `
146+ you can set own string for UserAgent.
147+
148+ > ** Note**
149+ > if you needed to change agent - you must do it before use the Browserizr tests
155150
156151``` php
157152<?php
158153
159154use WezomAgency\Browserizr;
160155
161- Browserizr::detect('my_user_agent')
156+ Browserizr::detect()->setUserAgent('my own UserAgent string');
162157
163- ?>
164- <?php if (Browserizr::$is_edge_ios) { ?>
165- <div class =" alert" >Edge is here, baby! Yes, on iOS!</div >
166- <?php } ?>
158+ // then can test your browser correctly
159+ var_export(Browserizr::detect()->isWindowsPhone());
167160
168161```
169162
0 commit comments