Skip to content

Commit

Permalink
Merge pull request #48 from madapaja/mobile-optional
Browse files Browse the repository at this point in the history
The need for MobileTwigModule has decreased, so we will make it an optional install
  • Loading branch information
koriym authored Nov 23, 2024
2 parents 0df8a84 + 49977cc commit e677a85
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
4 changes: 2 additions & 2 deletions composer-require-checker.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"symbol-whitelist" : [
"Mobile_Detect"
"Mobile_Detect", "Detection\\MobileDetect"
],
"php-core-extensions" : [
"Core",
Expand All @@ -15,4 +15,4 @@
"standard"
],
"scan-files" : []
}
}
5 changes: 4 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -66,5 +66,8 @@
"bin-links": true,
"forward-command": true
}
},
"suggest": {
"mobiledetect/mobiledetectlib": "MobileTwigModule"
}
}
13 changes: 13 additions & 0 deletions src/MobileTwigModule.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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}
*/
Expand Down

0 comments on commit e677a85

Please sign in to comment.