From 49977cc6a7dfd7d9bdb87a516464957e327f3eba Mon Sep 17 00:00:00 2001 From: Akihito Koriyama Date: Sat, 23 Nov 2024 20:37:48 +0900 Subject: [PATCH] The need for MobileTwigModule has decreased, so we will make it an optional install. See https://github.com/madapaja/Madapaja.TwigModule/releases/tag/2.6.0 In order to use the MobileTwigModule, it is necessary to install mobiledetect/mobiledetectlib. Relocate `mobiledetect/mobiledetectlib` to "require-dev" in composer.json and implement a runtime check that throws an exception if the dependency is missing in MobileTwigModule. Additionally, add getInput method to ErrorPagerRenderer to handle input values from resource objects. --- composer-require-checker.json | 4 ++-- composer.json | 5 ++++- src/MobileTwigModule.php | 13 +++++++++++++ 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/composer-require-checker.json b/composer-require-checker.json index ad6a80c..f980cbf 100644 --- a/composer-require-checker.json +++ b/composer-require-checker.json @@ -1,6 +1,6 @@ { "symbol-whitelist" : [ - "Mobile_Detect" + "Mobile_Detect", "Detection\\MobileDetect" ], "php-core-extensions" : [ "Core", @@ -15,4 +15,4 @@ "standard" ], "scan-files" : [] -} \ No newline at end of file +} diff --git a/composer.json b/composer.json index 9b35c33..6382a38 100644 --- a/composer.json +++ b/composer.json @@ -19,12 +19,12 @@ "bear/sunday": "^1.7", "bear/app-meta": "^1.8", "twig/twig": "^v3.15", - "mobiledetect/mobiledetectlib": "^3.74.3", "ray/di": "^2.17", "ray/aop": "^2.17", "psr/log": "^3.0.2" }, "require-dev": { + "mobiledetect/mobiledetectlib": "^3.74.3", "phpunit/phpunit": "^9.6.21", "doctrine/annotations": "^1.14.4 || ^2.0", "bamarni/composer-bin-plugin": "^1.8.2" @@ -66,5 +66,8 @@ "bin-links": true, "forward-command": true } + }, + "suggest": { + "mobiledetect/mobiledetectlib": "MobileTwigModule" } } diff --git a/src/MobileTwigModule.php b/src/MobileTwigModule.php index 3116e62..1aabefb 100644 --- a/src/MobileTwigModule.php +++ b/src/MobileTwigModule.php @@ -4,7 +4,11 @@ namespace Madapaja\TwigModule; +use Detection\MobileDetect; use Ray\Di\AbstractModule; +use RuntimeException; + +use function class_exists; /** * Provides TemplateFinderInterface and derived bindings @@ -17,6 +21,15 @@ */ class MobileTwigModule extends AbstractModule { + public function __construct(AbstractModule $module) + { + if (! class_exists(MobileDetect::class)) { + throw new RuntimeException('mobiledetect/mobiledetectlib is required for MobileTwigModule, please install it via composer. (composer require mobiledetect/mobiledetectlib)'); // @codeCoverageIgnore + } + + parent::__construct($module); + } + /** * {@inheritDoc} */