From b90b824013e80ebbacd70a455f0241ef85a5c620 Mon Sep 17 00:00:00 2001 From: Joshua Estes Date: Mon, 23 Oct 2023 11:44:09 -0400 Subject: [PATCH 1/4] Exploring new component for checking user agent strings --- .../Component/UserAgent/.gitattributes | 4 ++ src/SonsOfPHP/Component/UserAgent/.gitignore | 3 ++ src/SonsOfPHP/Component/UserAgent/LICENSE | 19 +++++++ src/SonsOfPHP/Component/UserAgent/README.md | 18 +++++++ .../UserAgent/UserAgentFactoryInterface.php | 15 ++++++ .../UserAgent/UserAgentInterface.php | 19 +++++++ .../UserAgent/UserAgentProviderInterface.php | 13 +++++ .../Component/UserAgent/composer.json | 52 +++++++++++++++++++ 8 files changed, 143 insertions(+) create mode 100644 src/SonsOfPHP/Component/UserAgent/.gitattributes create mode 100644 src/SonsOfPHP/Component/UserAgent/.gitignore create mode 100644 src/SonsOfPHP/Component/UserAgent/LICENSE create mode 100644 src/SonsOfPHP/Component/UserAgent/README.md create mode 100644 src/SonsOfPHP/Component/UserAgent/UserAgentFactoryInterface.php create mode 100644 src/SonsOfPHP/Component/UserAgent/UserAgentInterface.php create mode 100644 src/SonsOfPHP/Component/UserAgent/UserAgentProviderInterface.php create mode 100644 src/SonsOfPHP/Component/UserAgent/composer.json diff --git a/src/SonsOfPHP/Component/UserAgent/.gitattributes b/src/SonsOfPHP/Component/UserAgent/.gitattributes new file mode 100644 index 00000000..84c7add0 --- /dev/null +++ b/src/SonsOfPHP/Component/UserAgent/.gitattributes @@ -0,0 +1,4 @@ +/Tests export-ignore +/phpunit.xml.dist export-ignore +/.gitattributes export-ignore +/.gitignore export-ignore diff --git a/src/SonsOfPHP/Component/UserAgent/.gitignore b/src/SonsOfPHP/Component/UserAgent/.gitignore new file mode 100644 index 00000000..5414c2c6 --- /dev/null +++ b/src/SonsOfPHP/Component/UserAgent/.gitignore @@ -0,0 +1,3 @@ +composer.lock +phpunit.xml +vendor/ diff --git a/src/SonsOfPHP/Component/UserAgent/LICENSE b/src/SonsOfPHP/Component/UserAgent/LICENSE new file mode 100644 index 00000000..d950b8dd --- /dev/null +++ b/src/SonsOfPHP/Component/UserAgent/LICENSE @@ -0,0 +1,19 @@ +Copyright 2022 Joshua Estes + +Permission is hereby granted, free of charge, to any person obtaining a copy of +this software and associated documentation files (the "Software"), to deal in +the Software without restriction, including without limitation the rights to +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies +of the Software, and to permit persons to whom the Software is furnished to do +so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/src/SonsOfPHP/Component/UserAgent/README.md b/src/SonsOfPHP/Component/UserAgent/README.md new file mode 100644 index 00000000..3c9e3fac --- /dev/null +++ b/src/SonsOfPHP/Component/UserAgent/README.md @@ -0,0 +1,18 @@ +Sons of PHP - User Agent Component +================================== + +## Learn More + +* [Documentation][docs] +* [Contributing][contributing] +* [Report Issues][issues] and [Submit Pull Requests][pull-requests] in the + [Mother Repository][mother-repo] +* Get Help & Support using [Discussions][discussions] or [Discord][discord] + +[discussions]: https://github.com/orgs/SonsOfPHP/discussions +[mother-repo]: https://github.com/SonsOfPHP/sonsofphp +[contributing]: https://docs.sonsofphp.com/contributing/ +[docs]: https://docs.sonsofphp.com/components/user-agent/ +[issues]: https://github.com/SonsOfPHP/sonsofphp/issues?q=is%3Aopen+is%3Aissue+label%3AUserAgent +[pull-requests]: https://github.com/SonsOfPHP/sonsofphp/pulls?q=is%3Aopen+is%3Apr+label%3AUserAgent +[discord]: https://discord.gg/sdVxNhFqND diff --git a/src/SonsOfPHP/Component/UserAgent/UserAgentFactoryInterface.php b/src/SonsOfPHP/Component/UserAgent/UserAgentFactoryInterface.php new file mode 100644 index 00000000..fd0f6e5d --- /dev/null +++ b/src/SonsOfPHP/Component/UserAgent/UserAgentFactoryInterface.php @@ -0,0 +1,15 @@ + + */ +interface UserAgentFactoryInterface +{ + public static function createFromGlobals(): UserAgentInterface; + + // createFromRequest(RequestInterface $request); <- PSR-7 Request +} diff --git a/src/SonsOfPHP/Component/UserAgent/UserAgentInterface.php b/src/SonsOfPHP/Component/UserAgent/UserAgentInterface.php new file mode 100644 index 00000000..cfea363f --- /dev/null +++ b/src/SonsOfPHP/Component/UserAgent/UserAgentInterface.php @@ -0,0 +1,19 @@ + + */ +interface UserAgentInterface extends \Stringable +{ + public function isBot(): bool; + + public function isMobile(): bool; + + public function isTablet(): bool; + + public function isDesktop(): bool; +} diff --git a/src/SonsOfPHP/Component/UserAgent/UserAgentProviderInterface.php b/src/SonsOfPHP/Component/UserAgent/UserAgentProviderInterface.php new file mode 100644 index 00000000..e729181d --- /dev/null +++ b/src/SonsOfPHP/Component/UserAgent/UserAgentProviderInterface.php @@ -0,0 +1,13 @@ + + */ +interface UserAgentProviderInterface +{ + public function getForUA(string $ua): UserAgentInterface; +} diff --git a/src/SonsOfPHP/Component/UserAgent/composer.json b/src/SonsOfPHP/Component/UserAgent/composer.json new file mode 100644 index 00000000..e6f0d8c0 --- /dev/null +++ b/src/SonsOfPHP/Component/UserAgent/composer.json @@ -0,0 +1,52 @@ +{ + "name": "sonsofphp/user-agent", + "type": "library", + "description": "Provides more details about the browser the end user is currently using.", + "keywords": [ + "user-agent", + "browser" + ], + "homepage": "https://github.com/SonsOfPHP/user-agent", + "license": "MIT", + "authors": [ + { + "name": "Joshua Estes", + "email": "joshua@sonsofphp.com" + } + ], + "support": { + "issues": "https://github.com/SonsOfPHP/sonsofphp/issues", + "forum": "https://github.com/orgs/SonsOfPHP/discussions", + "docs": "https://docs.sonsofphp.com", + "chat": "https://discord.gg/sdVxNhFqND" + }, + "autoload": { + "psr-4": { + "SonsOfPHP\\Component\\UserAgent\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "minimum-stability": "dev", + "prefer-stable": true, + "require": { + "php": ">=8.1" + }, + "extra": { + "sort-packages": true, + "branch-alias": { + "dev-main": "0.3.x-dev" + } + }, + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/JoshuaEstes" + }, + { + "type": "tidelift", + "url": "https://tidelift.com/subscription/pkg/packagist-sonsofphp-sonsofphp" + } + ] +} From d3a568b0300b37eb44cfce8aa9bdc97cb74cf973 Mon Sep 17 00:00:00 2001 From: Joshua Estes Date: Mon, 23 Oct 2023 13:22:32 -0400 Subject: [PATCH 2/4] updates --- .../Component/UserAgent/UserAgentException.php | 12 ++++++++++++ .../Component/UserAgent/UserAgentInterface.php | 2 +- 2 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 src/SonsOfPHP/Component/UserAgent/UserAgentException.php diff --git a/src/SonsOfPHP/Component/UserAgent/UserAgentException.php b/src/SonsOfPHP/Component/UserAgent/UserAgentException.php new file mode 100644 index 00000000..1452ec40 --- /dev/null +++ b/src/SonsOfPHP/Component/UserAgent/UserAgentException.php @@ -0,0 +1,12 @@ + + */ +class UserAgentException extends \Exception +{ +} diff --git a/src/SonsOfPHP/Component/UserAgent/UserAgentInterface.php b/src/SonsOfPHP/Component/UserAgent/UserAgentInterface.php index cfea363f..9ccf9ae4 100644 --- a/src/SonsOfPHP/Component/UserAgent/UserAgentInterface.php +++ b/src/SonsOfPHP/Component/UserAgent/UserAgentInterface.php @@ -7,7 +7,7 @@ /** * @author Joshua Estes */ -interface UserAgentInterface extends \Stringable +interface UserAgentInterface extends \Stringable, \JsonSerializable { public function isBot(): bool; From de5d6ed17f70744cd5009e7c5d21286677e1efec Mon Sep 17 00:00:00 2001 From: Joshua Estes Date: Thu, 30 Nov 2023 14:19:50 -0500 Subject: [PATCH 3/4] updates --- Makefile | 3 ++ bard.json | 8 +++ phpunit.xml.dist | 4 ++ .../Contract/UserAgent/.gitattributes | 2 + src/SonsOfPHP/Contract/UserAgent/.gitignore | 2 + src/SonsOfPHP/Contract/UserAgent/LICENSE | 19 +++++++ src/SonsOfPHP/Contract/UserAgent/README.md | 16 ++++++ .../UserAgent/UserAgentExceptionInterface.php | 10 ++++ .../UserAgent/UserAgentFactoryInterface.php | 2 +- .../UserAgent/UserAgentInterface.php | 2 +- .../UserAgent/UserAgentProviderInterface.php | 2 +- .../Contract/UserAgent/composer.json | 52 +++++++++++++++++++ 12 files changed, 119 insertions(+), 3 deletions(-) create mode 100644 src/SonsOfPHP/Contract/UserAgent/.gitattributes create mode 100644 src/SonsOfPHP/Contract/UserAgent/.gitignore create mode 100644 src/SonsOfPHP/Contract/UserAgent/LICENSE create mode 100644 src/SonsOfPHP/Contract/UserAgent/README.md create mode 100644 src/SonsOfPHP/Contract/UserAgent/UserAgentExceptionInterface.php rename src/SonsOfPHP/{Component => Contract}/UserAgent/UserAgentFactoryInterface.php (86%) rename src/SonsOfPHP/{Component => Contract}/UserAgent/UserAgentInterface.php (88%) rename src/SonsOfPHP/{Component => Contract}/UserAgent/UserAgentProviderInterface.php (82%) create mode 100644 src/SonsOfPHP/Contract/UserAgent/composer.json diff --git a/Makefile b/Makefile index 84a42c12..25fc48cb 100644 --- a/Makefile +++ b/Makefile @@ -70,6 +70,9 @@ test-money: phpunit test-pager: PHPUNIT_TESTSUITE=pager test-pager: phpunit +test-user-agent: PHPUNIT_TESTSUITE=user-agent +test-user-agent: phpunit + phpunit: XDEBUG_MODE=$(XDEBUG_MODE) \ $(PHP) \ diff --git a/bard.json b/bard.json index 8837d7fa..2d1af2bf 100644 --- a/bard.json +++ b/bard.json @@ -129,6 +129,14 @@ "path": "src/SonsOfPHP/Contract/Pager", "repository": "git@github.com:SonsOfPHP/pager-contract.git" }, + { + "path": "src/SonsOfPHP/Component/UserAgent", + "repository": "git@github.com:SonsOfPHP/user-agent.git" + }, + { + "path": "src/SonsOfPHP/Contract/UserAgent", + "repository": "git@github.com:SonsOfPHP/user-agent-contract.git" + }, { "path": "src/SonsOfPHP/Contract/Version", "repository": "git@github.com:SonsOfPHP/version-contract.git" diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 5ab54b33..36f09d9f 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -82,6 +82,10 @@ src/SonsOfPHP/Component/Pager/Tests + + src/SonsOfPHP/Component/UserAgent/Tests + + src/SonsOfPHP/Component/Version/Tests diff --git a/src/SonsOfPHP/Contract/UserAgent/.gitattributes b/src/SonsOfPHP/Contract/UserAgent/.gitattributes new file mode 100644 index 00000000..3a01b372 --- /dev/null +++ b/src/SonsOfPHP/Contract/UserAgent/.gitattributes @@ -0,0 +1,2 @@ +/.gitattributes export-ignore +/.gitignore export-ignore diff --git a/src/SonsOfPHP/Contract/UserAgent/.gitignore b/src/SonsOfPHP/Contract/UserAgent/.gitignore new file mode 100644 index 00000000..d8a7996a --- /dev/null +++ b/src/SonsOfPHP/Contract/UserAgent/.gitignore @@ -0,0 +1,2 @@ +composer.lock +vendor/ diff --git a/src/SonsOfPHP/Contract/UserAgent/LICENSE b/src/SonsOfPHP/Contract/UserAgent/LICENSE new file mode 100644 index 00000000..39238382 --- /dev/null +++ b/src/SonsOfPHP/Contract/UserAgent/LICENSE @@ -0,0 +1,19 @@ +Copyright 2022 to Present Joshua Estes + +Permission is hereby granted, free of charge, to any person obtaining a copy of +this software and associated documentation files (the "Software"), to deal in +the Software without restriction, including without limitation the rights to +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies +of the Software, and to permit persons to whom the Software is furnished to do +so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/src/SonsOfPHP/Contract/UserAgent/README.md b/src/SonsOfPHP/Contract/UserAgent/README.md new file mode 100644 index 00000000..aba5809c --- /dev/null +++ b/src/SonsOfPHP/Contract/UserAgent/README.md @@ -0,0 +1,16 @@ +Sons of PHP - User Agent Contract +================================= + +## Learn More + +* [Documentation][docs] +* [Contributing][contributing] +* [Report Issues][issues] and [Submit Pull Requests][pull-requests] in the [Mother Repository][mother-repo] +* Get Help & Support using [Discussions][discussions] + +[discussions]: https://github.com/orgs/SonsOfPHP/discussions +[mother-repo]: https://github.com/SonsOfPHP/sonsofphp +[contributing]: https://docs.sonsofphp.com/contributing/ +[docs]: https://docs.sonsofphp.com/contracts/user-agent/ +[issues]: https://github.com/SonsOfPHP/sonsofphp/issues?q=is%3Aopen+is%3Aissue+label%3AUserAgent +[pull-requests]: https://github.com/SonsOfPHP/sonsofphp/pulls?q=is%3Aopen+is%3Apr+label%3AUserAgent diff --git a/src/SonsOfPHP/Contract/UserAgent/UserAgentExceptionInterface.php b/src/SonsOfPHP/Contract/UserAgent/UserAgentExceptionInterface.php new file mode 100644 index 00000000..049293d7 --- /dev/null +++ b/src/SonsOfPHP/Contract/UserAgent/UserAgentExceptionInterface.php @@ -0,0 +1,10 @@ + + */ +interface UserAgentExceptionInterface {} diff --git a/src/SonsOfPHP/Component/UserAgent/UserAgentFactoryInterface.php b/src/SonsOfPHP/Contract/UserAgent/UserAgentFactoryInterface.php similarity index 86% rename from src/SonsOfPHP/Component/UserAgent/UserAgentFactoryInterface.php rename to src/SonsOfPHP/Contract/UserAgent/UserAgentFactoryInterface.php index fd0f6e5d..83bebd34 100644 --- a/src/SonsOfPHP/Component/UserAgent/UserAgentFactoryInterface.php +++ b/src/SonsOfPHP/Contract/UserAgent/UserAgentFactoryInterface.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace SonsOfPHP\Component\UserAgent; +namespace SonsOfPHP\Contract\UserAgent; /** * @author Joshua Estes diff --git a/src/SonsOfPHP/Component/UserAgent/UserAgentInterface.php b/src/SonsOfPHP/Contract/UserAgent/UserAgentInterface.php similarity index 88% rename from src/SonsOfPHP/Component/UserAgent/UserAgentInterface.php rename to src/SonsOfPHP/Contract/UserAgent/UserAgentInterface.php index 9ccf9ae4..9a63dc61 100644 --- a/src/SonsOfPHP/Component/UserAgent/UserAgentInterface.php +++ b/src/SonsOfPHP/Contract/UserAgent/UserAgentInterface.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace SonsOfPHP\Component\UserAgent; +namespace SonsOfPHP\Contract\UserAgent; /** * @author Joshua Estes diff --git a/src/SonsOfPHP/Component/UserAgent/UserAgentProviderInterface.php b/src/SonsOfPHP/Contract/UserAgent/UserAgentProviderInterface.php similarity index 82% rename from src/SonsOfPHP/Component/UserAgent/UserAgentProviderInterface.php rename to src/SonsOfPHP/Contract/UserAgent/UserAgentProviderInterface.php index e729181d..ba01bfd4 100644 --- a/src/SonsOfPHP/Component/UserAgent/UserAgentProviderInterface.php +++ b/src/SonsOfPHP/Contract/UserAgent/UserAgentProviderInterface.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace SonsOfPHP\Component\UserAgent; +namespace SonsOfPHP\Contract\UserAgent; /** * @author Joshua Estes diff --git a/src/SonsOfPHP/Contract/UserAgent/composer.json b/src/SonsOfPHP/Contract/UserAgent/composer.json new file mode 100644 index 00000000..f6e42fb0 --- /dev/null +++ b/src/SonsOfPHP/Contract/UserAgent/composer.json @@ -0,0 +1,52 @@ +{ + "name": "sonsofphp/user-agent-contract", + "type": "library", + "description": "", + "keywords": [ + "abstractions", + "contracts", + "decoupling", + "interfaces", + "interoperability", + "standards" + ], + "homepage": "https://github.com/SonsOfPHP/user-agent-contract", + "license": "MIT", + "authors": [ + { + "name": "Joshua Estes", + "email": "joshua@sonsofphp.com" + } + ], + "support": { + "issues": "https://github.com/SonsOfPHP/sonsofphp/issues", + "forum": "https://github.com/orgs/SonsOfPHP/discussions", + "docs": "https://docs.sonsofphp.com" + }, + "autoload": { + "psr-4": { + "SonsOfPHP\\Contract\\UserAgent\\": "" + } + }, + "minimum-stability": "dev", + "prefer-stable": true, + "require": { + "php": ">=8.1" + }, + "extra": { + "sort-packages": true, + "branch-alias": { + "dev-main": "0.3.x-dev" + } + }, + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/JoshuaEstes" + }, + { + "type": "tidelift", + "url": "https://tidelift.com/subscription/pkg/packagist-sonsofphp-sonsofphp" + } + ] +} From 980990adb266d1a93e6563bba28f7f0b6df9072d Mon Sep 17 00:00:00 2001 From: Joshua Estes Date: Tue, 23 Jan 2024 12:46:32 -0500 Subject: [PATCH 4/4] meh --- phpunit.xml.dist | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 39f402ff..c7c3d401 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -98,9 +98,9 @@ src/SonsOfPHP/Component/Pager/Tests - - src/SonsOfPHP/Component/UserAgent/Tests - + + + src/SonsOfPHP/Component/Version/Tests