-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathBlockBundle.php
More file actions
77 lines (63 loc) · 2.3 KB
/
Copy pathBlockBundle.php
File metadata and controls
77 lines (63 loc) · 2.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
<?php
declare(strict_types=1);
namespace Pixel\BlockBundle;
use Nijens\ProtocolStream\Stream\Stream;
use Nijens\ProtocolStream\StreamManager;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\HttpKernel\Bundle\Bundle;
use Symfony\Component\HttpKernel\KernelInterface;
/**
* Bundle class for Pixel BlockBundle that provides Sulu content blocks.
*/
class BlockBundle extends Bundle
{
private const STREAM_NAME = 'sulu-block-bundle';
private ?StreamManager $streamManager = null;
public function build(ContainerBuilder $container): void
{
$rootDirectory = $container->getParameter('kernel.project_dir');
if (! is_string($rootDirectory)) {
throw new \RuntimeException('kernel.project_dir parameter must be a string');
}
$this->registerStream($rootDirectory);
}
public function boot(): void
{
$kernel = $this->container?->get('kernel');
if (! $kernel instanceof KernelInterface) {
throw new \RuntimeException('Kernel service not available');
}
$this->registerStream($kernel->getProjectDir());
parent::boot();
}
/**
* Register the protocol stream for template management.
*/
private function registerStream(string $rootDirectory): void
{
if ($this->streamManager === null) {
$this->streamManager = StreamManager::create();
}
if ($this->streamManager->getStream(self::STREAM_NAME) !== null) {
return;
}
$streamPaths = $this->getStreamPaths($rootDirectory);
$stream = new Stream(self::STREAM_NAME, $streamPaths);
$this->streamManager->registerStream($stream);
}
/**
* Get the paths for the protocol stream.
*
* @return array<string, string>
*/
private function getStreamPaths(string $rootDirectory): array
{
return [
'blocks' => __DIR__ . '/Resources/templates/blocks/',
'forms' => __DIR__ . '/Resources/forms/',
'properties' => __DIR__ . '/Resources/templates/properties/',
'app-properties' => $rootDirectory . '/config/templates/PixelSuluBlockBundle/properties/',
'app-property-params' => $rootDirectory . '/config/templates/PixelSuluBlockBundle/params/',
];
}
}