Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

!!!TASK: Remove deprecated Http objects and replace with PSR-7 implementation #1552

Merged
merged 78 commits into from
Aug 16, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
78 commits
Select commit Hold shift + click to select a range
579435b
TASK: Remove deprecated Http objects and replace with PSR-7 implement…
albe Apr 19, 2019
80c317b
Adjust modifications and add PSR-15 package
kitsunet Apr 27, 2019
2bf493e
More component split up
kitsunet May 2, 2019
0303d82
Cleanup Http components
kitsunet May 2, 2019
13afc99
SERVER defaults and header extraction in ServerRequestFactory
kitsunet May 2, 2019
d989ce4
Add merging of ActionRequests via Renderer
kitsunet May 5, 2019
de87179
Fix style errors
kitsunet May 5, 2019
ffe8057
Small fixes and refinements
kitsunet May 5, 2019
cce89d5
Move FlowUploadedFile and streamline argument merging
kitsunet May 9, 2019
c353598
Get rid of inheritance in ActionReponse nad adjust everything
kitsunet May 9, 2019
c587e08
Fix style issues
kitsunet May 9, 2019
d4606fc
TASK: Some small fixes
albe May 5, 2019
4184fc8
TASK: Some more changes
albe May 9, 2019
bb38fe1
TASK: Fix a couple of tests
albe May 9, 2019
9561d7f
TASK: Some more cleanup and refactoring
albe May 9, 2019
cf55b18
Split between CLI and Mvc(Web) dispatcher
kitsunet May 12, 2019
cf22ede
Finish separation of MVC/HTTP and CLI dispatchers
kitsunet May 12, 2019
2eb076d
Cleanup and test fixes
kitsunet May 13, 2019
c1a0fe8
More PSR-7 HTTP test fixes
kitsunet May 13, 2019
9600929
TASK: More work on tests
albe May 13, 2019
5377347
TASK: Another round of test fixes
albe May 13, 2019
0cb5934
More test fixes
kitsunet May 13, 2019
6a8e614
Fix StyleCI issues
kitsunet May 13, 2019
fdaa1ed
Merge remote-tracking branch 'origin/master' into http-psr7
kitsunet May 13, 2019
d1bdc9f
More test fixes regarding PSR-7
kitsunet May 14, 2019
7bcb3c0
Next round of fixes for Flow PSR-7
kitsunet May 14, 2019
984852a
Some additional fixeSome additional fixes
kitsunet May 14, 2019
476159e
Some more refactoring
kitsunet May 15, 2019
2ddb0f5
Views can render responses directly that will get applied correctly
kitsunet May 15, 2019
9e178c4
First batch of functional test fixes
kitsunet May 16, 2019
e1faf14
More functional tests fixes
kitsunet May 16, 2019
66766f5
Follow up fix for Browser
kitsunet May 16, 2019
e73e5c4
More test fixes and corrections in code using Requests
kitsunet May 16, 2019
02f461b
CurlEngine fixes
kitsunet May 16, 2019
a37a852
More functional test fixes
kitsunet May 16, 2019
7b7ab35
Last functional test fixes
kitsunet May 16, 2019
480788f
Another round of text and style fixes
kitsunet May 16, 2019
2988e50
Removing major parts of Flows HTTP code
kitsunet May 16, 2019
02b2621
Some more fixes regarding Uri handling with PSR-7
kitsunet May 16, 2019
5d23efe
Adjust escaping of Uris according to PSR-7
kitsunet May 16, 2019
48f38a2
Removal of Uri class
kitsunet May 16, 2019
8aba9c3
Fix Widget tests by urldecoding redirect URLs
kitsunet May 17, 2019
bce2431
Fixes for remaining style and test issues
kitsunet May 17, 2019
2426595
TASK: Some more cleanup and added type hints
albe May 18, 2019
e3ca850
TASK: Rename Cli\Request and Cli\Response
albe May 19, 2019
9761244
TASK: Fix tests again and re-add setContent/appendContent to CommandR…
albe May 19, 2019
a6ccd5e
TASK: Some fixes after last changes
albe May 19, 2019
539aa39
Merge remote-tracking branch 'upstream/master' into http-psr7
albe May 19, 2019
f474d3c
TASK: Merge master and fix tests again
albe May 19, 2019
9054823
TASK: Test fixes
albe May 19, 2019
a0f4565
TASK: Revert renaming Cli Request/Response
albe May 21, 2019
6b87cea
TASK: Remove obsolete references to Mvc\RequestInterface
albe May 21, 2019
825f347
Merge branch 'master' into http-psr7
albe May 21, 2019
0079fee
TASK: Remove ResponseDeprecationTrait
albe May 21, 2019
e044477
TASK: Fix return typehint
albe May 21, 2019
c6ba364
TASK: Remove Renderer import leftovers
albe May 21, 2019
33f1077
TASK: Remove leftover from `IntoComponentContext` renderer
albe May 22, 2019
18edfe9
Replace trait with ActionRequestFactory
kitsunet Jun 11, 2019
31946dd
Separate Uri path and query string in route UriContraints
kitsunet Jun 12, 2019
3947129
Merge branch 'master' into http-psr7
kdambekalns Jul 8, 2019
eb88071
Merge branch 'master' into http-psr7
albe Aug 11, 2019
745e798
TASK: Fix tests
albe Aug 11, 2019
98ac8ea
TASK: Remove unused import
albe Aug 11, 2019
123feeb
TASK: Fix routing tests
albe Aug 11, 2019
3f90598
TASK: Fix getPathConstraint() implementation
albe Aug 12, 2019
dcb2fb7
TASK: View may return a StreamInterface
albe Aug 12, 2019
0630b2f
Merge branch 'master' into http-psr7
albe Aug 14, 2019
e8e267d
TASK: Fix a couple of psalm issues
albe Aug 14, 2019
9ec2901
Disentangle CLI and MVC some more
kitsunet Aug 15, 2019
e2eb5a3
Adjust ActionResponse creation and parent request handling
kitsunet Aug 15, 2019
693c518
Fix error with dispatcher and AuthenticationRequiredException
kitsunet Aug 15, 2019
5b94c18
More psalm and type safety fixes
kitsunet Aug 16, 2019
cd2834d
Psalm and type safety fixes
kitsunet Aug 16, 2019
e2b5b84
More type safety fixes
kitsunet Aug 16, 2019
a8ef2fd
Unit test fixes and type fixes
kitsunet Aug 16, 2019
67c865e
Psalm and test fixes
kitsunet Aug 16, 2019
8961bf2
Fix issues with template lookups
kitsunet Aug 16, 2019
4ec2b5c
Fix template path resolving
kitsunet Aug 16, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 11 additions & 18 deletions Neos.Flow/Classes/Cli/CommandController.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,19 @@
use Neos\Flow\Annotations as Flow;
use Neos\Flow\Command\HelpCommandController;
use Neos\Flow\Mvc\Controller\Argument;
use Neos\Flow\Mvc\Controller\ControllerInterface;
use Neos\Flow\Mvc\Controller\Arguments;
use Neos\Flow\Mvc\Exception\CommandException;
use Neos\Flow\Mvc\Exception\InvalidArgumentTypeException;
use Neos\Flow\Mvc\Exception\NoSuchCommandException;
use Neos\Flow\Mvc\Exception\StopActionException;
use Neos\Flow\Mvc\Exception\UnsupportedRequestTypeException;
use Neos\Flow\Mvc\RequestInterface;
use Neos\Flow\Mvc\ResponseInterface;
use Neos\Flow\Cli\Exception\StopCommandException;
use Neos\Flow\ObjectManagement\ObjectManagerInterface;

