Skip to content

Commit

Permalink
[Frontend] introduce template installer and new best-practice
Browse files Browse the repository at this point in the history
  • Loading branch information
dpfaffenbauer committed Oct 28, 2024
1 parent 6ff8c4a commit 2bcee62
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 3 deletions.
2 changes: 2 additions & 0 deletions src/CoreShop/Bundle/FrontendBundle/CoreShopFrontendBundle.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

use Composer\InstalledVersions;
use CoreShop\Bundle\CoreBundle\CoreShopCoreBundle;
use CoreShop\Bundle\FrontendBundle\DependencyInjection\CompilerPass\FrontendInstallerPass;
use CoreShop\Bundle\FrontendBundle\DependencyInjection\CompilerPass\RegisterFrontendControllerPass;
use Pimcore\Extension\Bundle\AbstractPimcoreBundle;
use Pimcore\HttpKernel\Bundle\DependentBundleInterface;
Expand All @@ -38,6 +39,7 @@ public function build(ContainerBuilder $container): void
parent::build($container);

$container->addCompilerPass(new RegisterFrontendControllerPass());
$container->addCompilerPass(new FrontendInstallerPass());
}

public function getNiceName(): string
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

declare(strict_types=1);

/*
* CoreShop
*
* This source file is available under two different licenses:
* - GNU General Public License version 3 (GPLv3)
* - CoreShop Commercial License (CCL)
* Full copyright and license information is available in
* LICENSE.md which is distributed with this source code.
*
* @copyright Copyright (c) CoreShop GmbH (https://www.coreshop.org)
* @license https://www.coreshop.org/license GPLv3 and CCL
*
*/

namespace CoreShop\Bundle\FrontendBundle\DependencyInjection\CompilerPass;

use CoreShop\Component\Registry\RegisterSimpleRegistryTypePass;

final class FrontendInstallerPass extends RegisterSimpleRegistryTypePass
{
public const FRONTEND_INSTALLER_TAG = 'coreshop.frontend.installer';

public function __construct()
{
parent::__construct(
'coreshop.registry.frontend.installers',
'coreshop.frontend.installers',
self::FRONTEND_INSTALLER_TAG,
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,18 @@

namespace CoreShop\Bundle\FrontendBundle\Installer;

use CoreShop\Component\Registry\ServiceRegistryInterface;

class FrontendInstaller implements FrontendInstallerInterface
{
public function __construct(private readonly \IteratorAggregate $installers)
public function __construct(private readonly ServiceRegistryInterface $installers)
{
}

public function installFrontend(string $frontendBundlePath, string $rootPath, string $templatePath): void
{
foreach ($this->installers as $installer) {
/** @var FrontendInstallerInterface $installer */
foreach ($this->installers->all() as $installer) {
$installer->installFrontend($frontendBundlePath, $rootPath, $templatePath);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
services:
coreshop.registry.frontend.installers:
class: CoreShop\Component\Registry\ServiceRegistry
arguments:
- CoreShop\Bundle\FrontendBundle\Installer\FrontendInstallerInterface
- frontend-installers
tags:
- { name: coreshop.registry, type_hint: frontendInstallers }

CoreShop\Bundle\FrontendBundle\Installer\TemplatesInstaller:
tags:
Expand All @@ -11,4 +18,4 @@ services:
CoreShop\Bundle\FrontendBundle\Installer\FrontendInstallerInterface: '@CoreShop\Bundle\FrontendBundle\Installer\FrontendInstaller'
CoreShop\Bundle\FrontendBundle\Installer\FrontendInstaller:
arguments:
- !tagged_iterator coreshop.frontend.installer
- '@coreshop.registry.cart_item_price_rule.actions'

0 comments on commit 2bcee62

Please sign in to comment.