-
-
Notifications
You must be signed in to change notification settings - Fork 219
/
Package.php
100 lines (91 loc) · 4.72 KB
/
Package.php
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
<?php
namespace Neos\ContentRepository;
/*
* This file is part of the Neos.ContentRepository package.
*
* (c) Contributors of the Neos Project - www.neos.io
*
* This package is Open Source Software. For the full copyright and license
* information, please view the LICENSE file which was distributed with this
* source code.
*/
use Neos\ContentRepository\Configuration\NodeTypesLoader;
use Neos\ContentRepository\Domain\Model\Workspace;
use Neos\Flow\Configuration\ConfigurationManager;
use Neos\Flow\Configuration\Source\YamlSource;
use Neos\Flow\Core\Booting\Sequence;
use Neos\Flow\Core\Bootstrap;
use Neos\Flow\Monitor\FileMonitor;
use Neos\Flow\Package\Package as BasePackage;
use Neos\Flow\Package\PackageManager;
use Neos\Flow\Persistence\Doctrine\PersistenceManager;
use Neos\ContentRepository\Domain\Model\Node;
use Neos\ContentRepository\Domain\Repository\NodeDataRepository;
use Neos\ContentRepository\Domain\Service\Context;
use Neos\ContentRepository\Domain\Service\ContextFactoryInterface;
use Neos\Utility\Files;
/**
* The ContentRepository Package
*/
class Package extends BasePackage
{
/**
* Invokes custom PHP code directly after the package manager has been initialized.
*
* @param Bootstrap $bootstrap The current bootstrap
* @return void
*/
public function boot(Bootstrap $bootstrap)
{
$dispatcher = $bootstrap->getSignalSlotDispatcher();
$dispatcher->connect(PersistenceManager::class, 'allObjectsPersisted', NodeDataRepository::class, 'flushNodeRegistry');
$dispatcher->connect(NodeDataRepository::class, 'repositoryObjectsPersisted', NodeDataRepository::class, 'flushNodeRegistry');
$dispatcher->connect(Node::class, 'nodePathChanged', function () use ($bootstrap) {
$contextFactory = $bootstrap->getObjectManager()->get(ContextFactoryInterface::class);
/** @var Context $contextInstance */
foreach ($contextFactory->getInstances() as $contextInstance) {
$contextInstance->getFirstLevelNodeCache()->flush();
}
});
// this fixes https://github.com/neos/neos-development-collection/issues/3173
$dispatcher->connect(Workspace::class, 'afterNodePublishing', function () use ($bootstrap) {
$contextFactory = $bootstrap->getObjectManager()->get(ContextFactoryInterface::class);
foreach ($contextFactory->getInstances() as $contextInstance) {
$contextInstance->getFirstLevelNodeCache()->flush();
}
});
$dispatcher->connect(ConfigurationManager::class, 'configurationManagerReady', function (ConfigurationManager $configurationManager) {
$configurationManager->registerConfigurationType('NodeTypes', new NodeTypesLoader(new YamlSource()));
});
if ($bootstrap->getContext()->isProduction()) {
return;
}
$dispatcher->connect(Sequence::class, 'afterInvokeStep', function ($step) use ($bootstrap) {
if ($step->getIdentifier() === 'neos.flow:systemfilemonitor') {
$nodeTypeConfigurationFileMonitor = FileMonitor::createFileMonitorAtBoot('ContentRepository_NodeTypesConfiguration', $bootstrap);
/** @var PackageManager $packageManager */
$packageManager = $bootstrap->getEarlyInstance(PackageManager::class);
foreach ($packageManager->getFlowPackages() as $packageKey => $package) {
if ($packageManager->isPackageFrozen($packageKey)) {
continue;
}
if (file_exists($package->getConfigurationPath())) {
$nodeTypeConfigurationFileMonitor->monitorDirectory($package->getConfigurationPath(), 'NodeTypes(\..+)\.yaml');
}
$nodeTypesConfigurationDirectory = Files::concatenatePaths([$package->getPackagePath(), 'NodeTypes']);
if (\is_dir($nodeTypesConfigurationDirectory)) {
$nodeTypeConfigurationFileMonitor->monitorDirectory($nodeTypesConfigurationDirectory, '(.+)\.yaml');
}
}
$nodeTypeConfigurationFileMonitor->monitorDirectory(FLOW_PATH_CONFIGURATION, 'NodeTypes(\..+)\.yaml');
$nodeTypeConfigurationFileMonitor->detectChanges();
$nodeTypeConfigurationFileMonitor->shutdownObject();
}
});
$dispatcher->connect(FileMonitor::class, 'filesHaveChanged', static function (string $fileMonitorIdentifier) use ($bootstrap) {
if ($fileMonitorIdentifier === 'ContentRepository_NodeTypesConfiguration') {
$bootstrap->getObjectManager()->get(ConfigurationManager::class)->refreshConfiguration();
}
});
}
}