-
-
Notifications
You must be signed in to change notification settings - Fork 424
function to change the name path of the template Template.tpl.php #562
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: 1.x
Are you sure you want to change the base?
function to change the name path of the template Template.tpl.php #562
Conversation
Hey @jonathankablan! Thanks for the PR :). This topic is being discussed in #560. For the record, I'm against making the templates overrideable. Well, at least, making them easily overrideable. The reason is that we don't guarantee backward-compatibility with the templates: we may (in a minor version) change the variables that we pass into a template, which could break a custom template. That's not to say that I'm against it completely, but it needs to be clearly and "advanced" thing to do, and should possibly be a little difficult. About your PR, I definitely don't like the If you're willing to put in some work and push on this, let me know. I can make some suggestions about how we could make this possible, but still "hard enough" that it's for advanced users ;). Cheers! |
Thanks for this first reading, I had wanted to have the possibility to change the TemplateName but this is not really essential for the blow. I would like to allow the change of the RootTemplateDirectory in the Generator class simply which won't change anything to the current operation of the Generator class, and discuss the other methods further. Thanks |
….com/jonathankablan/maker-bundle into feat/add-function-root-template-name
* @param string $templateName | ||
* @return string | ||
*/ | ||
public function supports(string $templateName): string; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
public function supports(string $templateName): string; | |
public function supports(string $templateName): bool; |
This will return a boolean. The idea is that MakerRenderer
will look a bit different than you have. It will look like this:
class MakerRenderer
{
/**
* @var MakerTemplateRendererInterface[]
*/
private $templateRenderers;
public function __construct(array $templateRenderers)
{
$this->templateRenderers = $templateRenderers;
}
public function renderTemplate(string $templateName, array $variables)
{
foreach ($this->templateRenderers as $templateRenderer) {
if ($templateRenderer->supports($templateName)) {
return $templateRenderer->render($templateName, $variables);
}
}
throw new \Exception(sprintf('No template renderers for template "%s"', $templateName);
}
}
There would be ONE class in MakerBundle that implements MakerTemplateRendererInterface
(and users could add more by using a dependency injection tag). It would probably look like this:
class MakerDefaultTemplateRenderer implements MakerTemplateRendererInterface
{
public function supports(string $templateName): string
{
$templatePath = __DIR__.'/Resources/skeleton/'.$templateName;
return file_exists($templatePath);
}
public function render(string $templateName, array $variables)
{
$templatePath = __DIR__.'/Resources/skeleton/'.$templateName;
// this is basically the current logic for rendering templates
$contents = $this->fileManager->parseTemplate($templatePath, $variables);
$this->fileManager->dumpFile($templatePath, $contents);
}
}
* @param string $templateName | ||
* @return string | ||
*/ | ||
public function render(string $templateName = null): string; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
public function render(string $templateName = null): string; | |
public function render(string $templateName, array $variables): string; |
@@ -64,6 +77,11 @@ public function generateClass(string $className, string $templateName, array $va | |||
|
|||
/** | |||
* Generate a normal file from a template. | |||
* | |||
* @param string $targetPath |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This information does not add value because we already have the type in the signature. You should delete them.
BTW, PHP-CS-Fixer should remove it 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
okay Max
No description provided.