diff options
| author | Greg Roach <greg@subaqua.co.uk> | 2025-01-06 11:17:28 +0000 |
|---|---|---|
| committer | Greg Roach <greg@subaqua.co.uk> | 2025-01-06 12:47:39 +0000 |
| commit | cba20eb871932d4301cf65b62972e9fad19015ac (patch) | |
| tree | cd01401993662b123d9c58cfb865f03a6e1b001e /app/Factories | |
| parent | 24cb7547cb882ddc3e5b99cdff164831ef80290c (diff) | |
| download | webtrees-cba20eb871932d4301cf65b62972e9fad19015ac.tar.gz webtrees-cba20eb871932d4301cf65b62972e9fad19015ac.tar.bz2 webtrees-cba20eb871932d4301cf65b62972e9fad19015ac.zip | |
Add PhpService so we can mock/test calles to ini_get(), etc.
Diffstat (limited to 'app/Factories')
| -rw-r--r-- | app/Factories/ImageFactory.php | 10 | ||||
| -rw-r--r-- | app/Factories/SlugFactory.php | 11 |
2 files changed, 10 insertions, 11 deletions
diff --git a/app/Factories/ImageFactory.php b/app/Factories/ImageFactory.php index 734a5ba089..58b2a2c70f 100644 --- a/app/Factories/ImageFactory.php +++ b/app/Factories/ImageFactory.php @@ -26,6 +26,7 @@ use Fisharebest\Webtrees\Contracts\UserInterface; use Fisharebest\Webtrees\MediaFile; use Fisharebest\Webtrees\Mime; use Fisharebest\Webtrees\Registry; +use Fisharebest\Webtrees\Services\PhpService; use Fisharebest\Webtrees\Webtrees; use Imagick; use Intervention\Gif\Exceptions\NotReadableException; @@ -44,7 +45,6 @@ use Throwable; use function addcslashes; use function basename; -use function extension_loaded; use function get_class; use function implode; use function pathinfo; @@ -76,6 +76,10 @@ class ImageFactory implements ImageFactoryInterface 'image/webp' => 'webp', ]; + public function __construct(private PhpService $php_service) + { + } + /** * Send the original file - either inline or as a download. */ @@ -305,11 +309,11 @@ class ImageFactory implements ImageFactoryInterface */ protected function imageManager(): ImageManager { - if (extension_loaded(extension: 'imagick')) { + if ($this->php_service->extensionLoaded(extension: 'imagick')) { return new ImageManager(driver: new ImagickDriver()); } - if (extension_loaded(extension: 'gd')) { + if ($this->php_service->extensionLoaded(extension: 'gd')) { return new ImageManager(driver: new GdDriver()); } diff --git a/app/Factories/SlugFactory.php b/app/Factories/SlugFactory.php index bd3be82055..24bf39caa8 100644 --- a/app/Factories/SlugFactory.php +++ b/app/Factories/SlugFactory.php @@ -21,9 +21,9 @@ namespace Fisharebest\Webtrees\Factories; use Fisharebest\Webtrees\Contracts\SlugFactoryInterface; use Fisharebest\Webtrees\GedcomRecord; +use Fisharebest\Webtrees\Services\PhpService; use Transliterator; -use function extension_loaded; use function in_array; use function preg_replace; use function strip_tags; @@ -36,9 +36,9 @@ class SlugFactory implements SlugFactoryInterface { private Transliterator|null $transliterator = null; - public function __construct() + public function __construct(private PhpService $php_service) { - if (extension_loaded('intl')) { + if ($this->php_service->extensionLoaded(extension: 'intl')) { $ids = Transliterator::listIDs(); if ($ids !== false && in_array('Any-Latin', $ids, true) && in_array('Latin-ASCII', $ids, true)) { @@ -47,11 +47,6 @@ class SlugFactory implements SlugFactoryInterface } } - /** - * @param GedcomRecord $record - * - * @return string - */ public function make(GedcomRecord $record): string { $slug = strip_tags($record->fullName()); |
