Skip to content

Commit e677a85

Browse files
authored
Merge pull request #48 from madapaja/mobile-optional
The need for MobileTwigModule has decreased, so we will make it an optional install
2 parents 0df8a84 + 49977cc commit e677a85

File tree

3 files changed

+19
-3
lines changed

3 files changed

+19
-3
lines changed

composer-require-checker.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"symbol-whitelist" : [
3-
"Mobile_Detect"
3+
"Mobile_Detect", "Detection\\MobileDetect"
44
],
55
"php-core-extensions" : [
66
"Core",
@@ -15,4 +15,4 @@
1515
"standard"
1616
],
1717
"scan-files" : []
18-
}
18+
}

composer.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@
1919
"bear/sunday": "^1.7",
2020
"bear/app-meta": "^1.8",
2121
"twig/twig": "^v3.15",
22-
"mobiledetect/mobiledetectlib": "^3.74.3",
2322
"ray/di": "^2.17",
2423
"ray/aop": "^2.17",
2524
"psr/log": "^3.0.2"
2625
},
2726
"require-dev": {
27+
"mobiledetect/mobiledetectlib": "^3.74.3",
2828
"phpunit/phpunit": "^9.6.21",
2929
"doctrine/annotations": "^1.14.4 || ^2.0",
3030
"bamarni/composer-bin-plugin": "^1.8.2"
@@ -66,5 +66,8 @@
6666
"bin-links": true,
6767
"forward-command": true
6868
}
69+
},
70+
"suggest": {
71+
"mobiledetect/mobiledetectlib": "MobileTwigModule"
6972
}
7073
}

src/MobileTwigModule.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,11 @@
44

55
namespace Madapaja\TwigModule;
66

7+
use Detection\MobileDetect;
78
use Ray\Di\AbstractModule;
9+
use RuntimeException;
10+
11+
use function class_exists;
812

913
/**
1014
* Provides TemplateFinderInterface and derived bindings
@@ -17,6 +21,15 @@
1721
*/
1822
class MobileTwigModule extends AbstractModule
1923
{
24+
public function __construct(AbstractModule $module)
25+
{
26+
if (! class_exists(MobileDetect::class)) {
27+
throw new RuntimeException('mobiledetect/mobiledetectlib is required for MobileTwigModule, please install it via composer. (composer require mobiledetect/mobiledetectlib)'); // @codeCoverageIgnore
28+
}
29+
30+
parent::__construct($module);
31+
}
32+
2033
/**
2134
* {@inheritDoc}
2235
*/

0 commit comments

Comments
 (0)