Skip to content

Commit

Permalink
Merge pull request #94 from NaokiTsuchiya/script-injector-interface
Browse files Browse the repository at this point in the history
Using ScriptInjectorInterface
  • Loading branch information
koriym authored Jun 10, 2022
2 parents 71966ca + 2325c96 commit 1591fa1
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 8 deletions.
8 changes: 4 additions & 4 deletions src/CachedInjectorFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,14 @@ public static function getInstance(string $injectorId, string $scriptDir, callab
/** @psalm-suppress DeprecatedClass */
$cache = $cache ?? new NullCache();
$cache->setNamespace($injectorId);
$cachedInjector = $cache->fetch(InjectorInterface::class);
if ($cachedInjector instanceof InjectorInterface) {
$cachedInjector = $cache->fetch(ScriptInjectorInterface::class);
if ($cachedInjector instanceof ScriptInjectorInterface) {
return $cachedInjector; // @codeCoverageIgnore
}

$injector = self::getInjector($modules, $scriptDir, $savedSingletons);
if ($injector instanceof ScriptInjector) {
$cache->save(InjectorInterface::class, $injector);
if ($injector instanceof ScriptInjectorInterface) {
$cache->save(ScriptInjectorInterface::class, $injector);
}

self::$injectors[$injectorId] = serialize($injector);
Expand Down
3 changes: 1 addition & 2 deletions src/CompileInjector.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
use Ray\Compiler\Exception\Unbound;
use Ray\Di\Annotation\ScriptDir;
use Ray\Di\Bind;
use Ray\Di\InjectorInterface;
use Ray\Di\Name;
use ReflectionParameter;

Expand All @@ -18,7 +17,7 @@
use function sprintf;
use function str_replace;

final class CompileInjector implements InjectorInterface
final class CompileInjector implements ScriptInjectorInterface
{
public const INSTANCE = '%s/%s.php';

Expand Down
3 changes: 1 addition & 2 deletions src/ScriptInjector.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
use Ray\Di\Bind;
use Ray\Di\Dependency;
use Ray\Di\DependencyInterface;
use Ray\Di\InjectorInterface;
use Ray\Di\Name;
use Ray\Di\NullModule;
use Ray\Di\ProviderSetModule;
Expand Down Expand Up @@ -39,7 +38,7 @@
use const DIRECTORY_SEPARATOR;
use const E_NOTICE;

final class ScriptInjector implements InjectorInterface
final class ScriptInjector implements ScriptInjectorInterface
{
public const MODULE = '/_module.txt';

Expand Down
14 changes: 14 additions & 0 deletions src/ScriptInjectorInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

declare(strict_types=1);

namespace Ray\Compiler;

use Ray\Di\InjectorInterface;

/**
* Injector interface for script injector based injector
*/
interface ScriptInjectorInterface extends InjectorInterface
{
}

0 comments on commit 1591fa1

Please sign in to comment.