Skip to content

Commit 861033a

Browse files
Merge branch 'turbo-mercure' into turbo
* turbo-mercure: run yarn tests for all workspaces - - - fix cs fix build re-add main package.json Fix JS Move Mercure integration to a dedicated bridge
2 parents 63efb1d + 57da895 commit 861033a

27 files changed

+131
-159
lines changed

.php_cs.dist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,6 @@ return PhpCsFixer\Config::create()
2424
->append([__FILE__])
2525
->notPath('#/Fixtures/#')
2626
->notPath('#/app/var/#')
27-
->notPath('Turbo/Broadcast.php') // Need https://github.com/FriendsOfPHP/PHP-CS-Fixer/issues/4702
27+
->notPath('Turbo/Attribute/Broadcast.php') // Need https://github.com/FriendsOfPHP/PHP-CS-Fixer/issues/4702
2828
)
2929
;

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"private": true,
33
"workspaces": [
4-
"src/*/Resources/assets"
4+
"src/**/Resources/assets"
55
],
66
"scripts": {
77
"build": "yarn workspaces run build",

src/Chartjs/composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
},
4040
"extra": {
4141
"branch-alias": {
42-
"dev-main": "1.1-dev"
42+
"dev-main": "1.3-dev"
4343
},
4444
"thanks": {
4545
"name": "symfony/ux",

src/Cropperjs/composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
},
4343
"extra": {
4444
"branch-alias": {
45-
"dev-main": "1.1-dev"
45+
"dev-main": "1.3-dev"
4646
},
4747
"thanks": {
4848
"name": "symfony/ux",

src/Dropzone/composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
},
4141
"extra": {
4242
"branch-alias": {
43-
"dev-main": "1.1-dev"
43+
"dev-main": "1.3-dev"
4444
},
4545
"thanks": {
4646
"name": "symfony/ux",

src/LazyImage/composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
},
4242
"extra": {
4343
"branch-alias": {
44-
"dev-main": "1.1-dev"
44+
"dev-main": "1.3-dev"
4545
},
4646
"thanks": {
4747
"name": "symfony/ux",

src/Swup/composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
],
2020
"extra": {
2121
"branch-alias": {
22-
"dev-main": "1.1-dev"
22+
"dev-main": "1.3-dev"
2323
},
2424
"thanks": {
2525
"name": "symfony/ux",

src/Turbo/Attribute/Broadcast.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
namespace Symfony\UX\Turbo\Attribute;
1313

14-
use Symfony\UX\Turbo\Mercure\Broadcaster;
14+
use Symfony\UX\Turbo\Bridge\Mercure\Broadcaster;
1515

1616
/**
1717
* Marks the entity as broadcastable.

src/Turbo/Mercure/Broadcaster.php renamed to src/Turbo/Bridge/Mercure/Broadcaster.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
* file that was distributed with this source code.
1010
*/
1111

12-
namespace Symfony\UX\Turbo\Mercure;
12+
namespace Symfony\UX\Turbo\Bridge\Mercure;
1313

1414
use Symfony\Component\Mercure\HubInterface;
1515
use Symfony\Component\Mercure\Update;

src/Turbo/Bridge/Mercure/LICENSE

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
Copyright (c) 2021 Fabien Potencier
2+
3+
Permission is hereby granted, free of charge, to any person obtaining a copy
4+
of this software and associated documentation files (the "Software"), to deal
5+
in the Software without restriction, including without limitation the rights
6+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7+
copies of the Software, and to permit persons to whom the Software is furnished
8+
to do so, subject to the following conditions:
9+
10+
The above copyright notice and this permission notice shall be included in all
11+
copies or substantial portions of the Software.
12+
13+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19+
THE SOFTWARE.
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
{
2+
"name": "@symfony/ux-turbo-mercure",
3+
"description": "Mercure integration for Symfony UX Turbo",
4+
"license": "MIT",
5+
"private": true,
6+
"version": "0.1.0",
7+
"symfony": {
8+
"controllers": {
9+
"turbo-stream": {
10+
"main": "dist/turbo_stream_controller.js",
11+
"webpackMode": "eager",
12+
"fetch": "eager",
13+
"enabled": true
14+
}
15+
}
16+
},
17+
"scripts": {
18+
"build": "babel src -d dist",
19+
"test": "babel src -d dist && jest",
20+
"lint": "eslint src test"
21+
},
22+
"peerDependencies": {
23+
"@hotwired/turbo": "^7.0.0-beta.4",
24+
"stimulus": "^2.0.0"
25+
},
26+
"devDependencies": {
27+
"@babel/cli": "^7.12.1",
28+
"@babel/core": "^7.12.3",
29+
"@babel/plugin-proposal-class-properties": "^7.12.1",
30+
"@babel/preset-env": "^7.12.7",
31+
"@hotwired/turbo": "^7.0.0-beta.4",
32+
"@symfony/stimulus-testing": "^1.1.0",
33+
"jest-canvas-mock": "^2.3.0",
34+
"stimulus": "^2.0.0"
35+
},
36+
"jest": {
37+
"testRegex": "test/.*\\.test.js",
38+
"setupFilesAfterEnv": [
39+
"./test/setup.js"
40+
]
41+
}
42+
}

src/Turbo/Resources/assets/test/turbo_stream_mercure_controller.test.js renamed to src/Turbo/Bridge/Mercure/Resources/assets/test/turbo_stream_controller.test.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,15 @@
1212
import { Application } from 'stimulus';
1313
import { getByTestId } from '@testing-library/dom';
1414
import { clearDOM, mountDOM } from '@symfony/stimulus-testing';
15-
import TurboStreamController from '../src/turbo_stream_mercure_controller.js';
15+
import TurboStreamController from '../src/turbo_stream_controller.js';
1616

1717
const startStimulus = () => {
1818
const application = Application.start();
19-
application.register('symfony--ux-turbo--turbo-stream-mercure', TurboStreamController);
19+
application.register('symfony--ux-turbo-mercure--turbo-stream', TurboStreamController);
2020
};
2121

2222
/* eslint-disable no-undef */
23-
describe('TurboStreamMercureController', () => {
23+
describe('TurboStreamController', () => {
2424
let container;
2525

2626
beforeEach(() => {
@@ -31,7 +31,7 @@ describe('TurboStreamMercureController', () => {
3131
}));
3232

3333
container = mountDOM(
34-
'<div data-testid="turbo-stream-mercure" data-controller="symfony--ux-turbo--turbo-stream-mercure" data-symfony--ux-turbo--turbo-stream-mercure-hub-value="https://example.com/.well-known/mercure" data-symfony--ux-turbo--turbo-stream-mercure-topic-value="foo"></div>'
34+
'<div data-testid="turbo-stream-mercure" data-controller="symfony--ux-turbo-mercure--turbo-stream" data-symfony--ux-turbo-mercure--turbo-stream-hub-value="https://example.com/.well-known/mercure" data-symfony--ux-turbo-mercure--turbo-stream-topic-value="foo"></div>'
3535
);
3636
});
3737

@@ -44,7 +44,7 @@ describe('TurboStreamMercureController', () => {
4444

4545
// smoke test
4646
expect(getByTestId(container, 'turbo-stream-mercure')).toHaveAttribute(
47-
'data-symfony--ux-turbo--turbo-stream-mercure-topic-value',
47+
'data-symfony--ux-turbo-mercure--turbo-stream-topic-value',
4848
'foo'
4949
);
5050
});

src/Turbo/Mercure/TurboStreamListenRenderer.php renamed to src/Turbo/Bridge/Mercure/TurboStreamListenRenderer.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
* file that was distributed with this source code.
1010
*/
1111

12-
namespace Symfony\UX\Turbo\Mercure;
12+
namespace Symfony\UX\Turbo\Bridge\Mercure;
1313

1414
use Symfony\Component\Mercure\HubInterface;
1515
use Symfony\UX\Turbo\Broadcaster\IdAccessor;
@@ -52,7 +52,7 @@ public function renderTurboStreamListen(Environment $env, $topic): string
5252

5353
return $this->stimulusTwigExtension->renderStimulusController(
5454
$env,
55-
'symfony/ux-turbo/turbo-stream-mercure',
55+
'symfony/ux-turbo-mercure/turbo-stream',
5656
['topic' => $topic, 'hub' => $this->hub->getPublicUrl()]
5757
);
5858
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
{
2+
"name": "symfony/ux-turbo-mercure",
3+
"type": "library",
4+
"description": "Mercure bridge for Symfony UX Turbo",
5+
"keywords": [
6+
"symfony-ux",
7+
"turbo",
8+
"hotwire",
9+
"mercure"
10+
],
11+
"homepage": "https://symfony.com",
12+
"license": "MIT",
13+
"authors": [
14+
{
15+
"name": "Kévin Dunglas",
16+
"email": "[email protected]"
17+
},
18+
{
19+
"name": "Symfony Community",
20+
"homepage": "https://symfony.com/contributors"
21+
}
22+
],
23+
"autoload": {
24+
"psr-4": {
25+
"Symfony\\UX\\Turbo\\Bridge\\Mercure\\": ""
26+
}
27+
},
28+
"require": {
29+
"php": ">=7.2.5",
30+
"symfony/mercure-bundle": "^0.3",
31+
"symfony/twig-bundle": "^5.2",
32+
"symfony/ux-turbo": "^1.3"
33+
},
34+
"extra": {
35+
"branch-alias": {
36+
"dev-main": "1.3-dev"
37+
},
38+
"thanks": {
39+
"name": "symfony/ux-turbo",
40+
"url": "https://github.com/symfony/ux"
41+
}
42+
},
43+
"minimum-stability": "dev"
44+
}

src/Turbo/DependencyInjection/Configuration.php

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313

1414
use Doctrine\Bundle\DoctrineBundle\DoctrineBundle;
1515
use Doctrine\ORM\EntityManagerInterface;
16-
use Symfony\Bundle\MercureBundle\MercureBundle;
1716
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
1817
use Symfony\Component\Config\Definition\ConfigurationInterface;
1918

@@ -47,17 +46,6 @@ public function getConfigTreeBuilder(): TreeBuilder
4746
->end()
4847
->end()
4948
->scalarNode('default_transport')->defaultValue('default')->end()
50-
->arrayNode('mercure')
51-
->{class_exists(MercureBundle::class) ? 'canBeDisabled' : 'canBeEnabled'}()
52-
->info('If no Mercure hubs are configured explicitly, the default Mercure hub will be used.')
53-
->children()
54-
->arrayNode('hubs')
55-
->fixXmlConfig('hub')
56-
->info('The name of the Mercure hubs (configured in MercureBundle) to use as transports')
57-
->scalarPrototype()->end()
58-
->end()
59-
->end()
60-
->end()
6149
->end()
6250
;
6351

src/Turbo/DependencyInjection/TurboExtension.php

Lines changed: 0 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,13 @@
1313

1414
use Doctrine\Bundle\DoctrineBundle\DoctrineBundle;
1515
use Doctrine\ORM\EntityManagerInterface;
16-
use Symfony\Bundle\MercureBundle\MercureBundle;
1716
use Symfony\Bundle\TwigBundle\TwigBundle;
1817
use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException;
1918
use Symfony\Component\Config\FileLocator;
2019
use Symfony\Component\Config\Loader\LoaderInterface;
21-
use Symfony\Component\DependencyInjection\ChildDefinition;
2220
use Symfony\Component\DependencyInjection\ContainerBuilder;
2321
use Symfony\Component\DependencyInjection\Loader\PhpFileLoader;
24-
use Symfony\Component\DependencyInjection\Reference;
2522
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
26-
use Symfony\Component\Mercure\HubInterface;
2723
use Symfony\UX\Turbo\Broadcaster\BroadcasterInterface;
2824
use Symfony\UX\Turbo\Twig\TurboStreamListenRendererInterface;
2925

@@ -48,7 +44,6 @@ public function load(array $configs, ContainerBuilder $container): void
4844

4945
$this->registerTwig($config, $container);
5046
$this->registerBroadcast($config, $container, $loader);
51-
$this->registerMercureTransports($config, $container, $loader);
5247
}
5348

5449
/**
@@ -99,55 +94,4 @@ private function registerBroadcast(array $config, ContainerBuilder $container, L
9994
throw new InvalidConfigurationException('You cannot use the Doctrine ORM integration as the Doctrine bundle is not installed. Try running "composer require symfony/orm-pack".');
10095
}
10196
}
102-
103-
/**
104-
* @param array<string, mixed> $config
105-
*/
106-
private function registerMercureTransports(array $config, ContainerBuilder $container, LoaderInterface $loader): void
107-
{
108-
if (!$config['mercure']['enabled']) {
109-
return;
110-
}
111-
112-
$missingDeps = array_filter([
113-
'symfony/mercure-bundle' => !class_exists(MercureBundle::class),
114-
'symfony/twig-pack' => !class_exists(TwigBundle::class),
115-
]);
116-
117-
if ($missingDeps) {
118-
throw new InvalidConfigurationException(sprintf('You cannot use the Mercure integration as some required dependencies are missing. Try running "composer require %s".', implode(' ', $missingDeps)));
119-
}
120-
121-
$loader->load('mercure.php');
122-
123-
if (!$config['mercure']['hubs']) {
124-
// Wire the default Mercure hub
125-
$this->registerMercureTransport($container, $config, $config['default_transport'], HubInterface::class);
126-
127-
return;
128-
}
129-
130-
foreach ($config['mercure']['hubs'] as $hub) {
131-
$this->registerMercureTransport($container, $config, $hub, "mercure.hub.{$hub}");
132-
}
133-
}
134-
135-
/**
136-
* @param array<string, mixed> $config
137-
*/
138-
private function registerMercureTransport(ContainerBuilder $container, array $config, string $name, string $hubId): void
139-
{
140-
$renderer = $container->setDefinition("turbo.mercure.{$name}.renderer", new ChildDefinition('turbo.stream_listen_renderer.mercure'));
141-
$renderer->replaceArgument(0, new Reference($hubId));
142-
$renderer->addTag('turbo.renderer.stream_listen', ['transport' => $name]);
143-
144-
if (!$config['broadcast']['enabled']) {
145-
return;
146-
}
147-
148-
$broadcaster = $container->setDefinition("turbo.mercure.{$name}.broadcaster", new ChildDefinition('turbo.broadcaster.mercure'));
149-
$broadcaster->replaceArgument(0, $name);
150-
$broadcaster->replaceArgument(1, new Reference($hubId));
151-
$broadcaster->addTag('turbo.broadcaster');
152-
}
15397
}

src/Turbo/Doctrine/BroadcastListener.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
use Symfony\UX\Turbo\Broadcaster\BroadcasterInterface;
2121

2222
/**
23-
* Detects changes made from Doctrine entities and broadcasts updates to the Mercure hub.
23+
* Detects changes made from Doctrine entities and broadcasts updates to the broadcasters.
2424
*
2525
* @author Kévin Dunglas <[email protected]>
2626
*

0 commit comments

Comments
 (0)