8000 Making AssetInterface::allAssets() iterable · symfony/symfony@a89b732 · GitHub
[go: up one dir, main page]

Skip to content

Commit a89b732

Browse files
committed
Making AssetInterface::allAssets() iterable
1 parent 05fc854 commit a89b732

File tree

5 files changed

+9
-12
lines changed

5 files changed

+9
-12
lines changed

src/Symfony/Component/AssetMapper/AssetMapper.php

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,21 +44,15 @@ public function getAsset(string $logicalPath): ?MappedAsset
4444
return $this->mappedAssetFactory->createMappedAsset($logicalPath, $filePath);
4545
}
4646

47-
/**
48-
* @return MappedAsset[]
49-
*/
50-
public function allAssets(): array
47+
public function allAssets(): iterable
5148
{
52-
$assets = [];
5349
foreach ($this->mapperRepository->all() as $logicalPath => $filePath) {
5450
$asset = $this->getAsset($logicalPath);
5551
if (null === $asset) {
5652
throw new \LogicException(sprintf('Asset "%s" could not be found.', $logicalPath));
5753
}
58-
$assets[] = $asset;
54+
yield $asset;
5955
}
60-
61-
return $assets;
6256
}
6357

6458
public function getAssetFromSourcePath(string $sourcePath): ?MappedAsset

src/Symfony/Component/AssetMapper/AssetMapperInterface.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ public function getAsset(string $logicalPath): ?MappedAsset;
2828
/**
2929
* Returns all mapped assets.
3030
*
31-
* @return MappedAsset[]
31+
* @return iterable<MappedAsset>
3232
*/
33-
public function allAssets(): array;
33+
public function allAssets(): iterable;
3434

3535
/**
3636
* Fetches the asset given its source path (i.e. filesystem path).

src/Symfony/Component/AssetMapper/Command/AssetMapperCompileCommand.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ private function createManifestAndWriteFiles(SymfonyStyle $io, string $publicDir
118118
{
119119
$allAssets = $this->assetMapper->allAssets();
120120

121-
$io->comment(sprintf('Compiling <info>%d</info> assets to <info>%s%s</info>', \count($allAssets), $publicDir, $this->publicAssetsPathResolver->resolvePublicPath('')));
121+
$io->comment(sprintf('Compiling assets to <info>%s%s</info>', $publicDir, $this->publicAssetsPathResolver->resolvePublicPath('')));
122122
$manifest = [];
123123
foreach ($allAssets as $asset) {
124124
// $asset->getPublicPath() will start with a "/"
@@ -132,6 +132,7 @@ private function createManifestAndWriteFiles(SymfonyStyle $io, string $publicDir
132132
$manifest[$asset->getLogicalPath()] = $asset->getPublicPath();
133133
}
134134
ksort($manifest);
135+
$io->comment(sprintf('Compiled <info>%d</info> assets', \count($manifest)));
135136

136137
return $manifest;
137138
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ public function testAllAssets()
6969
});
7070

7171
$assets = $assetMapper->allAssets();
72+
$this->assertIsIterable($assets);
73+
$assets = \iterator_to_array($assets);
7274
$this->assertCount(8, $assets);
7375
$this->assertInstanceOf(MappedAsset::class, $assets[0]);
7476
}

src/Symfony/Component/AssetMapper/Tests/Command/AssetsMapperCompileCommandTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public function testAssetsAreCompiled()
5252
$res = $tester->execute([]);
5353
$this->assertSame(0, $res);
5454
// match Compiling \d+ assets
55-
$this->assertMatchesRegularExpression('/Compiling \d+ assets/', $tester->getDisplay());
55+
$this->assertMatchesRegularExpression('/Compiled \d+ assets/', $tester->getDisplay());
5656

5757
$this->assertFileExists($targetBuildDir.'/subdir/file5-f4fdc37375c7f5f2629c5659a0579967.js');
5858
$this->assertSame(<<<EOF

0 commit comments

Comments
 (0)
0