Skip to content

Commit

Permalink
Support PHP5.x migration
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
koriym committed Jun 2, 2024
1 parent 9e7de07 commit 0e60c59
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 1 deletion.
2 changes: 1 addition & 1 deletion composer-require-checker.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
]
}
11 changes: 11 additions & 0 deletions src-deprecated/AppInjector.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@

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;
use Ray\Di\Bind;
use Ray\Di\Injector;
use Ray\Di\InjectorInterface;
use Ray\Di\Name;
use RuntimeException;

/**
* @deprecated
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -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');
}
}
}
26 changes: 26 additions & 0 deletions src-deprecated/Module/CacheModule.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

declare(strict_types=1);

namespace BEAR\Package\Module;

use Doctrine\Common\Cache\ArrayCache;
use Doctrine\Common\Cache\Cache;
use Ray\Di\AbstractModule;
use function interface_exists;

/**
* @deprecated
*/
class CacheModule extends AbstractModule
{
/**
* {@inheritdoc}
*/
protected function configure(): void
{
if (interface_exists(Cache::class)) {
$this->bind(Cache::class)->to(ArrayCache::class);
}
}
}

0 comments on commit 0e60c59

Please sign in to comment.