Skip to content

Commit

Permalink
Merge pull request #98 from daniellienert/bugfix/use-psr7-methods
Browse files Browse the repository at this point in the history
BUGFIX: Use PSR-7 methods in RedirectFinisher
  • Loading branch information
daniellienert committed Aug 26, 2019
2 parents b54712c + b5efef1 commit 14347f6
Showing 1 changed file with 21 additions and 11 deletions.
32 changes: 21 additions & 11 deletions Classes/Finishers/RedirectFinisher.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,14 @@
* information, please view the LICENSE file which was distributed with this
* source code.
*/

use Neos\Flow\Annotations as Flow;
use Neos\Flow\Http\ServerRequestAttributes;
use Neos\Flow\Mvc\ActionRequest;
use Neos\Flow\Mvc\Routing\Exception\MissingActionNameException;
use Neos\Flow\Mvc\Routing\UriBuilder;
use Neos\Form\Core\Model\AbstractFinisher;
use Psr\Http\Message\UriFactoryInterface;

/**
* This finisher redirects to another Controller or a specific URI.
Expand All @@ -32,20 +37,25 @@ class RedirectFinisher extends AbstractFinisher
'statusCode' => 303
];

/**
* @Flow\Inject
* @var UriFactoryInterface
*/
protected $uriFactory;

/**
* Executes this finisher
* @see AbstractFinisher::execute()
*
* @return void
* @throws \Neos\Form\Exception\FinisherException
* @throws MissingActionNameException
* @see AbstractFinisher::execute()
*/
public function executeInternal()
{
$formRuntime = $this->finisherContext->getFormRuntime();
$request = $formRuntime->getRequest()->getMainRequest();

$delay = (integer)$this->parseOption('delay');
$statusCode = $this->parseOption('statusCode');
$delay = (int)$this->parseOption('delay');
$statusCode = (int)$this->parseOption('statusCode');
$uri = trim($this->parseOption('uri'));


Expand All @@ -55,18 +65,18 @@ public function executeInternal()

$uriParts = parse_url($uri);
if (!isset($uriParts['scheme']) || $uriParts['scheme'] === '') {
$uri = $request->getHttpRequest()->getBaseUri() . $uri;
$uri = $request->getHttpRequest()->getAttribute(ServerRequestAttributes::BASE_URI) . $uri;
}

$escapedUri = htmlentities($uri, ENT_QUOTES, 'utf-8');

$response = $formRuntime->getResponse();

$response->setContent('<html><head><meta http-equiv="refresh" content="' . $delay . ';url=' . $escapedUri . '"/></head></html>');
$response->setStatus($statusCode);
$response->setStatusCode($statusCode);

if ($delay === 0) {
$response->setHeader('Location', (string)$uri);
$response->setRedirectUri($this->uriFactory->createUri((string)$uri));
}
}

Expand All @@ -83,8 +93,9 @@ public function setOptions(array $options)
/**
* @param ActionRequest $request
* @return string
* @throws MissingActionNameException
*/
protected function buildActionUri(ActionRequest $request)
protected function buildActionUri(ActionRequest $request): string
{
$packageKey = $this->parseOption('package');
$controllerName = $this->parseOption('controller');
Expand All @@ -99,7 +110,6 @@ protected function buildActionUri(ActionRequest $request)
$uriBuilder->setRequest($request);
$uriBuilder->reset();

$uri = $uriBuilder->uriFor($actionName, $arguments, $controllerName, $packageKey, $subpackageKey);
return $uri;
return $uriBuilder->uriFor($actionName, $arguments, $controllerName, $packageKey, $subpackageKey);
}
}

0 comments on commit 14347f6

Please sign in to comment.