Symfony MakerBundle定制制造商
在Symfony MakerBundle文档中,有一个词是关于创建自己的制造商的。它说: 在src/Maker中创建一个扩展AbstractMaker的类/ 目录这是真的 慢点。 这个新制造商的自定义模板/骨架怎么样?我签入了Symfony MakerBundle定制制造商,symfony,symfony5,Symfony,Symfony5,在Symfony MakerBundle文档中,有一个词是关于创建自己的制造商的。它说: 在src/Maker中创建一个扩展AbstractMaker的类/ 目录这是真的 慢点。 这个新制造商的自定义模板/骨架怎么样?我签入了Symfony\Bundle\MakerBundle\Generator类,它搜索如下模板: $templatePath = __DIR__.'/Resources/skeleton/'.$templateName; 因此,在运行custom maker(命令)时,路径仍
Symfony\Bundle\MakerBundle\Generator
类,它搜索如下模板:
$templatePath = __DIR__.'/Resources/skeleton/'.$templateName;
因此,在运行custom maker(命令)时,路径仍然设置为Symfony MakerBundle resources。我错过什么了吗?没有干净的方法从自定义模板生成文件?如果我查看
Symfony\Bundle\MakerBundle\Generator
中的代码,我会看到:
private function addOperation(string $targetPath, string $templateName, array $variables)
{
if ($this->fileManager->fileExists($targetPath)) {
throw new RuntimeCommandException(sprintf('The file "%s" can\'t be generated because it already exists.', $this->fileManager->relativizePath($targetPath)));
}
$variables['relative_path'] = $this->fileManager->relativizePath($targetPath);
$templatePath = $templateName;
if (!file_exists($templatePath)) {
$templatePath = __DIR__.'/Resources/skeleton/'.$templateName;
if (!file_exists($templatePath)) {
throw new \Exception(sprintf('Cannot find template "%s"', $templateName));
}
}
$this->pendingOperations[$targetPath] = [
'template' => $templatePath,
'variables' => $variables,
];
}
因此,基本上,它首先检查文件是否存在,如果不存在,则将模板的路径更改为\uuu DIR\uuu.'/Resources/skeleton/'。$templateName如果该文件也不存在,它就会抛出一个异常
因此,基本上,如果您提供了一个存在于$templateName
参数的文件路径,您可以决定从何处加载模板。谢谢!我太专注于原创制作人,只传递“dir/templatename”。祝你今天愉快:)