Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit c00f3b3

Browse filesBrowse files
committed
AbstractController and "entry"
1 parent 2ace4e5 commit c00f3b3
Copy full SHA for c00f3b3

File tree

Expand file treeCollapse file tree

3 files changed

+21
-2
lines changed
Filter options
Expand file treeCollapse file tree

3 files changed

+21
-2
lines changed

‎src/Symfony/Bridge/Twig/Extension/ImportMapRuntime.php

Copy file name to clipboardExpand all lines: src/Symfony/Bridge/Twig/Extension/ImportMapRuntime.php
+5-1Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public function __construct(
2525
) {
2626
}
2727

28-
public function importmap(): string
28+
public function importmap(?string $entryPoint = 'app'): string
2929
{
3030
$output = <<<HTML
3131
<script type="importmap">
@@ -49,6 +49,10 @@ public function importmap(): string
4949
$output .= "\n<link rel=\"modulepreload\" href=\"{$url}\">";
5050
}
5151

52+
if (null !== $entryPoint) {
53+
$output .= "\n<script type=\"module\">import '$entryPoint';</script>";
54+
}
55+
5256
return $output;
5357
}
5458
}

‎src/Symfony/Bundle/FrameworkBundle/Controller/AbstractController.php

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/Controller/AbstractController.php
+15-1Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use Psr\Container\ContainerInterface;
1515
use Psr\Link\EvolvableLinkInterface;
1616
use Psr\Link\LinkInterface;
17+
use Symfony\Component\AssetMapper\ImportMap\ImportMapManager;
1718
use Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException;
1819
use Symfony\Component\DependencyInjection\ParameterBag\ContainerBagInterface;
1920
use Symfony\Component\Form\Extension\Core\Type\FormType;
@@ -44,6 +45,7 @@
4445
use Symfony\Component\WebLink\EventListener\AddLinkHeaderListener;
4546
use Symfony\Component\WebLink\GenericLinkProvider;
4647
use Symfony\Component\WebLink\HttpHeaderSerializer;
48+
use Symfony\Component\WebLink\Link;
4749
use Symfony\Contracts\Service\Attribute\Required;
4850
use Symfony\Contracts\Service\ServiceSubscriberInterface;
4951
use Twig\Environment;
@@ -95,6 +97,7 @@ public static function getSubscribedServices(): array
9597
'security.csrf.token_manager' => '?'.CsrfTokenManagerInterface::class,
9698
'parameter_bag' => '?'.ContainerBagInterface::class,
9799
'web_link.http_header_serializer' => '?'.HttpHeaderSerializer::class,
100+
'asset_mapper.importmap.manager' => '?'.ImportMapManager::class,
98101
];
99102
}
100103

@@ -409,7 +412,7 @@ protected function addLink(Request $request, LinkInterface $link): void
409412
/**
410413
* @param LinkInterface[] $links
411414
*/
412-
protected function sendEarlyHints(iterable $links, Response $response = null): Response
415+
protected function sendEarlyHints(iterable $links = [], Response $response = null, bool $preloadJavaScriptModules = false): Response
413416
{
414417
if (!$this->container->has('web_link.http_header_serializer')) {
415418
throw new \LogicException('You cannot use the "sendEarlyHints" method if the WebLink component is not available. Try running "composer require symfony/web-link".');
@@ -418,6 +421,17 @@ protected function sendEarlyHints(iterable $links, Response $response = null): R
418421
$response ??= new Response();
419422

420423
$populatedLinks = [];
424+
425+
if ($preloadJavaScriptModules) {
426+
if (!$this->container->has('asset_mapper.importmap.manager')) {
427+
throw new \LogicException('You cannot use the JavaScript modules method if the AssetMapper component is not available. Try running "composer require symfony/asset-mapper".');
428+
}
429+
430+
foreach ($this->container->get('asset_mapper.importmap.manager')->getModulesToPreload() as $url) {
431+
$populatedLinks[] = new Link('modulepreload', $url);
432+
}
433+
}
434+
421435
foreach ($links as $link) {
422436
if ($link instanceof EvolvableLinkInterface && !$link->getRels()) {
423437
$link = $link->withRel('preload');

‎src/Symfony/Bundle/FrameworkBundle/Tests/Controller/AbstractControllerTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/Tests/Controller/AbstractControllerTest.php
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ public function testSubscribedServices()
7474
'security.token_storage' => '?Symfony\\Component\\Security\\Core\\Authentication\\Token\\Storage\\TokenStorageInterface',
7575
'security.csrf.token_manager' => '?Symfony\\Component\\Security\\Csrf\\CsrfTokenManagerInterface',
7676
'web_link.http_header_serializer' => '?Symfony\\Component\\WebLink\\HttpHeaderSerializer',
77+
'importmap.manager' => '?Symfony\\Component\\ImportMap\\ImportMapManager',
7778
];
7879

7980
$this->assertEquals($expectedServices, $subscribed, 'Subscribed core services in AbstractController have changed');

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.