From 85c0ef6b416451739ada6d13d5ec6e3128ce3d69 Mon Sep 17 00:00:00 2001 From: Ryan Weaver Date: Thu, 23 Nov 2023 20:30:30 -0500 Subject: [PATCH] [AssetMapper] Adding an option (true by default) to not publish dot files --- .../DependencyInjection/Configuration.php | 5 +++++ .../FrameworkExtension.php | 3 ++- .../Resources/config/asset_mapper.php | 1 + .../Resources/config/schema/symfony-1.0.xsd | 1 + .../DependencyInjection/ConfigurationTest.php | 2 ++ .../AssetMapper/AssetMapperRepository.php | 5 +++++ .../Tests/AssetMapperRepositoryTest.php | 20 +++++++++++++++++++ .../Tests/Fixtures/dot_file/.dotfile | 1 + 8 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 src/Symfony/Component/AssetMapper/Tests/Fixtures/dot_file/.dotfile diff --git a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php index dc5290c098438..2c21302bed491 100644 --- a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php +++ b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php @@ -899,6 +899,11 @@ private function addAssetMapperSection(ArrayNodeDefinition $rootNode, callable $ ->prototype('scalar')->end() ->example(['*/assets/build/*', '*/*_.scss']) ->end() + // boolean called defaulting to true + ->booleanNode('exclude_dotfiles') + ->info('If true, any files starting with "." will be excluded from the asset mapper') + ->defaultTrue() + ->end() ->booleanNode('server') ->info('If true, a "dev server" will return the assets from the public directory (true in "debug" mode only by default)') ->defaultValue($this->debug) diff --git a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php index 132904c303f1d..8a42bfb29ee20 100644 --- a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php +++ b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php @@ -1351,7 +1351,8 @@ private function registerAssetMapperConfiguration(array $config, ContainerBuilde $container->getDefinition('asset_mapper.repository') ->setArgument(0, $paths) - ->setArgument(2, $excludedPathPatterns); + ->setArgument(2, $excludedPathPatterns) + ->setArgument(3, $config['exclude_dotfiles']); $container->getDefinition('asset_mapper.public_assets_path_resolver') ->setArgument(0, $config['public_prefix']); diff --git a/src/Symfony/Bundle/FrameworkBundle/Resources/config/asset_mapper.php b/src/Symfony/Bundle/FrameworkBundle/Resources/config/asset_mapper.php index 9139a6c898fc9..f41574d3b58da 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Resources/config/asset_mapper.php +++ b/src/Symfony/Bundle/FrameworkBundle/Resources/config/asset_mapper.php @@ -74,6 +74,7 @@ abstract_arg('array of asset mapper paths'), param('kernel.project_dir'), abstract_arg('array of excluded path patterns'), + abstract_arg('exclude dot files'), ]) ->set('asset_mapper.public_assets_path_resolver', PublicAssetsPathResolver::class) diff --git a/src/Symfony/Bundle/FrameworkBundle/Resources/config/schema/symfony-1.0.xsd b/src/Symfony/Bundle/FrameworkBundle/Resources/config/schema/symfony-1.0.xsd index dfdf84893c82c..6483732ef7364 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Resources/config/schema/symfony-1.0.xsd +++ b/src/Symfony/Bundle/FrameworkBundle/Resources/config/schema/symfony-1.0.xsd @@ -196,6 +196,7 @@ + diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/ConfigurationTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/ConfigurationTest.php index ab08f47655a8b..42619d07f3c3b 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/ConfigurationTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/ConfigurationTest.php @@ -137,6 +137,7 @@ public function testAssetMapperCanBeEnabled() 'importmap_polyfill' => 'es-module-shims', 'vendor_dir' => '%kernel.project_dir%/assets/vendor', 'importmap_script_attributes' => [], + 'exclude_dotfiles' => true, ]; $this->assertEquals($defaultConfig, $config['asset_mapper']); @@ -674,6 +675,7 @@ protected static function getBundleDefaultConfig() 'importmap_polyfill' => 'es-module-shims', 'vendor_dir' => '%kernel.project_dir%/assets/vendor', 'importmap_script_attributes' => [], + 'exclude_dotfiles' => true, ], 'cache' => [ 'pools' => [], diff --git a/src/Symfony/Component/AssetMapper/AssetMapperRepository.php b/src/Symfony/Component/AssetMapper/AssetMapperRepository.php index eb9e20506baa4..b001c49bead9e 100644 --- a/src/Symfony/Component/AssetMapper/AssetMapperRepository.php +++ b/src/Symfony/Component/AssetMapper/AssetMapperRepository.php @@ -33,6 +33,7 @@ public function __construct( private readonly array $paths, private readonly string $projectRootDir, private readonly array $excludedPathPatterns = [], + private readonly bool $excludeDotFiles = true, ) { } @@ -185,6 +186,10 @@ private function isExcluded(string $filesystemPath): bool } } + if ($this->excludeDotFiles && str_starts_with(basename($filesystemPath), '.')) { + return true; + } + return false; } } diff --git a/src/Symfony/Component/AssetMapper/Tests/AssetMapperRepositoryTest.php b/src/Symfony/Component/AssetMapper/Tests/AssetMapperRepositoryTest.php index 3fe2e9aadeec4..17abd534eb6c2 100644 --- a/src/Symfony/Component/AssetMapper/Tests/AssetMapperRepositoryTest.php +++ b/src/Symfony/Component/AssetMapper/Tests/AssetMapperRepositoryTest.php @@ -162,4 +162,24 @@ public function testExcludedPaths() $this->assertNull($repository->find('file3.css')); $this->assertNull($repository->findLogicalPath(__DIR__.'/Fixtures/dir2/file3.css')); } + + public function testDotFilesExcluded() + { + $repository = new AssetMapperRepository([ + 'dot_file' => '', + ], __DIR__.'/Fixtures', [], true); + + $actualAssets = array_keys($repository->all()); + $this->assertEquals([], $actualAssets); + } + + public function testDotFilesNotExcluded() + { + $repository = new AssetMapperRepository([ + 'dot_file' => '', + ], __DIR__.'/Fixtures', [], false); + + $actualAssets = array_keys($repository->all()); + $this->assertEquals(['.dotfile'], $actualAssets); + } } diff --git a/src/Symfony/Component/AssetMapper/Tests/Fixtures/dot_file/.dotfile b/src/Symfony/Component/AssetMapper/Tests/Fixtures/dot_file/.dotfile new file mode 100644 index 0000000000000..92b7ad31be4cf --- /dev/null +++ b/src/Symfony/Component/AssetMapper/Tests/Fixtures/dot_file/.dotfile @@ -0,0 +1 @@ +I'm a dot file! pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy