Skip to content

Commit

Permalink
TASK: Adjust to interface changes from neos/neos-development-collecti…
Browse files Browse the repository at this point in the history
  • Loading branch information
mficzel committed Sep 8, 2023
1 parent 5b33c35 commit ff57f98
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 21 deletions.
21 changes: 13 additions & 8 deletions Classes/Aspects/FusionCachingAspect.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use Neos\Flow\Annotations as Flow;
use Neos\Flow\Aop\JoinPointInterface;
use Neos\Cache\Frontend\VariableFrontend;
use Neos\Fusion\Core\FusionConfiguration;

/**
* @Flow\Scope("singleton")
Expand All @@ -30,22 +31,26 @@ class FusionCachingAspect
protected $fusionCache;

/**
* @Flow\Around("setting(Sitegeist.Monocle.fusion.enableObjectTreeCache) && method(Sitegeist\Monocle\Fusion\FusionService->getMergedFusionObjectTreeForSitePackage())")
* @Flow\Around("setting(Sitegeist.Monocle.fusion.enableObjectTreeCache) && method(Sitegeist\Monocle\Fusion\FusionService->getFusionConfigurationForPackageKey())")
* @param JoinPointInterface $joinPoint The current join point
* @return mixed
*/
public function cacheGetMergedFusionObjectTree(JoinPointInterface $joinPoint)
public function cacheFusionConfigurationForPackageKey(JoinPointInterface $joinPoint)
{
$siteResourcesPackageKey = $joinPoint->getMethodArgument('siteResourcesPackageKey');
$cacheIdentifier = str_replace('.', '_', $siteResourcesPackageKey);
$packageKey = $joinPoint->getMethodArgument('packageKey');
$cacheIdentifier = str_replace('.', '_', $packageKey);

if ($this->fusionCache->has($cacheIdentifier)) {
$fusionObjectTree = $this->fusionCache->get($cacheIdentifier);
$fusionConfigurationArray = $this->fusionCache->get($cacheIdentifier);
$fusionConfiguration = FusionConfiguration::fromArray($fusionConfigurationArray);
} else {
$fusionObjectTree = $joinPoint->getAdviceChain()->proceed($joinPoint);
$this->fusionCache->set($cacheIdentifier, $fusionObjectTree);
/**
* @var FusionConfiguration $fusionConfiguration
*/
$fusionConfiguration = $joinPoint->getAdviceChain()->proceed($joinPoint);
$this->fusionCache->set($cacheIdentifier, $fusionConfiguration->toArray());
}

return $fusionObjectTree;
return $fusionConfiguration;
}
}
5 changes: 3 additions & 2 deletions Classes/Domain/Fusion/PrototypeRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
*/

