forked from symfony/ux
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
51 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,10 +11,12 @@ | |
|
||
namespace Symfony\UX\Turbo\Bridge\Mercure; | ||
|
||
use Symfony\Component\HttpFoundation\RequestStack; | ||
use Symfony\Component\Mercure\Authorization; | ||
use Symfony\Component\Mercure\HubInterface; | ||
use Symfony\UX\StimulusBundle\Helper\StimulusHelper; | ||
use Symfony\UX\Turbo\Broadcaster\IdAccessor; | ||
use Symfony\UX\Turbo\Twig\TurboStreamListenRendererInterface; | ||
use Symfony\UX\Turbo\Twig\TurboStreamListenRendererWithOptionsInterface; | ||
use Symfony\WebpackEncoreBundle\Twig\StimulusTwigExtension; | ||
use Twig\Environment; | ||
|
||
|
@@ -23,14 +25,16 @@ | |
* | ||
* @author Kévin Dunglas <[email protected]> | ||
*/ | ||
final class TurboStreamListenRenderer implements TurboStreamListenRendererInterface | ||
final class TurboStreamListenRenderer implements TurboStreamListenRendererWithOptionsInterface | ||
{ | ||
private StimulusHelper $stimulusHelper; | ||
|
||
public function __construct( | ||
private HubInterface $hub, | ||
StimulusHelper|StimulusTwigExtension $stimulus, | ||
private IdAccessor $idAccessor, | ||
private ?Authorization $authorization = null, | ||
private ?RequestStack $requestStack = null, | ||
) { | ||
if ($stimulus instanceof StimulusTwigExtension) { | ||
trigger_deprecation('symfony/ux-turbo', '2.9', 'Passing an instance of "%s" as second argument of "%s" is deprecated, pass an instance of "%s" instead.', StimulusTwigExtension::class, __CLASS__, StimulusHelper::class); | ||
|
@@ -59,8 +63,27 @@ public function renderTurboStreamListen(Environment $env, $topic /* array $event | |
$controllerAttributes['topic'] = current($topics); | ||
} | ||
|
||
if (isset($eventSourceOptions, $eventSourceOptions['withCredentials'])) { | ||
$controllerAttributes['withCredentials'] = $eventSourceOptions['withCredentials']; | ||
if (isset($eventSourceOptions)) { | ||
if ( | ||
null !== $this->authorization | ||
&& null !== $this->requestStack | ||
&& (isset($eventSourceOptions['subscribe']) || isset($eventSourceOptions['publish']) || isset($eventSourceOptions['additionalClaims'])) | ||
&& null !== $request = $this->requestStack->getMainRequest() | ||
) { | ||
$this->authorization->setCookie( | ||
$request, | ||
$eventSourceOptions['subscribe'] ?? [], | ||
$eventSourceOptions['publish'] ?? [], | ||
$eventSourceOptions['additionalClaims'] ?? [], | ||
$eventSourceOptions['transport'] ?? null, | ||
); | ||
|
||
unset($eventSourceOptions['subscribe'], $eventSourceOptions['publish'], $eventSourceOptions['additionalClaims']); | ||
} | ||
|
||
if (isset($eventSourceOptions['withCredentials'])) { | ||
$controllerAttributes['withCredentials'] = $eventSourceOptions['withCredentials']; | ||
} | ||
} | ||
|
||
$stimulusAttributes = $this->stimulusHelper->createStimulusAttributes(); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
src/Turbo/src/Twig/TurboStreamListenRendererWithOptionsInterface.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\UX\Turbo\Twig; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
interface TurboStreamListenRendererWithOptionsInterface extends TurboStreamListenRendererInterface | ||
{ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,7 +16,6 @@ | |
|
||
/** | ||
* @author Kévin Dunglas <[email protected]> | ||
* @author Pierre Ambroise <[email protected]> | ||
*/ | ||
final class TwigExtension extends AbstractExtension | ||
{ | ||
|