Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[AssetMapper] Allow DirectoryResource for cache #50749

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

Merged
merged 1 commit into from
Jun 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

use Symfony\Component\AssetMapper\MappedAsset;
use Symfony\Component\Config\ConfigCache;
use Symfony\Component\Config\Resource\DirectoryResource;
use Symfony\Component\Config\Resource\FileResource;
use Symfony\Component\Config\Resource\ResourceInterface;

Expand Down Expand Up @@ -59,7 +60,7 @@ private function getCacheFilePath(string $logicalPath, string $sourcePath): stri
*/
private function collectResourcesFromAsset(MappedAsset $mappedAsset): array
{
$resources = array_map(fn (string $path) => new FileResource($path), $mappedAsset->getFileDependencies());
$resources = array_map(fn (string $path) => is_dir($path) ? new DirectoryResource($path) : new FileResource($path), $mappedAsset->getFileDependencies());
$resources[] = new FileResource($mappedAsset->sourcePath);

foreach ($mappedAsset->getDependencies() as $dependency) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use Symfony\Component\AssetMapper\Factory\MappedAssetFactoryInterface;
use Symfony\Component\AssetMapper\MappedAsset;
use Symfony\Component\Config\ConfigCache;
use Symfony\Component\Config\Resource\DirectoryResource;
use Symfony\Component\Config\Resource\FileResource;
use Symfony\Component\Filesystem\Filesystem;

Expand Down Expand Up @@ -103,6 +104,7 @@ public function testAssetConfigCacheResourceContainsDependencies()

// just adding any file as an example
$mappedAsset->addFileDependency(__DIR__.'/../fixtures/importmap.php');
$mappedAsset->addFileDependency(__DIR__.'/../fixtures/dir3');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we have a addDirectoryDependency instead to make the intent more clear ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps - though I'm also trying to keep the patch on the smaller side.

We could merge this as-is, then think about a more generic method name like addPathDependency() for 6.4.


$factory = $this->createMock(MappedAssetFactoryInterface::class);
$factory->expects($this->once())
Expand All @@ -117,13 +119,14 @@ public function testAssetConfigCacheResourceContainsDependencies()
$cachedFactory->createMappedAsset('file1.css', $sourcePath);

$configCacheMetadata = $this->loadConfigCacheMetadataFor($mappedAsset);
$this->assertCount(4, $configCacheMetadata);
$this->assertCount(5, $configCacheMetadata);
$this->assertInstanceOf(FileResource::class, $configCacheMetadata[0]);
$this->assertInstanceOf(FileResource::class, $configCacheMetadata[1]);
$this->assertInstanceOf(DirectoryResource::class, $configCacheMetadata[1]);
$this->assertInstanceOf(FileResource::class, $configCacheMetadata[2]);
$this->assertSame(realpath(__DIR__.'/../fixtures/importmap.php'), $configCacheMetadata[0]->getResource());
$this->assertSame($mappedAsset->sourcePath, $configCacheMetadata[1]->getResource());
$this->assertSame($dependentOnContentAsset->sourcePath, $configCacheMetadata[2]->getResource());
$this->assertSame($deeplyNestedAsset->sourcePath, $configCacheMetadata[3]->getResource());
$this->assertSame($mappedAsset->sourcePath, $configCacheMetadata[2]->getResource());
$this->assertSame($dependentOnContentAsset->sourcePath, $configCacheMetadata[3]->getResource());
$this->assertSame($deeplyNestedAsset->sourcePath, $configCacheMetadata[4]->getResource());
}

private function loadConfigCacheMetadataFor(MappedAsset $mappedAsset): array
Expand Down