use Neos\Flow\Annotations as Flow;
use Neos\Fusion\Core\FusionConfiguration;
use Neos\Fusion\Core\Runtime as FusionRuntime;
use Neos\Fusion\Core\RuntimeFactory as FusionRuntimeFactory;
use Sitegeist\Monocle\Fusion\FusionService;
Expand All @@ -39,8 +40,8 @@ public function findOneByPrototypeNameInSitePackage(
string $prototypeName,
string $sitePackageKey
): ?Prototype {
$fusionObjectTree = $this->fusionService->getMergedFusionObjectTreeForSitePackage($sitePackageKey);

$fusionConfiguration = $this->fusionService->getFusionConfigurationForPackageKey($sitePackageKey);
$fusionObjectTree = $fusionConfiguration->toArray();
if (isset($fusionObjectTree['__prototypes'][$prototypeName])) {
$fusionAst = $fusionObjectTree['__prototypes'][$prototypeName];
$fusionRuntime = $this->fusionRuntimeFactory->create($fusionObjectTree);
Expand Down
32 changes: 23 additions & 9 deletions Classes/Fusion/FusionService.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,28 +17,41 @@
use Neos\Flow\Package\PackageManager;
use Neos\Fusion\Core\FusionConfiguration;
use Neos\Fusion\Core\FusionSourceCodeCollection;
use \Neos\Neos\Domain\Service\FusionService as NeosFusionService;
use Neos\Fusion\Core\Parser;
use Neos\Neos\Domain\Service\FusionSourceCodeFactory;

/**
* Class FusionService
* @package Sitegeist\Monocle\Fusion
*/
class FusionService extends NeosFusionService
class FusionService
{
/**
* @Flow\Inject
* @var PackageManager
*/
protected $packageManager;

/**
* @Flow\Inject
* @var Parser
*/
protected $fusionParser;

/**
* @Flow\Inject
* @var FusionSourceCodeFactory
*/
protected $fusionSourceCodeFactory;

/**
* Returns a merged fusion object tree in the context of the given site-package
*
* @param string $siteResourcesPackageKey
* @return array The merged object tree as of the given node
* @deprecated use getFusionConfigurationForPackageKey instead
* @throws \Neos\Neos\Domain\Exception
*/
public function getMergedFusionObjectTreeForSitePackage($siteResourcesPackageKey)
public function getMergedFusionObjectTreeForSitePackage($siteResourcesPackageKey): array
{
return $this->getFusionConfigurationForPackageKey($siteResourcesPackageKey)->toArray();
}
Expand All @@ -60,7 +73,7 @@ public function getFusionConfigurationForPackageKey(string $packageKey): FusionC
$fusionCodeCollection = FusionSourceCodeCollection::tryFromFilePath('resource://Sitegeist.Monocle/Private/Fusion/Root.fusion');

// use autoinclude for neos-site packages only as this is a neos specific behavior
if ($package->getComposerManifest('type') == 'neos-site') {
if ($package->getComposerManifest('type') === 'neos-site') {
$fusionCodeCollection = $fusionCodeCollection->union(
$this->fusionSourceCodeFactory->createFromAutoIncludes()
);
Expand All @@ -76,12 +89,13 @@ public function getFusionConfigurationForPackageKey(string $packageKey): FusionC

/**
* Get all styleguide objects for the given fusion-ast
*
* @param array $fusionAst
* @return array
*/
public function getStyleguideObjectsFromFusionAst($fusionAst)
public function getStyleguideObjectsFromFusionAst(array|FusionConfiguration $fusionAst): array
{
if (is_object($fusionAst) && $fusionAst instanceof FusionConfiguration) {
$fusionAst = $fusionAst->toArray();
}

$styleguideObjects = [];
if ($fusionAst && $fusionAst['__prototypes']) {
foreach ($fusionAst['__prototypes'] as $prototypeFullName => $prototypeObject) {
Expand Down
12 changes: 10 additions & 2 deletions Classes/Fusion/FusionView.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
*/

use Neos\Flow\Annotations as Flow;
use Neos\Fusion\Core\FusionConfiguration;
use Neos\Fusion\View\FusionView as BaseFusionView;
use Neos\Fusion\Core\Runtime as FusionRuntime;
use Neos\Flow\I18n\Locale;
Expand Down Expand Up @@ -45,8 +46,15 @@ class FusionView extends BaseFusionView
*/
protected function loadFusion()
{
$fusionAst = $this->fusionService->getMergedFusionObjectTreeForSitePackage($this->getOption('packageKey'));
$this->parsedFusion = $fusionAst;
$parsedFusion = $this->fusionService->getFusionConfigurationForPackageKey($this->getOption('packageKey'));
/** @todo remove the switch after Neos 8 support is removed */
$r = new \ReflectionClass(static::class);
$parsedFusionType = $r->getProperty('parsedFusion')->getType();
if ($parsedFusionType?->getName() === FusionConfiguration::class) {
$this->parsedFusion = $parsedFusion;
} else {
$this->parsedFusion = $parsedFusion->toArray();
}
}

/**
Expand Down

0 comments on commit ff57f98

Please sign in to comment.