I suggest we depreciate JBrowser in favor of using the framework webclient going forward
in depreciating JBrowser for 4.0 we will need to rewrite some parts of JHtml that currently use JBrowser so they will work with the framework Joomla\Application\Web\WebClient
What is the community's thoughts on this???
one library for one task
we currently are (poorly) maintaining two similar libraries that do basically the same thing. The code is not the same and the function outputs are different in both classes, even though they have the same tasks.
duplicated code is bad, we should be DRY (do not repeat yourself)
Discussions on replacing all the browser detection with a 3rd party library should be separate from this discussion.
Labels |
Added:
?
|
Category | ⇒ | Libraries |
Do you think it would be worth replacing Joomla\Application\Web\WebClient with JBrowser?
note: It would make a bit of a mess in the framework since the two classes have different return values.
Status | New | ⇒ | Discussion |
Title |
|
Title |
|
Looking at the current state of Joomla\Application\Web\WebClient
I don't think deprecating JBrowser
is a very good idea. You have to use some black magic like PHP to "stringify" the return values of WebClient
which are integers only, where JBrowser
returns some very convenient values like "unix", "mac", "chrome", "mozilla" etc.
You have to use some black magic like PHP to "stringify" the return values of WebClient which are integers only
It's not an issue unique to this class. Anything which uses constants to represent values can have this issue where the constant's value doesn't necessarily align to what the code is passing. WebClient::MAC
will always be integer 7 (or if we took the B/C break and changed them to strings whatever string value it's assigned), but you can use the constant to read the value versus hardcoding a 7 into your code and having to leave inline comments about what it actually represents.
It's not an issue unique to this class. Anything which uses constants to represent values can have this issue where the constant's value doesn't necessarily align to what the code is passing.
I do understand that it might be better to prefer constants in terms of performance, I just wanted to point out that currently there seems to be missing a method for extension-developer friendly output. Deprecating JBrowser
in favor of the current verison of WebClient
would easily result in developers repeating themselves (instead of DRY in the core) or even worse: using third party libraries.
Another thing: if you add some functionality e.g. in detection of browsers this might result in problems even if there are hardcoded values always staying the same (until one day they won't :) ).
Lets say an update is adding constant 42 as return value for a fork of a browser. This would force every extension/template developer to review or rework their code.
Of course you could do something like: array_shift( (new ReflectionClass( 'JApplicationWebClient' ) ) ->getConstants() );
but I guess this would not perform very well.
Lets say an update is adding constant 42 as return value for a fork of a browser. This would force every extension/template developer to review or rework their code.
And it'd be the same if a new return value were added into JBrowser
which uses "developer friendly" strings if your code was interested in a behavior for that browser. So I don't think that scenario strengthens or weakens the case for constants versus string values that aren't declared somewhere (as in right now you basically have to reverse engineer JBrowser
to know what you can get from it, at least with a list of constants you have a set of known values).
as in right now you basically have to reverse engineer JBrowser to know what you can get from it, at least with a list of constants you have a set of known values
I totally agree with you. I was never saying JBrowser
was a better class, but it's easier to handle since it provides human-readable results. I'd be totally satisfied if there was a built in ability to resolve the name of the constants in WebClient
and I guess others would be too.
In my case I'm just logging values like browser, version and OS which is hard to read if you get constants only.
Honestly, I don't know if that's something that's practical in PHP since constants are just a code shortcut to a value (everything internally uses that constant's value, the constant's just there for readability). You can use Reflection and come up with methods to help make that work on a class basis, but global constants would never work that well with a resolver since many share the same value.
At this point, I'd suggest whichever of the two classes is in better shape is the one we should move forward with and the other one deprecated and dropped with next major. Internal design decisions aside (i.e. constant values), I'd rather focus on whichever one is more functionally up to par for the task at hand and we can address the shortcomings in that class and if necessary correct design issues.
Anyone?
I mean JBrowser covers more cases. The question is does WebClient cover the common cases - because most people care about desktop vs mobile etc. Not what the specific browser is....
I think they both cover the same small set of browsers (at least from what I remember from the minor code fixes I've done to both of them)
both cover desktop vs mobile
Labels |
Added:
?
|
Here is a quick properties comparison between the two (I think I got everything in here)
Still need to do a function comparison to get the full picture
framework Joomla\Application\Web\WebClient | Description | JBrowser aka Joomla\CMS\Environment | Description |
---|---|---|---|
$platform | integer The detected platform on which the web client runs. | $platform | string Platform the browser is running on |
$mobile | boolean True if the web client is a mobile device. | $mobile | boolean Is this a mobile browser? |
$engine | integer The detected rendering engine used by the web client. | - | - |
$browser | integer The detected browser used by the web client. | $browser | string Browser name |
- | - | $majorVersion | integer Major version number |
- | - | $minorVersion | integer Minor version number |
$browserVersion | string The detected browser version used by the web client. | - | - |
$languages | array The priority order detected accepted languages for the client. | - | - |
$encodings | array The priority order detected accepted encodings for the client. | - | - |
$userAgent | string The web client's user agent string. | $agent | string Full user agent string. |
- | - | $lowerAgent | string Lower-case user agent string |
- | - | $accept | string HTTP_ACCEPT string |
- | - | $acceptParsed | array Parsed HTTP_ACCEPT string |
$acceptEncoding | string The web client's accepted encoding string. | - | - |
$acceptLanguage | string The web client's accepted languages string. | - | - |
$detection | array An array of flags determining whether or not a detection routine has been run. | - | - |
$robot | boolean True if the web client is a robot | - | - |
- | - | $robots | array Known robots. |
$headers | array An array of all headers sent by client | - | - |
- | - | $images | List of viewable image MIME subtypes. This list of viewable images works for IE and Netscape/Mozilla. |
- | - | $instances | array Browser instances container. |
Status | Discussion | ⇒ | Closed |
Closed_Date | 0000-00-00 00:00:00 | ⇒ | 2018-07-30 00:17:20 |
Closed_By | ⇒ | photodude |
Here is a quick function comparison between the two (I think I got everything in here)
As best I can tell there is feature parody between the two, a few functions here and there are not in the other class. but the big things like mobile detection are in both.
framework Joomla\Application\Web\WebClient | Description | JBrowser aka Joomla\CMS\Environment | Description |
---|---|---|---|
__construct($userAgent = null, $acceptEncoding = null, $acceptLanguage = null) | Class constructor | __construct($userAgent = null, $accept = null) | Create a browser instance (constructor) |
__get($name) | Magic method to get an object property's value by name | getInstance($userAgent = null, $accept = null) | Returns the global Browser object, only creating it if it doesn't already exist |
detectBrowser($userAgent) | Detects the client browser and version in a user agent string. | getBrowser() | Retrieve the current browser |
- | - | setBrowser($browser) | Sets the current browser |
detectEncoding($acceptEncoding) | Method to detect the accepted response encoding by the client | - | - |
detectEngine($userAgent) | Detects the client rendering engine in a user agent string. | - | - |
detectLanguage($acceptLanguage) | Method to detect the accepted languages by the client. | - | - |
detectPlatform($userAgent) | Detects the client platform in a user agent string | getPlatform() | Return the currently matched platform |
- | - | _setPlatform() | Match the platform of the browser. |
detectRobot($userAgent) | Determines if the browser is a robot or not | isRobot() | Determines if the browser is a robot or not |
detectHeaders() | Fills internal array of headers | - | - |
- | - | match($userAgent = null, $accept = null) | Parses the user agent string and inititializes the object with all the known features and quirks for the given browser. |
- | - | identifyBrowserVersion() | Set browser version, not by engine version Fallback to use when no other method identify the engine version |
- | - | getMajor() | Retrieve the current browser's major version |
- | - | getMinor() | Retrieve the current browser's minor version |
- | - | getVersion() | Retrieve the current browser's version |
- | - | getAgentString() | Return the full browser agent string |
- | - | getHTTPProtocol() | Returns the server protocol in use on the current server |
- | - | isViewable($mimetype) | Determines if a browser can display a given MIME type |
- | - | isBrowser($browser) | Determine if the given browser is the same as the current |
- | - | isMobile() | Determines if the browser is mobile version or not. |
- | - | isSSLConnection() | Determine if we are using a secure (SSL) connection |
Status | Closed | ⇒ | New |
Closed_Date | 2018-07-30 00:17:20 | ⇒ | |
Closed_By | photodude | ⇒ |
Sorry, I fat fingered the keyboard. I didn't intend to close this, thus it's been reopened.
Status | New | ⇒ | Discussion |
Status changed from "New" to "Discussion".
Labels |
Added:
J3 Issue
|
Title |
|
Thank you for raising this issue.
Joomla 3 is now in security only mode with no further bug fixes or new features. It appears that this has already been addressed in Joomla 4 and it will now been closed.
If we are mistaken and this does apply to Joomla 4 please open a new issue (and reference this one if you wish) with updated details for testing in Joomla 4.
cc @zero-24
Status | Discussion | ⇒ | Closed |
Closed_Date | 0000-00-00 00:00:00 | ⇒ | 2022-08-23 13:48:12 |
Closed_By | ⇒ | zero-24 | |
Labels |
Added:
?
No Code Attached Yet
Removed: ? ? |
Labels |
Removed:
?
|
There's a lot of options here.
Joomla\Application\Web\WebClient
is honestly worse thanJBrowser
. I'm unconvinced that many (if any) people useJBrowser
parts ofJHtml
so honestly it comes down to the mobile detection, which is used more.