/**
* A controller which processes requests from the command line
*
* @Flow\Scope("singleton")
*/
class CommandController implements ControllerInterface
class CommandController implements CommandControllerInterface
{
/**
* @var Request
Expand Down Expand Up @@ -106,18 +102,15 @@ public function injectObjectManager(ObjectManagerInterface $objectManager)
/**
* Processes a command line request.
*
* @param RequestInterface $request The request object
* @param ResponseInterface $response The response, modified by this handler
* @param Request $request The request object
* @param Response $response The response, modified by this handler
* @return void
* @throws UnsupportedRequestTypeException if the controller doesn't support the current request type
* @throws InvalidArgumentTypeException
* @throws NoSuchCommandException
* @api
*/
public function processRequest(RequestInterface $request, ResponseInterface $response)
public function processRequest(Request $request, Response $response): void
{
if (!$request instanceof Request) {
throw new UnsupportedRequestTypeException(sprintf('%s only supports command line requests – requests of type "%s" given.', get_class($this), get_class($request)), 1300787096);
}

$this->request = $request;
$this->request->setDispatched(true);
$this->response = $response;
Expand Down Expand Up @@ -214,7 +207,7 @@ protected function mapRequestArgumentsToControllerArguments()
* @param string $controllerObjectName
* @param array $arguments
* @return void
* @throws StopActionException
* @throws StopCommandException
*/
protected function forward(string $commandName, string $controllerObjectName = null, array $arguments = [])
{
Expand All @@ -226,7 +219,7 @@ protected function forward(string $commandName, string $controllerObjectName = n
$this->request->setArguments($arguments);

$this->arguments->removeAll();
throw new StopActionException();
throw new StopCommandException(sprintf('Forwarded to "%s".', $commandName));
}

/**
Expand Down Expand Up @@ -338,13 +331,13 @@ protected function outputFormatted(string $text = '', array $arguments = [], int
* shutdown (such as the persistence framework), you must use quit() instead of exit().
*
* @param integer $exitCode Exit code to return on exit (see http://www.php.net/exit)
* @throws StopActionException
* @throws StopCommandException
* @return void
*/
protected function quit(int $exitCode = 0)
{
$this->response->setExitCode($exitCode);
throw new StopActionException;
throw new StopCommandException(sprintf('Quitting with exit code %s', $exitCode));
}

/**
Expand Down
21 changes: 21 additions & 0 deletions Neos.Flow/Classes/Cli/CommandControllerInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php
namespace Neos\Flow\Cli;

use Neos\Flow\Cli\Exception\StopCommandException;

/**
* Transitional interface for command controllers.
* @internal
*/
interface CommandControllerInterface
{
/**
* Processes a general request. The result can be returned by altering the given response.
*
* @param Request $request The request object
* @param Response $response The response, modified by the controller
* @return void
* @throws StopCommandException
*/
public function processRequest(Request $request, Response $response): void;
}
18 changes: 10 additions & 8 deletions Neos.Flow/Classes/Cli/CommandRequestHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
use Neos\Flow\Core\Bootstrap;
use Neos\Flow\Core\LockManager;
use Neos\Flow\Core\RequestHandlerInterface;
use Neos\Flow\Mvc\Dispatcher;
use Neos\Flow\ObjectManagement\ObjectManagerInterface;
use Neos\Flow\Security\Context;

Expand Down Expand Up @@ -130,19 +129,22 @@ public function exitIfCompiletimeCommandWasNotCalledCorrectly(string $runlevel)
if ($runlevel === Bootstrap::RUNLEVEL_COMPILETIME) {
return;
}

$command = $this->request->getCommand();
if ($this->bootstrap->isCompiletimeCommand($command->getCommandIdentifier())) {
$this->response->appendContent(sprintf(
if (!$this->bootstrap->isCompiletimeCommand($command->getCommandIdentifier())) {
return;
}

$this->response->appendContent(sprintf(
"<b>Unrecognized Command</b>\n\n" .
"Sorry, but the command \"%s\" must be specified by its full command\n" .
"identifier because it is a compile time command which cannot be resolved\n" .
"from an abbreviated command identifier.\n\n",
$command->getCommandIdentifier())
);
$this->response->send();
$this->shutdown($runlevel);
exit(1);
}
);
$this->response->send();
$this->shutdown($runlevel);
exit(1);
}

/**
Expand Down
131 changes: 131 additions & 0 deletions Neos.Flow/Classes/Cli/Dispatcher.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
<?php
namespace Neos\Flow\Cli;

use Neos\Flow\Annotations as Flow;
use Neos\Flow\Cli\Exception\InfiniteLoopException;
use Neos\Flow\Cli\Exception\InvalidCommandControllerException;
use Neos\Flow\Cli\Exception\StopCommandException;
use Neos\Flow\ObjectManagement\ObjectManagerInterface;

/**
* A command dispatcher.
*
* @Flow\Scope("singleton")
*/
class Dispatcher
{
/**
* @var \Neos\Flow\SignalSlot\Dispatcher
*/
protected $signalDispatcher;

/**
* @var ObjectManagerInterface
*/
protected $objectManager;

/**
* @param \Neos\Flow\SignalSlot\Dispatcher $signalDispatcher
*/
public function injectSignalDispatcher(\Neos\Flow\SignalSlot\Dispatcher $signalDispatcher)
{
$this->signalDispatcher = $signalDispatcher;
}

/**
* @param ObjectManagerInterface $objectManager
*/
public function injectObjectManager(ObjectManagerInterface $objectManager)
{
$this->objectManager = $objectManager;
}

/**
* Try processing the request until it is successfully marked "dispatched"
*
* @param Request $request
* @param Response $response
* @return Response
* @throws InfiniteLoopException
* @throws InvalidCommandControllerException
*/
public function dispatch(Request $request, Response $response): Response
{
$dispatchLoopCount = 0;
/** @var Request $request */
while (!$request->isDispatched()) {
if ($dispatchLoopCount++ > 99) {
throw new InfiniteLoopException(sprintf('Could not ultimately dispatch the command request after %d iterations.', $dispatchLoopCount), 1565874819);
}
$controller = $this->resolveController($request);
try {
$this->emitBeforeControllerInvocation($request, $response, $controller);
$controller->processRequest($request, $response);
$this->emitAfterControllerInvocation($request, $response, $controller);
} catch (StopCommandException $exception) {
$this->emitAfterControllerInvocation($request, $response, $controller);
}
}

return $response;
}

/**
* This signal is emitted directly before the request is been dispatched to a controller.
*
* @param Request $request
* @param Response $response
* @param CommandControllerInterface $controller
* @return void
*/
protected function emitBeforeControllerInvocation(Request $request, Response $response, CommandControllerInterface $controller)
{
$this->signalDispatcher->dispatch(\Neos\Flow\Mvc\Dispatcher::class, 'beforeControllerInvocation', [
'request' => $request,
'response' => $response,
'controller' => $controller
]);
}

/**
* This signal is emitted directly after the request has been dispatched to a controller and the controller
* returned control back to the dispatcher.
*
* @param Request $request
* @param Response $response
* @param CommandControllerInterface $controller
* @return void
*/
protected function emitAfterControllerInvocation(Request $request, Response $response, CommandControllerInterface $controller)
{
$this->signalDispatcher->dispatch(\Neos\Flow\Mvc\Dispatcher::class, 'afterControllerInvocation', [
'request' => $request,
'response' => $response,
'controller' => $controller
]);
}

/**
* Finds and instantiates a controller that matches the current request.
* If no controller can be found, an instance of NotFoundControllerInterface is returned.
*
* @param Request $request The request to dispatch
* @return CommandControllerInterface
* @throws InvalidCommandControllerException
*/
protected function resolveController(Request $request): CommandControllerInterface
{
$controllerObjectName = $request->getControllerObjectName();
if ($controllerObjectName === '') {
$exceptionMessage = 'No controller could be resolved which would match your request';
throw new InvalidCommandControllerException($exceptionMessage, 1565878092);
}

$controller = $this->objectManager->get($controllerObjectName);
if (!$controller instanceof CommandControllerInterface) {
throw new InvalidCommandControllerException('Invalid controller "' . $request->getControllerObjectName() . '". The controller must be a valid request handling controller, ' . (is_object($controller) ? get_class($controller) : gettype($controller)) . ' given.', 1565878098);
}

return $controller;
}
}
11 changes: 11 additions & 0 deletions Neos.Flow/Classes/Cli/Exception/InfiniteLoopException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php
namespace Neos\Flow\Cli\Exception;

/**
* An "Infinite Loop" exception
*
* @api
*/
class InfiniteLoopException extends \Exception
{
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php
namespace Neos\Flow\Cli\Exception;

/**
*
*/
class InvalidCommandControllerException extends \Exception
{
}
9 changes: 9 additions & 0 deletions Neos.Flow/Classes/Cli/Exception/StopCommandException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php
namespace Neos\Flow\Cli\Exception;

/**
*
*/
class StopCommandException extends \Exception
{
}
15 changes: 4 additions & 11 deletions Neos.Flow/Classes/Cli/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,13 @@

use Neos\Flow\Mvc\Exception\InvalidArgumentNameException;
use Neos\Flow\Mvc\Exception\NoSuchArgumentException;
use Neos\Flow\Mvc\RequestInterface;

/**
* Represents a CLI request.
*
* @api
*/
class Request implements RequestInterface
class Request
{
/**
* @var string
Expand Down Expand Up @@ -54,12 +53,6 @@ class Request implements RequestInterface
*/
protected $dispatched = false;

/**
*
* @var array
*/
protected $commandLineArguments;

/**
* Sets the dispatched flag
*
Expand Down Expand Up @@ -111,7 +104,7 @@ public function getControllerObjectName(): string
* Returns the this request, as CLI request nesting is not supported.
*
* @return Request
* @api
* @deprecated
*/
public function getMainRequest(): Request
{
Expand All @@ -122,7 +115,7 @@ public function getMainRequest(): Request
* Returns true, as CLI request nesting is not supported.
*
* @return boolean
* @api
* @deprecated
*/
public function isMainRequest(): bool
{
Expand Down Expand Up @@ -174,7 +167,7 @@ public function getCommand(): Command
* @return void
* @throws InvalidArgumentNameException
*/
public function setArgument(string $argumentName, $value)
public function setArgument(string $argumentName, $value): void
{
if ($argumentName === '') {
throw new InvalidArgumentNameException('Invalid argument name.', 1300893885);
Expand Down
Loading