Skip to content

Commit 85c0ef6

Browse files
committed
[AssetMapper] Adding an option (true by default) to not publish dot files
1 parent b85a083 commit 85c0ef6

File tree

8 files changed

+37
-1
lines changed

8 files changed

+37
-1
lines changed

src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -899,6 +899,11 @@ private function addAssetMapperSection(ArrayNodeDefinition $rootNode, callable $
899899
->prototype('scalar')->end()
900900
->example(['*/assets/build/*', '*/*_.scss'])
901901
->end()
902+
// boolean called defaulting to true
903+
->booleanNode('exclude_dotfiles')
904+
->info('If true, any files starting with "." will be excluded from the asset mapper')
905+
->defaultTrue()
906+
->end()
902907
->booleanNode('server')
903908
->info('If true, a "dev server" will return the assets from the public directory (true in "debug" mode only by default)')
904909
->defaultValue($this->debug)

src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1351,7 +1351,8 @@ private function registerAssetMapperConfiguration(array $config, ContainerBuilde
13511351

13521352
$container->getDefinition('asset_mapper.repository')
13531353
->setArgument(0, $paths)
1354-
->setArgument(2, $excludedPathPatterns);
1354+
->setArgument(2, $excludedPathPatterns)
1355+
->setArgument(3, $config['exclude_dotfiles']);
13551356

13561357
$container->getDefinition('asset_mapper.public_assets_path_resolver')
13571358
->setArgument(0, $config['public_prefix']);

src/Symfony/Bundle/FrameworkBundle/Resources/config/asset_mapper.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@
7474
abstract_arg('array of asset mapper paths'),
7575
param('kernel.project_dir'),
7676
abstract_arg('array of excluded path patterns'),
77+
abstract_arg('exclude dot files'),
7778
])
7879

7980
->set('asset_mapper.public_assets_path_resolver', PublicAssetsPathResolver::class)

src/Symfony/Bundle/FrameworkBundle/Resources/config/schema/symfony-1.0.xsd

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,7 @@
196196
<xsd:element name="importmap-script-attribute" type="asset_mapper_attribute" minOccurs="0" maxOccurs="unbounded" />
197197
</xsd:sequence>
198198
<xsd:attribute name="enabled" type="xsd:boolean" />
199+
<xsd:attribute name="exclude-dotfiles" type="xsd:boolean" />
199200
<xsd:attribute name="server" type="xsd:boolean" />
200201
<xsd:attribute name="public-prefix" type="xsd:string" />
201202
<xsd:attribute name="missing-import-mode" type="missing-import-mode" />

src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/ConfigurationTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ public function testAssetMapperCanBeEnabled()
137137
'importmap_polyfill' => 'es-module-shims',
138138
'vendor_dir' => '%kernel.project_dir%/assets/vendor',
139139
'importmap_script_attributes' => [],
140+
'exclude_dotfiles' => true,
140141
];
141142

142143
$this->assertEquals($defaultConfig, $config['asset_mapper']);
@@ -674,6 +675,7 @@ protected static function getBundleDefaultConfig()
674675
'importmap_polyfill' => 'es-module-shims',
675676
'vendor_dir' => '%kernel.project_dir%/assets/vendor',
676677
'importmap_script_attributes' => [],
678+
'exclude_dotfiles' => true,
677679
],
678680
'cache' => [
679681
'pools' => [],

src/Symfony/Component/AssetMapper/AssetMapperRepository.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ public function __construct(
3333
private readonly array $paths,
3434
private readonly string $projectRootDir,
3535
private readonly array $excludedPathPatterns = [],
36+
private readonly bool $excludeDotFiles = true,
3637
) {
3738
}
3839

@@ -185,6 +186,10 @@ private function isExcluded(string $filesystemPath): bool
185186
}
186187
}
187188

189+
if ($this->excludeDotFiles && str_starts_with(basename($filesystemPath), '.')) {
190+
return true;
191+
}
192+
188193
return false;
189194
}
190195
}

src/Symfony/Component/AssetMapper/Tests/AssetMapperRepositoryTest.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,4 +162,24 @@ public function testExcludedPaths()
162162
$this->assertNull($repository->find('file3.css'));
163163
$this->assertNull($repository->findLogicalPath(__DIR__.'/Fixtures/dir2/file3.css'));
164164
}
165+
166+
public function testDotFilesExcluded()
167+
{
168+
$repository = new AssetMapperRepository([
169+
'dot_file' => '',
170+
], __DIR__.'/Fixtures', [], true);
171+
172+
$actualAssets = array_keys($repository->all());
173+
$this->assertEquals([], $actualAssets);
174+
}
175+
176+
public function testDotFilesNotExcluded()
177+
{
178+
$repository = new AssetMapperRepository([
179+
'dot_file' => '',
180+
], __DIR__.'/Fixtures', [], false);
181+
182+
$actualAssets = array_keys($repository->all());
183+
$this->assertEquals(['.dotfile'], $actualAssets);
184+
}
165185
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
I'm a dot file!

0 commit comments

Comments
 (0)
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