Skip to content

Commit

Permalink
Refactor cache initialization and update composer config.
Browse files Browse the repository at this point in the history
Extract cache adapter initialization into a separate method for clarity and reusability in `src/Injector.php`. Update `composer.json` to allow `bamarni/composer-bin-plugin` for improved plugin management during builds.
  • Loading branch information
koriym committed Nov 16, 2024
1 parent e0663b2 commit 4ab8d49
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
5 changes: 5 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -81,5 +81,10 @@
"phpmd": ["./vendor/bin/phpmd --exclude src/Annotation src text ./phpmd.xml"],
"build": ["@cs", "@sa", "@pcov", "@metrics"],
"compile": "./bin/bear.compile FakeVendor\\\\HelloWorld prod-app ./tests/Fake/fake-app"
},
"config": {
"allow-plugins": {
"bamarni/composer-bin-plugin": true
}
}
}
15 changes: 14 additions & 1 deletion src/Injector.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public static function getInstance(string $appName, string $context, string $app
}

$meta = new Meta($appName, $context, $appDir);
$cache = $cache ?? new ChainAdapter([new ApcuAdapter($injectorId), new FilesystemAdapter($injectorId, 0, $meta->tmpDir . '/injector')]);
$cache = self::getAdapter($cache, $injectorId, $meta);
assert($cache instanceof AdapterInterface);
/** @psalm-suppress all */
[$injector, $fileUpdate] = $cache->getItem($injectorId)->get();
Expand Down Expand Up @@ -99,4 +99,17 @@ private static function factory(Meta $meta, string $context, ?AbstractModule $ov

return $injector;
}

public static function getAdapter(?CacheInterface $cache, string $injectorId, Meta $meta): CacheInterface
{
if ($cache instanceof CacheInterface) {

Check failure on line 105 in src/Injector.php

View workflow job for this annotation

GitHub Actions / Coding Standards

Expected 1 line after "if", found 0.

Check failure on line 105 in src/Injector.php

View workflow job for this annotation

GitHub Actions / Coding Standards

Expected 1 line after "if", found 0.
return $cache;
}
$filesystemAdapter = new FilesystemAdapter($injectorId, 0, $meta->tmpDir . '/injector');
if (ApcuAdapter::isSupported()) {
return new ChainAdapter([new ApcuAdapter($injectorId), $filesystemAdapter]);
}

return $filesystemAdapter;
}
}

0 comments on commit 4ab8d49

Please sign in to comment.