|
11 | 11 |
|
12 | 12 | namespace Symfony\Component\Config\Definition\Builder;
|
13 | 13 |
|
| 14 | +use Composer\InstalledVersions; |
14 | 15 | use Symfony\Component\Config\Definition\BaseNode;
|
15 | 16 | use Symfony\Component\Config\Definition\Exception\InvalidDefinitionException;
|
16 | 17 | use Symfony\Component\Config\Definition\NodeInterface;
|
@@ -76,6 +77,33 @@ public function example(string|array $example): static
|
76 | 77 | return $this->attribute('example', $example);
|
77 | 78 | }
|
78 | 79 |
|
| 80 | + /** |
| 81 | + * Sets the documentation URI, as usually put in the "@see" tag of a doc block. This |
| 82 | + * can either be a URL or a file path. You can use the placeholders {package}, |
| 83 | + * {version:major}, {version:minor}, and {version:patch} in the URI. |
| 84 | + * |
| 85 | + * @return $this |
| 86 | + */ |
| 87 | + public function documentationUri(string $uri, ?string $package = null): static |
| 88 | + { |
| 89 | + $installedVersion = []; |
| 90 | + if ($package) { |
| 91 | + try { |
| 92 | + preg_match('/\d+.\d+.\d+/', InstalledVersions::getVersion($package) ?? '', $m); |
| 93 | + $installedVersion = explode('.', $m[0] ?? ''); |
| 94 | + } catch (\OutOfBoundsException) { |
| 95 | + // no-op |
| 96 | + } |
| 97 | + } |
| 98 | + |
| 99 | + return $this->attribute('documentationUri', strtr($uri, [ |
| 100 | + '{package}' => $package ?? '', |
| 101 | + '{version:major}' => $installedVersion[0] ?? '', |
| 102 | + '{version:minor}' => $installedVersion[1] ?? '', |
| 103 | + '{version:patch}' => $installedVersion[2] ?? '', |
| 104 | + ])); |
| 105 | + } |
| 106 | + |
79 | 107 | /**
|
80 | 108 | * Sets an attribute on the node.
|
81 | 109 | *
|
|