Skip to content

Commit 27cfdc9

Browse files
committed
bug #204 Fixed the IDE link in new controller + make code simpler in the generated controller (lyrixx)
This PR was merged into the 1.0-dev branch. Discussion ---------- Fixed the IDE link in new controller + make code simpler in the generated controller fixes #199 Commits ------- 8b810bd Fixed the IDE link in new controller + make code simpler in the generated controller
2 parents bc20c9e + 8b810bd commit 27cfdc9

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
@@ -84,8 +84,10 @@ public function getHeadPrintCode($title): string
8484
HTML;
8585
}
8686

87-
public function getFileLink($path): string
87+
public function getFileLink($path, $text = null, $line = 0): string
8888
{
89-
return sprintf('<a href="{{ \'%s\'|file_link(0) }}">%1$s</a>', $path);
89+
$text = $text ?: $path;
90+
91+
return "<a href=\"{{ '$path'|file_link($line) }}\">$text</a>";
9092
}
9193
}

src/Maker/MakeController.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ public function generate(InputInterface $input, ConsoleStyle $io, Generator $gen
7171
'controller/twig_template.tpl.php',
7272
[
7373
'controller_path' => $controllerPath,
74+
'root_directory' => $generator->getRootDirectory(),
75+
'class_name' => $controllerClassNameDetails->getShortName(),
7476
]
7577
);
7678
}

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)