Skip to content

Commit 8b810bd

Browse files
committed
Fixed the IDE link in new controller + make code simpler in the generated controller
1 parent 2664394 commit 8b810bd

File tree

5 files changed

+19
-5
lines changed

5 files changed

+19
-5
lines changed

src/FileManager.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,11 @@ public function isNamespaceConfiguredToAutoload(string $namespace): bool
169169
return $this->autoloaderUtil->isNamespaceConfiguredToAutoload($namespace);
170170
}
171171

172+
public function getRootDirectory(): string
173+
{
174+
return $this->rootDirectory;
175+
}
176+
172177
/**
173178
* Resolve '../' in paths (like real_path), but for non-existent files.
174179
*

src/Generator.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,11 @@ public function createClassNameDetails(string $name, string $namespacePrefix, st
152152
return new ClassNameDetails($className, $fullNamespacePrefix, $suffix);
153153
}
154154

155+
public function getRootDirectory(): string
156+
{
157+
return $this->fileManager->getRootDirectory();
158+
}
159+
155160
private function addOperation(string $targetPath, string $templateName, array $variables)
156161
{
157162
if ($this->fileManager->fileExists($targetPath)) {

src/GeneratorTwigHelper.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,10 @@ public function getHeadPrintCode($title): string
7070
HTML;
7171
}
7272

73-
public function getFileLink($path): string
73+
public function getFileLink($path, $text = null, $line = 0): string
7474
{
75-
return sprintf('<a href="{{ \'%s\'|file_link(0) }}">%1$s</a>', $path);
75+
$text = $text ?: $path;
76+
77+
return "<a href=\"{{ '$path'|file_link($line) }}\">$text</a>";
7678
}
7779
}

src/Maker/MakeController.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ public function generate(InputInterface $input, ConsoleStyle $io, Generator $gen
6868
'controller/twig_template.tpl.php',
6969
[
7070
'controller_path' => $controllerPath,
71+
'root_directory' => $generator->getRootDirectory(),
72+
'class_name' => $controllerClassNameDetails->getShortName(),
7173
]
7274
);
7375
}

src/Resources/skeleton/controller/twig_template.tpl.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<?= $helper->getHeadPrintCode('Hello {{ controller_name }}!'); ?>
1+
<?= $helper->getHeadPrintCode("Hello $class_name!"); ?>
22

33
{% block body %}
44
<style>
@@ -11,8 +11,8 @@
1111

1212
This friendly message is coming from:
1313
<ul>
14-
<li>Your controller at <code><?= $helper->getFileLink($controller_path); ?></code></li>
15-
<li>Your template at <code><?= $helper->getFileLink($relative_path); ?></code></li>
14+
<li>Your controller at <code><?= $helper->getFileLink("$root_directory/$controller_path", "$controller_path"); ?></code></li>
15+
<li>Your template at <code><?= $helper->getFileLink("$root_directory/$relative_path", "$relative_path"); ?></code></li>
1616
</ul>
1717
</div>
1818
{% endblock %}

0 commit comments

Comments
 (0)