Closed warmbook closed 1 year ago
I don't know why the current behavior is like this.
But it comes from CI3 and the parameter is $key
that specifies the Config array key.
Therefore, the usage is:
$agent->isBrowser('MicroMessenger')
// or
$agent->getBrowser() === 'WeChat`
PHP Version
8.1
CodeIgniter4 Version
4.3.1
CodeIgniter4 Installation Method
Manual (zip or tar.gz)
Which operating systems have you tested for this bug?
Linux
Which server did you use?
fpm-fcgi
Database
No response
What happened?
I add one row to the property 'browsers' of 'Config\UserAgents' class, the key is 'MicroMessenger' and the value is 'WeChat'. Then I want to know whether a HTTP request is from WeChat browser, so I called the 'isBrowser' method in my service code and the only argument is 'WeChat'. But it always returns false. I read the first floor code and find that the 'isBrowser' method only check if the key is exist.
Steps to Reproduce
Add one row to the property 'browsers' of 'Config\UserAgents' class, the key is 'MicroMessenger' and the value is 'WeChat'. Then call the 'isBrowser' method with 'WeChat'.
Expected Output
Return true when the header 'user-agent' contains 'MicroMessenger'.
Anything else?
Sometimes, we only want to know whether the HTTP request is from some browser, and don't care which version it is. So why not compare the argument '$key' with the property 'browser'? Just like this: