Skip to content

Commit

Permalink
feature #160 Method reference generate link with scroll to text fragm…
Browse files Browse the repository at this point in the history
…ent (alamirault)

This PR was merged into the main branch.

Discussion
----------

Method reference generate link with scroll to text fragment

This PR fix #159 if you're ok to use `Scroll-To-Text Fragment`

Commits
-------

12bf347 Method reference generate link with scoll to text fragment
  • Loading branch information
javiereguiluz committed May 24, 2023
2 parents 11d9d81 + 12bf347 commit faf2c5f
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/Reference/MethodReference.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,11 @@ public function resolve(Environment $environment, string $data): ResolvedReferen

$methodName = explode('::', $data)[1];

$scrollTextFragment = sprintf('#:~:text=%s', rawurlencode('function '.$methodName));
return new ResolvedReference(
$environment->getCurrentFileName(),
$methodName.'()',
sprintf('%s/%s.php#method_%s', $this->symfonyRepositoryUrl, str_replace('\\', '/', $className), $methodName),
sprintf('%s/%s.php%s', $this->symfonyRepositoryUrl, str_replace('\\', '/', $className), $scrollTextFragment),
[],
[
'title' => sprintf('%s::%s()', $className, $methodName),
Expand Down
2 changes: 1 addition & 1 deletion tests/fixtures/expected/blocks/references/method.html
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<p><a href="https://github.com/symfony/symfony/blob/4.0/src/Symfony/Component/HttpFoundation/RequestStack.php#method_getCurrentRequest" class="reference external" title="Symfony\Component\HttpFoundation\RequestStack::getCurrentRequest()" rel="external noopener noreferrer" target="_blank">getCurrentRequest()</a></p>
<p><a href="https://github.com/symfony/symfony/blob/4.0/src/Symfony/Component/HttpFoundation/RequestStack.php#:~:text=function%20getCurrentRequest" class="reference external" title="Symfony\Component\HttpFoundation\RequestStack::getCurrentRequest()" rel="external noopener noreferrer" target="_blank">getCurrentRequest()</a></p>
2 changes: 1 addition & 1 deletion tests/fixtures/expected/main/datetime.html
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ <h3 id="the-date-format-option">
<span>Tip</span>
</p>
<p>This is a little tip about something! We an also talk about specific
methods: <a href="https://github.com/symfony/symfony/blob/4.0/src/Symfony/Component/BrowserKit/Client.php#method_doRequest" class="reference external" title="Symfony\Component\BrowserKit\Client::doRequest()" rel="external noopener noreferrer" target="_blank">doRequest()</a>.
methods: <a href="https://github.com/symfony/symfony/blob/4.0/src/Symfony/Component/BrowserKit/Client.php#:~:text=function%20doRequest" class="reference external" title="Symfony\Component\BrowserKit\Client::doRequest()" rel="external noopener noreferrer" target="_blank">doRequest()</a>.
Or a namespace: <a href="https://github.com/symfony/symfony/blob/4.0/src/Symfony/Component/Validator/Constraints" class="reference external" title="Symfony\Component\Validator\Constraints" rel="external noopener noreferrer" target="_blank">Constraints</a>.
Or a PHP function: <a href="https://secure.php.net/manual/en/function.parse-ini-file.php" class="reference external" title="parse_ini_file" rel="external noopener noreferrer" target="_blank">parse_ini_file</a>.
Or a PHP method! <a href="https://secure.php.net/manual/en/locale.getdefault.php" class="reference external" title="Locale" rel="external noopener noreferrer" target="_blank">Locale::getDefault()</a>.</p>
Expand Down

0 comments on commit faf2c5f

Please sign in to comment.