Skip to content

Commit 1b8cbb3

Browse files
authored
Merge pull request #4 from Flowpack/neos-9
BUGFIX: Neos 9.0 compatibility
2 parents b76e068 + ee341b1 commit 1b8cbb3

6 files changed

Lines changed: 128 additions & 23 deletions

Classes/Aspect/CollectDebugInformationAspect.php

Lines changed: 5 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@
1616

1717
use Doctrine\ORM\EntityManagerInterface;
1818
use Flowpack\Neos\Debug\DataCollector\CacheAccessCollector;
19+
use Flowpack\Neos\Debug\DataCollector\ContentContextMetricsCollectorInterface;
1920
use Flowpack\Neos\Debug\DataCollector\MessagesCollector;
2021
use Flowpack\Neos\Debug\Domain\Model\Dto\ResourceStreamRequest;
2122
use Flowpack\Neos\Debug\Logging\DebugStack;
2223
use Flowpack\Neos\Debug\Service\DebugService;
2324
use GuzzleHttp\Psr7\Response;
2425
use GuzzleHttp\Psr7\Utils;
25-
use Neos\ContentRepository\Domain\Service\ContextFactoryInterface;
2626
use Neos\Flow\Annotations as Flow;
2727
use Neos\Flow\Aop\JoinPointInterface;
2828
use Neos\Flow\ResourceManagement\PersistentResource;
@@ -41,9 +41,6 @@ class CollectDebugInformationAspect
4141

4242
protected DebugStack $sqlLoggingStack;
4343

44-
#[Flow\Inject]
45-
protected ContextFactoryInterface $contextFactory;
46-
4744
protected int $contentCacheHits = 0;
4845

4946
/**
@@ -67,6 +64,9 @@ class CollectDebugInformationAspect
6764
#[Flow\Inject]
6865
protected CacheAccessCollector $cacheAccessCollector;
6966

67+
#[Flow\Inject()]
68+
protected ContentContextMetricsCollectorInterface $contentContextMetricsCollector;
69+
7070
#[Flow\Pointcut("setting(Flowpack.Neos.Debug.enabled)")]
7171
public function debuggingActive(): void
7272
{
@@ -120,24 +120,6 @@ protected function addDebugValues(JoinPointInterface $joinPoint): string|Respons
120120

121121
$groupedQueries = $this->groupQueries($this->sqlLoggingStack->queries);
122122

123-
// Analyse ContentContext
124-
$contentContextMetrics = [];
125-
foreach ($this->contextFactory->getInstances() as $contextIdentifier => $context) {
126-
$firstLevelNodeCache = $context->getFirstLevelNodeCache();
127-
$contentContextMetrics[$contextIdentifier] = [
128-
'workspace' => $context->getWorkspace()->getName(),
129-
'dimensions' => $context->getDimensions(),
130-
'invisibleContentShown' => $context->isInvisibleContentShown(),
131-
'removedContentShown' => $context->isRemovedContentShown(),
132-
'inaccessibleContentShown' => $context->isInaccessibleContentShown(),
133-
'firstLevelNodeCache' => [
134-
'nodesByPath' => count(ObjectAccess::getProperty($firstLevelNodeCache, 'nodesByPath', true)),
135-
'nodesByIdentifier' => count(ObjectAccess::getProperty($firstLevelNodeCache, 'nodesByIdentifier', true)),
136-
'childNodesByPathAndNodeTypeFilter' => count(ObjectAccess::getProperty($firstLevelNodeCache, 'childNodesByPathAndNodeTypeFilter', true)),
137-
],
138-
];
139-
}
140-
141123
// TODO: Introduce DTOs for the data
142124
$data = [
143125
'startRenderAt' => $startRenderAt,
@@ -160,7 +142,7 @@ protected function addDebugValues(JoinPointInterface $joinPoint): string|Respons
160142
// TODO: Iterate over all existing collectors
161143
$this->messagesCollector->getName() => $this->messagesCollector->collect(),
162144
$this->cacheAccessCollector->getName() => $this->cacheAccessCollector->collect(),
163-
'contentContextMetrics' => $contentContextMetrics,
145+
$this->contentContextMetricsCollector->getName() => $this->contentContextMetricsCollector->collect(),
164146
]
165147
];
166148

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Flowpack\Neos\Debug\DataCollector;
6+
7+
use Flowpack\Neos\Debug\DataFormatter\DataFormatterInterface;
8+
use Neos\Flow\Annotations as Flow;
9+
use Neos\Flow\ObjectManagement\ObjectManagerInterface;
10+
11+
class ContentContextMetricsCollectorFactory
12+
{
13+
public function __construct(
14+
protected ObjectManagerInterface $objectManager,
15+
protected ?DataFormatterInterface $dataFormatter = null,
16+
)
17+
{
18+
}
19+
20+
public function build(): ?ContentContextMetricsCollectorInterface
21+
{
22+
// ContextFactoryInterface only exists before Neos 9.x
23+
if (interface_exists(\Neos\ContentRepository\Domain\Service\ContextFactoryInterface::class)) {
24+
return new ContentContextMetricsCollectorNeos8(
25+
$this->dataFormatter,
26+
$this->objectManager->get(\Neos\ContentRepository\Domain\Service\ContextFactoryInterface::class)
27+
);
28+
} else {
29+
return new ContentContextMetricsCollectorNeos9(
30+
$this->dataFormatter
31+
);
32+
}
33+
}
34+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?php
2+
declare(strict_types=1);
3+
4+
namespace Flowpack\Neos\Debug\DataCollector;
5+
6+
interface ContentContextMetricsCollectorInterface
7+
{
8+
9+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Flowpack\Neos\Debug\DataCollector;
6+
7+
use Flowpack\Neos\Debug\DataFormatter\DataFormatterInterface;
8+
use Neos\ContentRepository\Domain\Service\ContextFactoryInterface;
9+
use Neos\Flow\Annotations as Flow;
10+
use Neos\Utility\ObjectAccess;
11+
12+
class ContentContextMetricsCollectorNeos8 extends AbstractDataCollector implements ContentContextMetricsCollectorInterface
13+
{
14+
public function __construct(
15+
?DataFormatterInterface $dataFormatter,
16+
protected ContextFactoryInterface $contextFactory,
17+
)
18+
{
19+
parent::__construct($dataFormatter);
20+
}
21+
22+
public function getName(): string
23+
{
24+
return 'contentContextMetrics';
25+
}
26+
27+
/**
28+
* @return array<string, mixed>
29+
*/
30+
public function collect(): array
31+
{
32+
// Analyse ContentContext
33+
$contentContextMetrics = [];
34+
foreach ($this->contextFactory->getInstances() as $contextIdentifier => $context) {
35+
$firstLevelNodeCache = $context->getFirstLevelNodeCache();
36+
$contentContextMetrics[$contextIdentifier] = [
37+
'workspace' => $context->getWorkspace()->getName(),
38+
'dimensions' => $context->getDimensions(),
39+
'invisibleContentShown' => $context->isInvisibleContentShown(),
40+
'removedContentShown' => $context->isRemovedContentShown(),
41+
'inaccessibleContentShown' => $context->isInaccessibleContentShown(),
42+
'firstLevelNodeCache' => [
43+
'nodesByPath' => count(ObjectAccess::getProperty($firstLevelNodeCache, 'nodesByPath', true)),
44+
'nodesByIdentifier' => count(ObjectAccess::getProperty($firstLevelNodeCache, 'nodesByIdentifier', true)),
45+
'childNodesByPathAndNodeTypeFilter' => count(ObjectAccess::getProperty($firstLevelNodeCache, 'childNodesByPathAndNodeTypeFilter', true)),
46+
],
47+
];
48+
}
49+
return $contentContextMetrics;
50+
}
51+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Flowpack\Neos\Debug\DataCollector;
6+
7+
use Flowpack\Neos\Debug\Domain\Model\Dto\CacheMonitorMetrics;
8+
use Neos\Flow\Annotations as Flow;
9+
10+
class ContentContextMetricsCollectorNeos9 extends AbstractDataCollector implements ContentContextMetricsCollectorInterface
11+
{
12+
public function getName(): string
13+
{
14+
return 'contentContextMetrics';
15+
}
16+
17+
/**
18+
* @return array<string, mixed>
19+
*/
20+
public function collect(): array
21+
{
22+
return [];
23+
}
24+
}

Configuration/Objects.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,7 @@
11
Flowpack\Neos\Debug\DataFormatter\DataFormatterInterface:
22
className: Flowpack\Neos\Debug\DataFormatter\DataFormatter
3+
4+
Flowpack\Neos\Debug\DataCollector\ContentContextMetricsCollectorInterface:
5+
scope: singleton
6+
factoryObjectName: 'Flowpack\Neos\Debug\DataCollector\ContentContextMetricsCollectorFactory'
7+
factoryMethodName: build

0 commit comments

Comments
 (0)