-
-
Notifications
You must be signed in to change notification settings - Fork 364
Introduce Symfony UX Turbo #61
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
71b4520
c7ac1ec
123432d
884463f
35852c7
58df899
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
/.gitattributes export-ignore | ||
/.gitignore export-ignore | ||
/phpunit.xml.dist export-ignore | ||
/assets/test export-ignore | ||
/tests export-ignore |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
/vendor/ | ||
.phpunit.result.cache | ||
.php_cs.cache | ||
composer.lock |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
<?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\DependencyInjection; | ||
|
||
use Symfony\Component\Config\Definition\Builder\TreeBuilder; | ||
use Symfony\Component\Config\Definition\ConfigurationInterface; | ||
|
||
/** | ||
* @author Titouan Galopin <[email protected]> | ||
* | ||
* @internal | ||
*/ | ||
class Configuration implements ConfigurationInterface | ||
{ | ||
public function getConfigTreeBuilder() | ||
{ | ||
$treeBuilder = new TreeBuilder('turbo'); | ||
$rootNode = $treeBuilder->getRootNode(); | ||
|
||
$rootNode | ||
->children() | ||
->arrayNode('streams') | ||
->info('Enable this section to use Turbo Streams') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. there is nothing to enable in this config :) |
||
->children() | ||
->scalarNode('adapter') | ||
->defaultNull() | ||
->info('The service to use to create Turbo Streams') | ||
->end() | ||
->arrayNode('options') | ||
->info('Key/value options passed to the adapter to create Turbo Streams') | ||
->normalizeKeys(false) | ||
->variablePrototype() | ||
tgalopin marked this conversation as resolved.
Show resolved
Hide resolved
|
||
->end() | ||
->end() | ||
->end() | ||
->end() | ||
->end() | ||
; | ||
|
||
return $treeBuilder; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
<?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\DependencyInjection; | ||
|
||
use Symfony\Component\DependencyInjection\ContainerBuilder; | ||
use Symfony\Component\DependencyInjection\Definition; | ||
use Symfony\Component\DependencyInjection\Reference; | ||
use Symfony\Component\HttpKernel\DependencyInjection\Extension; | ||
use Symfony\UX\Turbo\Streams\MercureStreamAdapter; | ||
use Symfony\UX\Turbo\Twig\TurboFrameExtension; | ||
use Symfony\UX\Turbo\Twig\TurboStreamExtension; | ||
use Symfony\WebpackEncoreBundle\Twig\StimulusTwigExtension; | ||
use Twig\Environment; | ||
|
||
/** | ||
* @author Titouan Galopin <[email protected]> | ||
* | ||
* @internal | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think we need all those There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I may be a bit conservative regarding these annotations indeed :) . Other UX packages have these annotations as well, not sure what our policy should be on them. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm often adding As for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree with @wouterj here, we should remove |
||
*/ | ||
class TurboExtension extends Extension | ||
{ | ||
public function load(array $configs, ContainerBuilder $container) | ||
{ | ||
$configuration = new Configuration(); | ||
$config = $this->processConfiguration($configuration, $configs); | ||
|
||
// Register Turbo Streams config | ||
if (!empty($config['streams']['adapter'])) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we try to avoid using empty as much as possible |
||
$this->registerStreamsConfig($config, $container); | ||
} | ||
|
||
// Add Twig extension | ||
if (class_exists(Environment::class)) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. could use an early return statement |
||
$container | ||
->setDefinition('turbo.twig.frame_extension', new Definition(TurboFrameExtension::class)) | ||
->addTag('twig.extension') | ||
->setPublic(false) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. not needed |
||
; | ||
|
||
if (!empty($config['streams']['adapter']) && class_exists(StimulusTwigExtension::class)) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
$container | ||
->setDefinition('turbo.twig.stream_extension', new Definition(TurboStreamExtension::class)) | ||
->addArgument(new Reference('webpack_encore.twig_stimulus_extension')) | ||
->addArgument(new Reference('turbo.streams.adapter')) | ||
->addArgument($config['streams']['options'] ?? []) | ||
->addTag('twig.extension') | ||
->setPublic(false) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should be removed |
||
; | ||
} | ||
} | ||
} | ||
|
||
private function registerStreamsConfig(array $config, ContainerBuilder $container) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. maybe we can inline this method? I don't think it provides much |
||
{ | ||
// Register native stream adapters | ||
$container->setDefinition('turbo.streams.adapter.mercure', new Definition(MercureStreamAdapter::class)) | ||
->setPublic(false); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should be removed |
||
|
||
// Wire configured adapter | ||
$container->setAlias('turbo.streams.adapter', $config['streams']['adapter'])->setPublic(false); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
Copyright (c) 2020-2021 Fabien Potencier | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 2021 only :) |
||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is furnished | ||
to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
THE SOFTWARE. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe we could remove this nesting level and rename
adapter
tostream_adapter
? (same for options)