Skip to content

Commit

Permalink
!!! TASK: Mvc\Dispatcher::afterControllerInvocation will not be cal…
Browse files Browse the repository at this point in the history
…led for CLI requests anymore.

Reverts that the cli dispatcher invokes the mvc slots dispatcher slots with cli requests.

When there was one dispatcher the slot `afterControllerInvocation` was fired for both cli and web request. (Seemingly only ever at Runtime?)

Then with the split of web and cli dispatchers this legacy layer was introduced:

cf55b18#diff-2c9408e74a8ac737f84468e74c23956d2057e64196e66b97281905d8697226ca

Now during a short time the `Mvc\Dispatcher::afterControllerInvocation` signal was now also called for cli request during compile time.

With this bugfix #2529 the initial behaviour was restored again.
For cli request it will only fire at runtime, and web request are either way always runtime.

This breaking change cleans up the legacy layer.

- The original signals Mvc\Dispatcher 'afterControllerInvocation' and 'BeforeControllerInvocation'
Will be only invoked for action requests.
They still only fire at runtime, as web requests happen at runtime.

- The with Flow 6.0 introduced signals Cli\Dispatcher 'afterControllerInvocation' and 'BeforeControllerInvocation'
Will still be only invoked for cli requests.
Will still fired either at compile or runtime, as cli requests can happen always.

In case you used the MVC signals and relied on it to also be invoked for CliRequest, you need to connect as well to the respective Cli\Dispatcher signal.
But keep in mind that you might need to check if flow is in runtime as this signal will be also fired for compile time unlike the mvc signal before.
  • Loading branch information
mhsdesign committed Jan 30, 2024
1 parent a5cd6e3 commit 4708efc
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 22 deletions.
21 changes: 0 additions & 21 deletions Neos.Flow/Classes/Cli/Dispatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
use Neos\Flow\Cli\Exception\InfiniteLoopException;
use Neos\Flow\Cli\Exception\InvalidCommandControllerException;
use Neos\Flow\Cli\Exception\StopCommandException;
use Neos\Flow\ObjectManagement\CompileTimeObjectManager;
use Neos\Flow\ObjectManagement\ObjectManagerInterface;

/**
Expand Down Expand Up @@ -81,16 +80,6 @@ public function dispatch(Request $request, Response $response): Response
*/
protected function emitBeforeControllerInvocation(Request $request, Response $response, CommandControllerInterface $controller)
{
// Before Flow 5.3 you could rely on this slot only being called during runtime
// There will be new slots in 7.x, which will run in compile time, too
if ($this->objectManager instanceof CompileTimeObjectManager) {
return;
}
$this->signalDispatcher->dispatch(\Neos\Flow\Mvc\Dispatcher::class, 'beforeControllerInvocation', [
'request' => $request,
'response' => $response,
'controller' => $controller
]);
}

/**
Expand All @@ -104,16 +93,6 @@ protected function emitBeforeControllerInvocation(Request $request, Response $re
*/
protected function emitAfterControllerInvocation(Request $request, Response $response, CommandControllerInterface $controller)
{
// Before Flow 5.3 you could rely on this slot only being called during runtime
// There will be new slots in 7.x, which will run in compile time, too
if ($this->objectManager instanceof CompileTimeObjectManager) {
return;
}
$this->signalDispatcher->dispatch(\Neos\Flow\Mvc\Dispatcher::class, 'afterControllerInvocation', [
'request' => $request,
'response' => $response,
'controller' => $controller
]);
}

/**
Expand Down
15 changes: 14 additions & 1 deletion Neos.Flow/Classes/Package.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use Neos\Flow\Configuration\Source\YamlSource;
use Neos\Flow\Core\Booting\Step;
use Neos\Flow\Http\Helper\SecurityHelper;
use Neos\Flow\ObjectManagement\CompileTimeObjectManager;
use Neos\Flow\ObjectManagement\Proxy;
use Neos\Flow\Package\Package as BasePackage;
use Neos\Flow\Package\PackageManager;
Expand Down Expand Up @@ -67,17 +68,29 @@ public function boot(Core\Bootstrap $bootstrap)

$dispatcher->connect(Mvc\Dispatcher::class, 'afterControllerInvocation', function ($request) use ($bootstrap) {
// No auto-persistence if there is no PersistenceManager registered
// This signal will not be fired at compile time, as it's only emitted for web requests which happen at runtime.
if (
$bootstrap->getObjectManager()->has(Persistence\PersistenceManagerInterface::class)
) {
if (!$request instanceof Mvc\ActionRequest || SecurityHelper::hasSafeMethod($request->getHttpRequest()) !== true) {
if (SecurityHelper::hasSafeMethod($request->getHttpRequest()) !== true) {
$bootstrap->getObjectManager()->get(Persistence\PersistenceManagerInterface::class)->persistAll();
} elseif (SecurityHelper::hasSafeMethod($request->getHttpRequest())) {
/** @phpstan-ignore-next-line the persistence manager interface doesn't specify this method */
$bootstrap->getObjectManager()->get(Persistence\PersistenceManagerInterface::class)->persistAllowedObjects();
}
}
});

$dispatcher->connect(Cli\Dispatcher::class, 'afterControllerInvocation', function () use ($bootstrap) {
// No auto-persistence if there is no PersistenceManager registered or during compile time
if (
$bootstrap->getObjectManager()->has(Persistence\PersistenceManagerInterface::class)
&& !($bootstrap->getObjectManager() instanceof CompileTimeObjectManager)
) {
$bootstrap->getObjectManager()->get(Persistence\PersistenceManagerInterface::class)->persistAll();
}
});

$dispatcher->connect(Cli\SlaveRequestHandler::class, 'dispatchedCommandLineSlaveRequest', Persistence\PersistenceManagerInterface::class, 'persistAll', false);

$dispatcher->connect(Command\CacheCommandController::class, 'warmupCaches', PrecomposedHashProvider::class, 'precomposeHash');
Expand Down

0 comments on commit 4708efc

Please sign in to comment.