modette / cache-generator
此包已被废弃且不再维护。未建议替代包。
使用单个命令生成 Latte 模板和 DI 容器缓存。
此包尚未发布版本,可用的信息很少。
README
使用单个命令生成 Latte 模板和 DI 容器缓存。
安装
安装 modette/cache-generator 的最佳方式是使用 Composer
$ composer require modette/cache-generator
在您的 config.neon
中注册
extensions: cacheGenerator: Modette\CacheGenerator\DI\CacheGeneratorExtension
配置
DI 容器生成器
修改 bootstrap.php
的最后一行
$configurator->addServices(['configurator' => $configurator]); // we need Configurator available as a service $container = $configurator->createContainer(); return $container;
以下示例配置为生成 3 个容器(debug
、production
和 console
),它们在 consoleMode
和 debugMode
参数上不同。
对于 Nette BC,您不需要添加 productionMode
参数,它会自动完成。
默认配置期望您仅在调试模式下运行控制台。
警告 同一包可能存在不兼容的情况。要求是在所有 CompilerExtensions 中使用参数 debugMode 而不是 PHP_SAPI。
cacheGenerator: generators: diContainers: Modette\CacheGenerator\Generators\DiContainersCacheGenerator( [ debug: [debugMode: true, consoleMode: false], production: [debugMode: false, consoleMode: false], console: [debugMode: true, consoleMode: true] ], "?->getService('configurator')"(@container) )
Latte 模板缓存生成器
cacheGenerator: generators: latteTemplates: Modette\CacheGenerator\Generators\LatteTemplatesCacheGenerator( [%appDir%], "?->createTemplate()"(@latte.templateFactory) )
使用方法 - 通过 CLI
在 Symfony 控制台中运行命令
$ cache:generate
添加 -v
参数以显示更详细的信息
使用方法 - 直接
<?php // get Modette\CacheGenerator\CacheGenerator from DI container $generator->generate(new \Symfony\Component\Console\Output\NullOutput());
创建自己的生成器
实现 IGenerator
并在生成器列表中注册它
<?php class YourGenerator implements \Modette\CacheGenerator\Generators\IGenerator { public function generate(\Symfony\Component\Console\Output\OutputInterface $output): void { // generate cache // inform about it in console } }
下一步是什么?
使用出色的 Composer 插件 composer-warmup 生成 OpCode 缓存