mirror of
https://github.com/twigphp/Twig.git
synced 2026-09-16 20:36:33 +00:00
Improve wiring
This commit is contained in:
committed by
Fabien Potencier
parent
4d036a9148
commit
fff62b9eb1
+2
-1
@@ -100,13 +100,14 @@ are local to the template fragment:
|
||||
If you are not using Symfony, you must also register the extension runtime::
|
||||
|
||||
use Symfony\Component\Cache\Adapter\FilesystemAdapter;
|
||||
use Symfony\Component\Cache\Adapter\TagAwareAdapter;
|
||||
use Twig\Extra\Cache\CacheRuntime;
|
||||
use Twig\RuntimeLoader\RuntimeLoaderInterface;
|
||||
|
||||
$twig->addRuntimeLoader(new class implements RuntimeLoaderInterface {
|
||||
public function load($class) {
|
||||
if (CacheRuntime::class === $class) {
|
||||
return new CacheRuntime(new FilesystemAdapter());
|
||||
return new CacheRuntime(new TagAwareAdapter(new FilesystemAdapter()));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
@@ -38,9 +38,6 @@ class CacheNode extends Node
|
||||
->subcompile($this->getNode('key'))
|
||||
->raw(", function (\Symfony\Contracts\Cache\ItemInterface \$item) use (\$context) {\n")
|
||||
->indent()
|
||||
->write("try {\n")
|
||||
->indent()
|
||||
->write("\$item->tag('twig');\n")
|
||||
;
|
||||
|
||||
if ($this->hasNode('tags')) {
|
||||
@@ -51,15 +48,6 @@ class CacheNode extends Node
|
||||
;
|
||||
}
|
||||
|
||||
$compiler
|
||||
->outdent()
|
||||
->write("} catch (\Psr\Cache\CacheException \$e) {\n")
|
||||
->indent()
|
||||
->write("// cache doesn't support tags\n")
|
||||
->outdent()
|
||||
->write("}\n")
|
||||
;
|
||||
|
||||
if ($this->hasNode('ttl')) {
|
||||
$compiler
|
||||
->write('$item->expiresAfter(')
|
||||
|
||||
@@ -11,6 +11,9 @@
|
||||
|
||||
namespace Symfony\Component\DependencyInjection\Loader\Configurator;
|
||||
|
||||
use Psr\Cache\CacheItemPoolInterface;
|
||||
use Symfony\Component\Cache\Adapter\TagAwareAdapter;
|
||||
use Symfony\Contracts\Cache\CacheInterface;
|
||||
use Symfony\Contracts\Cache\TagAwareCacheInterface;
|
||||
use Twig\Extra\Cache\CacheExtension;
|
||||
use Twig\Extra\Cache\CacheRuntime;
|
||||
@@ -22,10 +25,21 @@ return static function (ContainerConfigurator $container) {
|
||||
|
||||
->set('twig.runtime.cache', CacheRuntime::class)
|
||||
->args([
|
||||
service('twig.cache.default'),
|
||||
service('twig.cache'),
|
||||
])
|
||||
->tag('twig.runtime')
|
||||
|
||||
->alias('twig.cache.default', TagAwareCacheInterface::class)
|
||||
->set('twig.cache', TagAwareAdapter::class)
|
||||
->args([
|
||||
service('.twig.cache.inner')
|
||||
])
|
||||
|
||||
->set('.twig.cache.inner')
|
||||
->parent('cache.app')
|
||||
->tag('cache.pool', ['name' => 'twig.cache'])
|
||||
|
||||
->alias(TagAwareCacheInterface::class.' $twigCache', 'twig.cache')
|
||||
->alias(CacheInterface::class.' $twigCache', '.twig.cache.inner')
|
||||
->alias(CacheItemPoolInterface::class.' $twigCache', '.twig.cache.inner')
|
||||
;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user