Skip to content

Commit 6e1ed41

Browse files
authored
minor #1606 move templates to root template dir
1 parent 673c3a5 commit 6e1ed41

File tree

69 files changed

+32
-5
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

69 files changed

+32
-5
lines changed

src/Generator.php

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public function generateClass(string $className, string $templateName, array $va
8181
*
8282
* @internal
8383
*
84-
* @param string $templateName Template name in Resources/skeleton to use
84+
* @param string $templateName Template name in the templates/ dir to use
8585
* @param array $variables Array of variables to pass to the template
8686
* @param bool $isController Set to true if generating a Controller that needs
8787
* access to the TemplateComponentGenerator ("generator") in
@@ -299,10 +299,14 @@ private function addOperation(string $targetPath, string $templateName, array $v
299299

300300
$templatePath = $templateName;
301301
if (!file_exists($templatePath)) {
302-
$templatePath = __DIR__.'/Resources/skeleton/'.$templateName;
302+
$templatePath = \sprintf('%s/templates/%s', \dirname(__DIR__), $templateName);
303303

304304
if (!file_exists($templatePath)) {
305-
throw new \Exception(\sprintf('Cannot find template "%s"', $templateName));
305+
$templatePath = $this->getTemplateFromLegacySkeletonPath($templateName);
306+
}
307+
308+
if (!file_exists($templatePath)) {
309+
throw new \Exception(\sprintf('Cannot find template "%s" in the templates/ dir.', $templateName));
306310
}
307311
}
308312

@@ -311,4 +315,27 @@ private function addOperation(string $targetPath, string $templateName, array $v
311315
'variables' => $variables,
312316
];
313317
}
318+
319+
/**
320+
* @legacy - Remove when public generate methods become "internal" to MakerBundle in v2
321+
*/
322+
private function getTemplateFromLegacySkeletonPath(string $templateName): string
323+
{
324+
$templatePath = $templateName;
325+
if (!file_exists($templatePath)) {
326+
$templatePath = __DIR__.'/Resources/skeleton/'.$templateName;
327+
328+
if (!file_exists($templatePath)) {
329+
throw new \Exception(\sprintf('Cannot find template "%s"', $templateName));
330+
}
331+
}
332+
333+
@trigger_deprecation(
334+
'symfony/maker-bundle',
335+
'1.62.0',
336+
'Storing templates in src/Resources/skeleton is deprecated. Store MakerBundle templates in the "~/templates/" dir instead.',
337+
);
338+
339+
return $templatePath;
340+
}
314341
}

src/Maker/MakeTwigComponent.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,14 +79,14 @@ public function generate(InputInterface $input, ConsoleStyle $io, Generator $gen
7979

8080
$generator->generateClass(
8181
$factory->getFullName(),
82-
\sprintf('%s/../Resources/skeleton/twig/%s', __DIR__, $live ? 'LiveComponent.tpl.php' : 'Component.tpl.php'),
82+
\sprintf('%s/templates/twig/%s', \dirname(__DIR__, 2), $live ? 'LiveComponent.tpl.php' : 'Component.tpl.php'),
8383
[
8484
'live' => $live,
8585
]
8686
);
8787
$generator->generateTemplate(
8888
"components/{$templatePath}.html.twig",
89-
\sprintf('%s/../Resources/skeleton/twig/%s', __DIR__, 'component_template.tpl.php')
89+
\sprintf('%s/templates/twig/%s', \dirname(__DIR__, 2), 'component_template.tpl.php')
9090
);
9191

9292
$generator->writeChanges();
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)