Skip to content

Commit

Permalink
Merge pull request #116 from neos/feature/create-content-context-trait
Browse files Browse the repository at this point in the history
FEATURE: Remove CreateContentContextTrait and add todos
  • Loading branch information
dlubitz authored Dec 23, 2024
2 parents ec19d6b + 1251a24 commit 411fdfc
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 1 deletion.
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
"autoload": {
"psr-4": {
"Neos\\Rector\\": "src"
}
},
"classmap": ["src/ContentRepository90/Legacy"]
},
"autoload-dev": {
"psr-4": {
Expand Down
12 changes: 12 additions & 0 deletions config/set/contentrepository-90.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@
use Neos\Rector\Generic\ValueObject\RemoveParentClass;
use Neos\Rector\Generic\ValueObject\SignalSlotToWarningComment;
use Rector\Config\RectorConfig;
use Rector\Removing\Rector\Class_\RemoveTraitUseRector;
use Rector\Renaming\Rector\MethodCall\RenameMethodRector;
use Rector\Renaming\Rector\Name\RenameClassRector;
use Rector\Renaming\ValueObject\MethodCallRename;
Expand Down Expand Up @@ -401,6 +402,12 @@
$rectorConfig->rule(ContextGetCurrentRenderingModeRector::class);
$rectorConfig->rule(FusionContextCurrentRenderingModeRector::class);

/**
* CreateContentContextTrait
*/
$methodCallToWarningComments[] = new MethodCallToWarningComment(\Neos\Neos\Controller\CreateContentContextTrait::class, 'createContentContext', '!! CreateContentContextTrait::createContentContext() is removed in Neos 9.0.');
$methodCallToWarningComments[] = new MethodCallToWarningComment(\Neos\Neos\Controller\CreateContentContextTrait::class, 'createContextMatchingNodeData', '!! CreateContentContextTrait::createContextMatchingNodeData() is removed in Neos 9.0.');

/**
* CacheLifetimeOperation
*/
Expand Down Expand Up @@ -628,6 +635,11 @@
new RemoveInjection(\Neos\ContentRepository\Domain\Repository\NodeDataRepository::class),
]);

// Remove traits which are gone
$rectorConfig->ruleWithConfiguration(RemoveTraitUseRector::class, [
\Neos\Neos\Controller\CreateContentContextTrait::class
]);

// todo these ToStringToMethodCallOrPropertyFetchRector rules are likely mostly obsolete and only to migrate from one Neos 9 beta to another but NOT for upgrading from 8.3
// see https://github.com/neos/neos-development-collection/pull/4156
$rectorConfig->ruleWithConfiguration(ToStringToMethodCallOrPropertyFetchRector::class, [
Expand Down
23 changes: 23 additions & 0 deletions src/ContentRepository90/Legacy/CreateContentContextTrait.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php
namespace Neos\Neos\Controller;

use Neos\Flow\Annotations as Flow;
use Neos\Neos\Domain\Service\ContentContext;
use Neos\ContentRepository\Domain\Model\NodeData;

/**
* @deprecated
*/
trait CreateContentContextTrait
{
protected function createContentContext($workspaceName, array $dimensions = []): ContentContext
{
return new ContentContext($workspaceName, $dimensions);
}

protected function createContextMatchingNodeData(NodeData $nodeData): ContentContext
{
return new ContentContext();

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?php

namespace Neos\Rector\Test;

use Neos\ContentRepository\Domain\Model\NodeData;
use Neos\Neos\Controller\CreateContentContextTrait;

class CreateContentContextClassTest extends AnotherClass
{
use CreateContentContextTrait;

public function foo() {
$workspaceName = "workspacename";
$dimensions = [];
$context = $this->createContentContext($workspaceName, $dimensions);
$context->getCurrentSite();
}

public function bar(NodeData $nodeData)
{
$context = $this->createContextMatchingNodeData($nodeData);
$context->getCurrentSite();
}
}

-----
<?php

namespace Neos\Rector\Test;

use Neos\ContentRepository\Domain\Model\NodeData;
use Neos\Neos\Controller\CreateContentContextTrait;

class CreateContentContextClassTest extends AnotherClass
{
public function foo() {
$workspaceName = "workspacename";
$dimensions = [];
// TODO 9.0 migration: !! CreateContentContextTrait::createContentContext() is removed in Neos 9.0.

$context = $this->createContentContext($workspaceName, $dimensions);
// TODO 9.0 migration: !! ContentContext::getCurrentSite() is removed in Neos 9.0.

$context->getCurrentSite();
}

public function bar(NodeData $nodeData)
{
// TODO 9.0 migration: !! CreateContentContextTrait::createContextMatchingNodeData() is removed in Neos 9.0.

$context = $this->createContextMatchingNodeData($nodeData);
// TODO 9.0 migration: !! ContentContext::getCurrentSite() is removed in Neos 9.0.

$context->getCurrentSite();
}
}

0 comments on commit 411fdfc

Please sign in to comment.