-
-
Notifications
You must be signed in to change notification settings - Fork 127
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #50 from donatj/constants
1.x Release Development
- Loading branch information
Showing
17 changed files
with
809 additions
and
235 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?php | ||
|
||
require __DIR__ . '/../vendor/autoload.php'; | ||
|
||
$class = new ReflectionClass($argv[1]); | ||
|
||
echo "Predefined helper constants from `{$class->getName()}`\n\n"; | ||
|
||
echo "| Constant | {$argv[2]} | \n|----------|----------| \n"; | ||
|
||
foreach( $class->getConstants() as $constant => $value ) { | ||
echo "| `{$class->getShortName()}::{$constant}` | {$value} | \n"; | ||
} | ||
|
||
echo "\n"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
<mddoc> | ||
<docpage target="README.md" autoloader="psr0" autoloader-root="src"> | ||
<section title="PHP User Agent Parser"> | ||
<text><![CDATA[ | ||
[![Join the chat at https://gitter.im/PhpUserAgentParser/Lobby](https://badges.gitter.im/PhpUserAgentParser/Lobby.svg)](https://gitter.im/PhpUserAgentParser/Lobby?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) | ||
]]></text> | ||
<badge-poser type="version"/> | ||
<badge-poser type="downloads"/> | ||
<badge-poser type="license"/> | ||
<badge-travis name="donatj/phpUserAgent"/> | ||
<badge-github-action name="donatj/phpUserAgent" workflow="CI"/> | ||
<section title="What It Is"> | ||
<text><![CDATA[ | ||
A simple, streamlined PHP user-agent parser! | ||
Licensed under the MIT license: http://www.opensource.org/licenses/mit-license.php | ||
]]></text> | ||
</section> | ||
<section title="Upgrading to `1.*`"> | ||
<text><![CDATA[ | ||
The new `1.*` release **does not break compatibility** with `0.*` and nothing need to change to upgrade. However, the global `parse_user_agent` is now deprecated; it has been replaced with the namespaced `\donatj\UserAgent\parse_user_agent` and functions exactly the same. You can easily replace any existing call to `parse_user_agent` with `\donatj\UserAgent\parse_user_agent` | ||
In addition, 1.x adds a convenience object wrapper you may use should you prefer. More information on this is in the Usage section below. | ||
]]></text> | ||
</section> | ||
<section title="Why Use This"> | ||
<text><![CDATA[ | ||
You have your choice in user-agent parsers. This one detects **all modern browsers** in a very light, quick, understandable fashion. | ||
It is less than 200 lines of code, and consists of just three regular expressions! | ||
It can also correctly identify exotic versions of IE others fail on. | ||
It offers 100% unit test coverage, is installable via Composer, and is very easy to use. | ||
]]></text> | ||
</section> | ||
<section title="What It Does Not Do"> | ||
<text><![CDATA[ | ||
This is not meant as a browser "knowledge engine" but rather a simple parser. Anything not adequately provided directly by the user agent string itself will simply not be provided by this. | ||
]]></text> | ||
|
||
<section title="OS Versions"> | ||
<text><![CDATA[ | ||
User-agent strings **are not** a reliable source of OS Version! | ||
- Many agents simply don't send the information. | ||
- Others provide varying levels of accuracy. | ||
- Parsing Windows versions alone almost nearly doubles the size of the code. | ||
I'm much more interested in keeping this thing *tiny* and accurate than adding niché features and would rather focus on things that can be **done well**. | ||
All that said, there is the start of a [branch to do it](https://github.com/donatj/PhpUserAgent/tree/os_version_detection) I created for a client if you want to poke it, I update it from time to time, but frankly if you need to *reliably detect OS Version*, using user-agent isn't the way to do it. I'd go with JavaScript. | ||
]]></text> | ||
</section> | ||
<section title="Undetectable Browsers"> | ||
<text><![CDATA[ | ||
- **Brave** - Brave is simply not differentiable from Chrome. This was a design decision on their part. | ||
]]></text> | ||
</section> | ||
</section> | ||
<section title="Requirements"> | ||
<composer-requires/> | ||
</section> | ||
<section title="Installing"> | ||
<text>PHP User Agent is available through Packagist via Composer.</text> | ||
<composer-install/> | ||
</section> | ||
<section title="Usage"> | ||
<text><![CDATA[ | ||
The classic procedural use is as simple as: | ||
```php | ||
$ua_info = parse_user_agent(); | ||
/* | ||
array( | ||
'platform' => '[Detected Platform]', | ||
'browser' => '[Detected Browser]', | ||
'version' => '[Detected Browser Version]', | ||
); | ||
*/ | ||
``` | ||
]]></text> | ||
<text><![CDATA[ | ||
The new object oriented wrapper form: | ||
```php | ||
$parser = new UserAgentParser(); | ||
$ua = $parser->parse(); | ||
// or | ||
$ua = $parser(); | ||
$ua->platform(); | ||
$ua->browser(); | ||
$ua->browserVersion(); | ||
``` | ||
]]></text> | ||
</section> | ||
<section title="Currently Detected Platforms"> | ||
<exec cmd="php .helpers/constants.php 'donatj\UserAgent\Platforms' 'Platform'"/> | ||
</section> | ||
<section title="Currently Detected Browsers"> | ||
<exec cmd="php .helpers/constants.php 'donatj\UserAgent\Browsers' 'Browser'"/> | ||
</section> | ||
<text><![CDATA[ | ||
More information is available at [Donat Studios](http://donatstudios.com/PHP-Parser-HTTP_USER_AGENT). | ||
]]></text> | ||
</section> | ||
</docpage> | ||
</mddoc> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
.PHONY: test | ||
test: | ||
./vendor/bin/phpunit --coverage-text | ||
|
||
.PHONY: generate | ||
generate: | ||
php bin/user_agent_sorter.php > tests/user_agents.tmp.json && mv tests/user_agents.tmp.json tests/user_agents.json | ||
php bin/constant_generator.php | ||
|
||
.PHONY: init | ||
init: | ||
php bin/init_user_agent.php > tests/user_agents.tmp.json && mv tests/user_agents.tmp.json tests/user_agents.json | ||
make generate |
Oops, something went wrong.