Skip to content
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

Create link_source_file helper to replace internal WebProfiler helper #1456

Merged
merged 1 commit into from
Nov 22, 2023

Conversation

GromNaN
Copy link
Member

@GromNaN GromNaN commented Nov 22, 2023

Fix #1455

src/Twig/SourceCodeExtension.php Outdated Show resolved Hide resolved
{
$text = str_replace('\\', '/', $file);
if (str_starts_with($text, $this->projectDir)) {
$text = mb_substr($text, \mb_strlen($this->projectDir));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to use mbstring here to remove the string from the start (we know it already starts with it): substr($text, \strlen($this->projectDir)) works just fine (and would work even if the filesystem path is not in UTF-8)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree, that was updated by php-cs-fixer.

src/Twig/SourceCodeExtension.php Outdated Show resolved Hide resolved
@@ -30,15 +30,15 @@
<div class="tab-content" id="myTabContent">
<div class="tab-pane show active" id="controller-code" role="tabpanel" aria-labelledby="controller-tab">
{% if controller %}
<p class="file-link">{{ controller.file_path|format_file(controller.starting_line) }}</p>
<p class="file-link">{{ link_source_file(controller.file_path, controller.starting_line) }}</p>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why making it a Twig function and not a filter ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because both arguments are equally required. It seems more coherent to me to have them at the same level.

@@ -11,6 +11,8 @@

namespace App\Twig;

use Symfony\Component\DependencyInjection\Attribute\Autowire;
use Symfony\Component\ErrorHandler\ErrorRenderer\FileLinkFormatter;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This FileLinkFormatter class was moved in Symfony 6.4, I'll wait for the demo project to be upgraded.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No worries. Let's merge this and then we'll update the other PR that upgrades the app to 6.4. Thanks.

@javiereguiluz
Copy link
Member

Jérôme, thanks for taking care of this in preparation for the upstream changes in Symfony.

@javiereguiluz javiereguiluz merged commit 945a0f2 into symfony:main Nov 22, 2023
0 of 5 checks passed
@GromNaN GromNaN deleted the file-link branch November 22, 2023 17:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Don't use Twig CodeExtension helpers outside of a profiler panel
3 participants