Skip to content

Commit b32f087

Browse files
committed
feature #196 Update the class reference directive to support Symfony AI classes (javiereguiluz)
This PR was merged into the main branch. Discussion ---------- Update the class reference directive to support Symfony AI classes We need to publish Symfony AI docs on symfony.com ASAP. The GitHub links generated for the classes used in Symfony AI docs are wrong, so we must fix that somehow. This PR proposes a possible fix. In the future we'll need something better ... but we'r ealso migrating to another doc builder project, so it's not worth it to try to make it perfect now. Commits ------- 74df6be Update the class reference directive to support Symfony AI classes
2 parents 1c1e16f + 74df6be commit b32f087

File tree

3 files changed

+22
-1
lines changed

3 files changed

+22
-1
lines changed

src/Reference/ClassReference.php

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,27 @@ public function resolve(Environment $environment, string $data): ResolvedReferen
3232
{
3333
$className = u($data)->replace('\\\\', '\\');
3434

35+
if (str_starts_with($className, 'Symfony\\AI\\')) {
36+
// Example:
37+
// input: Symfony\AI\Agent\Memory\StaticMemoryProvider
38+
// output: https://github.com/symfony/ai/blob/main/src/agent/src/Memory/StaticMemoryProvider.php
39+
40+
$classPath = $className->after('Symfony\\AI\\');
41+
[$monorepoSubRepository, $classRelativePath] = $classPath->split('\\', 2);
42+
// because of monorepo structure, the first part of the classpath needs to be slugged
43+
// 'Agent' -> 'agent', 'AiBundle' -> 'ai-bundle', etc.
44+
$monorepoSubRepository = u($monorepoSubRepository)->snake('-')->lower();
45+
$classRelativePath = u($classRelativePath)->replace('\\', '/');
46+
47+
$url = \sprintf('https://github.com/symfony/ai/blob/main/src/%s/src/%s.php', $monorepoSubRepository, $classRelativePath);
48+
} else {
49+
$url = sprintf('%s/%s.php', $this->symfonyRepositoryUrl, $className->replace('\\', '/'));
50+
}
51+
3552
return new ResolvedReference(
3653
$environment->getCurrentFileName(),
3754
$className->afterLast('\\'),
38-
sprintf('%s/%s.php', $this->symfonyRepositoryUrl, $className->replace('\\', '/')),
55+
$url,
3956
[],
4057
[
4158
'title' => $className,
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
11
<p><a href="https://github.com/symfony/symfony/blob/4.0/src/Symfony/Component/HttpKernel/DependencyInjection/ContainerAwareHttpKernel.php" class="reference external" title="Symfony\Component\HttpKernel\DependencyInjection\ContainerAwareHttpKernel" rel="external noopener noreferrer" target="_blank">ContainerAwareHttpKernel</a></p>
2+
3+
<p><a href="https://github.com/symfony/ai/blob/main/src/agent/src/Memory/StaticMemoryProvider.php" class="reference external" title="Symfony\AI\Agent\Memory\StaticMemoryProvider" rel="external noopener noreferrer" target="_blank">StaticMemoryProvider</a></p>
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11

22
:class:`Symfony\\Component\\HttpKernel\\DependencyInjection\\ContainerAwareHttpKernel`
3+
4+
:class:`Symfony\\AI\\Agent\\Memory\\StaticMemoryProvider`

0 commit comments

Comments
 (0)