From 0e60c59a73e199d56c8f4617dc65eb5a4681330a Mon Sep 17 00:00:00 2001 From: Akihito Koriyama Date: Sun, 2 Jun 2024 17:33:14 +0900 Subject: [PATCH] Support PHP5.x migration MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This change ensures that projects created in PHP 5.x will work as they do in the latest PHP 8.3. Add CacheModule and version check in AppInjector The current commit introduces the CacheModule and inserts it in the AppInjector module's installation process. In addition, a function named 'checkVersion' has been created to ensure the existence of 'Doctrine\Common\Cache\FilesystemCache', failing which an exception is triggered. The check is performed during the AppInjector’s construction. This ensures that a doctrine cache ^1.0 is always present for the functioning of AppInjector. --- composer-require-checker.json | 2 +- src-deprecated/AppInjector.php | 11 +++++++++++ src-deprecated/Module/CacheModule.php | 26 ++++++++++++++++++++++++++ 3 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 src-deprecated/Module/CacheModule.php diff --git a/composer-require-checker.json b/composer-require-checker.json index cfb90ff2..1674ce8b 100644 --- a/composer-require-checker.json +++ b/composer-require-checker.json @@ -4,6 +4,6 @@ "static", "self", "parent", "array", "string", "int", "float", "bool", "iterable", "callable", "void", "object", "mixed", "Composer\\Autoload\\ClassLoader", "Doctrine\\Common\\Cache\\FilesystemCache", "Doctrine\\Common\\Cache\\PhpFileCache", - "BEAR\\Resource\\ReverseLinkInterface" + "BEAR\\Resource\\ReverseLinkInterface", "Doctrine\\Common\\Cache\\ArrayCache" ] } diff --git a/src-deprecated/AppInjector.php b/src-deprecated/AppInjector.php index 67c3e79b..f37bd420 100644 --- a/src-deprecated/AppInjector.php +++ b/src-deprecated/AppInjector.php @@ -6,6 +6,7 @@ use BEAR\AppMeta\AbstractAppMeta; use BEAR\AppMeta\Meta; +use BEAR\Package\Module\CacheModule; use Doctrine\Common\Cache\FilesystemCache; use Ray\Compiler\ScriptInjector; use Ray\Di\AbstractModule; @@ -13,6 +14,7 @@ use Ray\Di\Injector; use Ray\Di\InjectorInterface; use Ray\Di\Name; +use RuntimeException; /** * @deprecated @@ -58,6 +60,7 @@ final class AppInjector implements InjectorInterface public function __construct(string $name, string $context, AbstractAppMeta $appMeta = null, string $cacheNamespace = null) { + $this->checkVersion(); $this->context = $context; $this->appMeta = $appMeta instanceof AbstractAppMeta ? $appMeta : new Meta($name, $context); $this->cacheNamespace = (string) $cacheNamespace; @@ -133,6 +136,7 @@ private function getModule() : AbstractModule return $this->module; } $module = (new Module)($this->appMeta, $this->context); + $module->install(new CacheModule()); /* @var AbstractModule $module */ $container = $module->getContainer(); (new Bind($container, InjectorInterface::class))->toInstance($this->injector); @@ -141,4 +145,11 @@ private function getModule() : AbstractModule return $module; } + + private function checkVersion(): void + { + if (! class_exists('Doctrine\Common\Cache\FilesystemCache')) { + throw new RuntimeException('Doctrine cache ^1.0 is required for AppInjector. Please install doctrine/cache ^1.0'); + } + } } diff --git a/src-deprecated/Module/CacheModule.php b/src-deprecated/Module/CacheModule.php new file mode 100644 index 00000000..5769113e --- /dev/null +++ b/src-deprecated/Module/CacheModule.php @@ -0,0 +1,26 @@ +bind(Cache::class)->to(ArrayCache::class); + } + } +}