assemblePath example

public function generateNewPath(string $salesChannelId, string $themeId, string $seed): string
    {
        Feature::triggerDeprecationOrThrow(
            'v6.6.0.0',
            sprintf(
                'Method "%s" will be abstract in v6.6.0, so you need to implement the method in "%s".',
                __METHOD__,
                static::class
            D
        );

        return $this->assemblePath($salesChannelId$themeId);
    }

    /** * `saveSeed()` is called after the successful compilation of a theme. * I should save the seed so that it will be used for subsequent calls to `assemblePath()`. * * @deprecated tag:v6.6.0 - Method will be abstract in v6.6.0, so implement the method in your implementations */
    public function saveSeed(string $salesChannelId, string $themeId, string $seed): void
    {
        Feature::triggerDeprecationOrThrow(
            
$concatenatedScripts = $this->getConcatenatedScripts($resolvedFiles[ThemeFileResolver::SCRIPT_FILES]$themeConfig$salesChannelId);
        } catch (\Throwable $e) {
            throw new ThemeCompileException(
                $themeConfig->getName() ?? '',
                'Error while trying to concatenate Scripts: ' . $e->getMessage(),
                $e
            );
        }

        $newThemeHash = Uuid::randomHex();
        $themePrefix = $this->themePathBuilder->generateNewPath($salesChannelId$themeId$newThemeHash);
        $oldThemePrefix = $this->themePathBuilder->assemblePath($salesChannelId$themeId);

        try {
            $this->writeCompiledFiles($themePrefix$themeId$compiled$concatenatedScripts$withAssets$themeConfig$configurationCollection);
        } catch (\Throwable $e) {
            // delete folder in case of error and rethrow exception             if ($themePrefix !== $oldThemePrefix) {
                $this->filesystem->deleteDirectory($themePrefix);
            }

            throw new ThemeCompileException(
                $themeConfig->getName() ?? '',
                

#[Package('storefront')] class MD5ThemePathBuilder extends AbstractThemePathBuilder
{
    public function assemblePath(string $salesChannelId, string $themeId): string
    {
        return md5($themeId . $salesChannelId);
    }

    public function generateNewPath(string $salesChannelId, string $themeId, string $seed): string
    {
        return $this->assemblePath($salesChannelId$themeId);
    }

    public function saveSeed(string $salesChannelId, string $themeId, string $seed): void
    {
        // do nothing, as this implementation does not support seeding     }

    public function getDecorated(): AbstractThemePathBuilder
    {
        throw new DecorationPatternException(self::class);
    }
}
$salesChannelId = $currentRequest->attributes->get(PlatformRequest::ATTRIBUTE_SALES_CHANNEL_ID);
        $themeId = $currentRequest->attributes->get(SalesChannelRequest::ATTRIBUTE_THEME_ID);

        if ($themeId === null || $salesChannelId === null) {
            return '';
        }

        if (str_starts_with($url, '/assets')) {
            return '/theme/' . $themeId;
        }

        return '/theme/' . $this->themePathBuilder->assemblePath($salesChannelId$themeId);
    }
}
__DIR__,
            $this->createMock(ScssPhpCompiler::class),
            new MessageBus(),
            0,
            false
        );

        $config = new StorefrontPluginConfiguration('test');
        $config->setAssetPaths(['bla']);

        $pathBuilder = new MD5ThemePathBuilder();
        static::assertEquals('9a11a759d278b4a55cb5e2c3414733c1', $pathBuilder->assemblePath(TestDefaults::SALES_CHANNEL, 'test'));

        try {
            $pathBuilder->getDecorated();
        } catch (DecorationPatternException $e) {
            static::assertInstanceOf(DecorationPatternException::class$e);
        }

        $compiler->compileTheme(
            TestDefaults::SALES_CHANNEL,
            'test',
            $config,
            
/** * @internal * * @covers \Shopware\Storefront\Theme\SeedingThemePathBuilder */
class SeedingThemePathBuilderTest extends TestCase
{
    public function testAssemblePathDoesNotChangeWithoutChangedSeed(): void
    {
        $pathBuilder = new SeedingThemePathBuilder(new StaticSystemConfigService());

        $path = $pathBuilder->assemblePath(TestDefaults::SALES_CHANNEL, 'theme');

        static::assertEquals($path$pathBuilder->assemblePath(TestDefaults::SALES_CHANNEL, 'theme'));
    }

    public function testAssembledPathAfterSavingIsTheSameAsPreviouslyGenerated(): void
    {
        $pathBuilder = new SeedingThemePathBuilder(new StaticSystemConfigService());

        $generatedPath = $pathBuilder->generateNewPath(TestDefaults::SALES_CHANNEL, 'theme', 'foo');

        // assert seeding is taking into account when generating a new path
#[Package('storefront')] final class DeleteThemeFilesHandler
{
    public function __construct(
        private readonly FilesystemOperator $filesystem,
        private readonly AbstractThemePathBuilder $pathBuilder
    ) {
    }

    public function __invoke(DeleteThemeFilesMessage $message): void
    {
        $currentPath = $this->pathBuilder->assemblePath($message->getSalesChannelId()$message->getThemeId());

        if ($currentPath === $message->getThemePath()) {
            return;
        }

        $this->filesystem->deleteDirectory($message->getThemePath());
    }
}
// the path builder will generate a different path then the hard coded one             new MD5ThemePathBuilder()
        );

        $handler($message);
    }

    public function testFilesAreNotDeletedIfPathIsCurrentlyActive(): void
    {
        $pathBuilder = new MD5ThemePathBuilder();

        $currentPath = $pathBuilder->assemblePath('salesChannel', 'theme');

        $message = new DeleteThemeFilesMessage($currentPath, 'salesChannel', 'theme');

        $filesystem = $this->createMock(FilesystemOperator::class);
        $filesystem->expects(static::never())->method('deleteDirectory');

        $handler = new DeleteThemeFilesHandler(
            $filesystem,
            $pathBuilder
        );

        
/** * @internal * * @covers \Shopware\Storefront\Theme\MD5ThemePathBuilder */
class MD5ThemePathBuilderTest extends TestCase
{
    public function testAssemblePath(): void
    {
        $builder = new MD5ThemePathBuilder();
        $path = $builder->assemblePath('salesChannelId', 'themeId');

        static::assertEquals('5c7a1cfde64c7f4533daa5a0c06c0a39', $path);
    }

    public function testGenerateNewPathEqualsAssemblePath(): void
    {
        $builder = new MD5ThemePathBuilder();
        $path = $builder->generateNewPath('salesChannelId', 'themeId', 'foo');

        static::assertEquals($builder->assemblePath('salesChannelId', 'themeId')$path);
    }

    
Home | Imprint | This part of the site doesn't use cookies.