Skip to content

Commit 0b841d6

Browse files
Merge pull request #2735 from dpfaffenbauer/disable-frontendbundle
[FrontendBundle] disable by default
2 parents c0c7aa0 + aedcdee commit 0b841d6

File tree

5 files changed

+112
-1
lines changed

5 files changed

+112
-1
lines changed

src/AppKernel.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ class Kernel extends PimcoreKernel
2626
public function registerBundlesToCollection(BundleCollection $collection): void
2727
{
2828
$collection->addBundle(new \CoreShop\Bundle\CoreBundle\CoreShopCoreBundle(), 1000);
29+
$collection->addBundle(new \CoreShop\Bundle\FrontendBundle\CoreShopFrontendBundle(), 1800);
2930
$collection->addBundle(new \FriendsOfBehat\SymfonyExtension\Bundle\FriendsOfBehatSymfonyExtensionBundle());
3031
$collection->addBundle(new \CoreShop\Bundle\TestBundle\CoreShopTestBundle(), 0);
3132
}

src/BehatKernel.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ class BehatKernel extends PimcoreKernel
2323
public function registerBundlesToCollection(\Pimcore\HttpKernel\BundleCollection\BundleCollection $collection): void
2424
{
2525
$collection->addBundle(new \CoreShop\Bundle\CoreBundle\CoreShopCoreBundle(), 1000);
26+
$collection->addBundle(new \CoreShop\Bundle\FrontendBundle\CoreShopFrontendBundle(), 1800);
2627
$collection->addBundle(new \FriendsOfBehat\SymfonyExtension\Bundle\FriendsOfBehatSymfonyExtensionBundle());
2728
$collection->addBundle(new \CoreShop\Bundle\TestBundle\CoreShopTestBundle(), 0);
2829
}

src/CoreShop/Bundle/CoreBundle/CoreShopCoreBundle.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,6 @@ public static function registerDependentBundles(BundleCollection $collection): v
9595
$collection->addBundle(new CoreShopSequenceBundle(), 2100);
9696
$collection->addBundle(new CoreShopNotificationBundle(), 2000);
9797
$collection->addBundle(new CoreShopTrackingBundle(), 2000);
98-
$collection->addBundle(new CoreShopFrontendBundle(), 1800);
9998
$collection->addBundle(new CoreShopPayumBundle(), 1700);
10099
$collection->addBundle(new CoreShopProductQuantityPriceRulesBundle(), 1600);
101100
$collection->addBundle(new CoreShopWishlistBundle(), 1500);
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace CoreShop\Bundle\CoreBundle\Migrations;
6+
7+
use CoreShop\Bundle\FrontendBundle\CoreShopFrontendBundle;
8+
use Doctrine\DBAL\Schema\Schema;
9+
use Doctrine\Migrations\AbstractMigration;
10+
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
11+
use Symfony\Component\DependencyInjection\ContainerAwareTrait;
12+
13+
final class Version20241018060845 extends AbstractMigration implements ContainerAwareInterface
14+
{
15+
use ContainerAwareTrait;
16+
17+
public function getDescription(): string
18+
{
19+
return 'Enable the CoreShop FrontendBundle in bundles.php';
20+
}
21+
22+
public function up(Schema $schema): void
23+
{
24+
$this->enableFrontendBundle();
25+
}
26+
27+
public function down(Schema $schema): void
28+
{
29+
$this->disableFrontendBundle();
30+
}
31+
32+
private function enableFrontendBundle(): void
33+
{
34+
$file = $this->getConfigFile();
35+
$registered = $this->load($file);
36+
37+
$class = CoreShopFrontendBundle::class;
38+
$bundle = ltrim($class, '\\');
39+
40+
if (!isset($registered[$bundle])) {
41+
$registered[$bundle] = ['all' => true];
42+
}
43+
44+
$this->dump($file, $registered);
45+
}
46+
47+
private function disableFrontendBundle(): void
48+
{
49+
$file = $this->getConfigFile();
50+
$registered = $this->load($file);
51+
52+
$class = CoreShopFrontendBundle::class;
53+
$bundle = ltrim($class, '\\');
54+
55+
if (isset($registered[$bundle])) {
56+
unset($registered[$bundle]);
57+
}
58+
59+
$this->dump($file, $registered);
60+
}
61+
62+
private function dump(string $file, array $bundles)
63+
{
64+
$contents = $this->buildContents($bundles);
65+
66+
if (!is_dir(\dirname($file))) {
67+
if (!mkdir($concurrentDirectory = \dirname($file), 0777, true) && !is_dir($concurrentDirectory)) {
68+
throw new \RuntimeException(sprintf('Directory "%s" was not created', $concurrentDirectory));
69+
}
70+
}
71+
72+
file_put_contents($file, $contents);
73+
74+
if (\function_exists('opcache_invalidate')) {
75+
opcache_invalidate($file);
76+
}
77+
}
78+
79+
private function buildContents(array $bundles): string
80+
{
81+
$contents = "<?php\n\nreturn [\n";
82+
foreach ($bundles as $class => $envs) {
83+
$contents .= " $class::class => [";
84+
foreach ($envs as $env => $value) {
85+
$booleanValue = var_export($value, true);
86+
$contents .= "'$env' => $booleanValue, ";
87+
}
88+
$contents = substr($contents, 0, -2)."],\n";
89+
}
90+
$contents .= "];\n";
91+
92+
return $contents;
93+
}
94+
95+
private function load(string $file): array
96+
{
97+
$bundles = file_exists($file) ? (require_once $file) : [];
98+
if (!\is_array($bundles)) {
99+
$bundles = [];
100+
}
101+
102+
return $bundles;
103+
}
104+
105+
private function getConfigFile(): string
106+
{
107+
return $this->container->getParameter('kernel.project_dir').'/config/bundles.php';
108+
}
109+
}

src/Kernel.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ public function registerBundlesToCollection(BundleCollection $collection): void
2626
parent::registerBundlesToCollection($collection);
2727

2828
$collection->addBundle(new \CoreShop\Bundle\CoreBundle\CoreShopCoreBundle(), 10);
29+
$collection->addBundle(new \CoreShop\Bundle\FrontendBundle\CoreShopFrontendBundle(), 1800);
2930
$collection->addBundle(new \FriendsOfBehat\SymfonyExtension\Bundle\FriendsOfBehatSymfonyExtensionBundle());
3031
$collection->addBundle(new \CoreShop\Bundle\TestBundle\CoreShopTestBundle(), 0);
3132
}

0 commit comments

Comments
 (0)