Skip to content

Commit d37c595

Browse files
committed
[CHANGE] Make compatible with Neos Flow 6 and 7
1 parent 56e6c26 commit d37c595

4 files changed

Lines changed: 114 additions & 93 deletions

File tree

Classes/ViewHelpers/Form/AuthTokenViewHelper.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,24 +41,23 @@ class AuthTokenViewHelper extends \Neos\FluidAdaptor\ViewHelpers\Form\AbstractFo
4141
*/
4242
public function initializeArguments()
4343
{
44-
// this form field needs no other arguments
44+
$this->registerArgument('accountIdentifier', 'string', 'accountIdentifier to authenticate with', true);
4545
}
4646

4747
/**
4848
* Renders a hidden field with authToken.
4949
*
50-
* @param string $accountIdentifier
5150
* @return string
5251
* @api
5352
*/
54-
public function render($accountIdentifier)
53+
public function render()
5554
{
5655
$name = '__authentication[HmacAuthentication][authToken]';
5756
$this->registerFieldNameForFormTokenGeneration($name);
5857

5958
$this->tag->addAttribute('type', 'hidden');
6059
$this->tag->addAttribute('name', $name);
61-
$this->tag->addAttribute('value', $this->hmacService->encodeAuthToken($accountIdentifier));
60+
$this->tag->addAttribute('value', $this->hmacService->encodeAuthToken($this->arguments['accountIdentifier']));
6261

6362
$this->addAdditionalIdentityPropertiesIfNeeded();
6463
$this->setErrorClassAttribute();

Classes/ViewHelpers/Link/AuthenticatedActionViewHelper.php

Lines changed: 34 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use Neos\FluidAdaptor\Core\ViewHelper\AbstractTagBasedViewHelper;
1010
use Neos\FluidAdaptor\Core\ViewHelper;
1111
use Neos\Flow\Annotations as Flow;
12+
use Neos\Flow\Mvc\ActionRequest;
1213

1314
/**
1415
* A view helper for creating links to actions.
@@ -62,40 +63,45 @@ public function initializeArguments()
6263
$this->registerTagAttribute('rel', 'string', 'Specifies the relationship between the current document and the linked document');
6364
$this->registerTagAttribute('rev', 'string', 'Specifies the relationship between the linked document and the current document');
6465
$this->registerTagAttribute('target', 'string', 'Specifies where to open the linked document');
66+
$this->registerArgument('action', 'string', 'Target action', true);
67+
$this->registerArgument('arguments', 'array', 'Arguments', false, []);
68+
$this->registerArgument('controller', 'string', 'Target controller. If NULL current controllerName is used', false, null);
69+
$this->registerArgument('package', 'string', 'Target package. if NULL current package is used', false, null);
70+
$this->registerArgument('subpackage', 'string', 'Target subpackage. if NULL current subpackage is used', false, null);
71+
$this->registerArgument('section', 'string', 'The anchor to be added to the URI', false, '');
72+
$this->registerArgument('format', 'string', 'The requested format, e.g. ".html"', false, '');
73+
$this->registerArgument('additionalParams', 'array', 'additional query parameters that won\'t be prefixed like $arguments (overrule $arguments)', false, []);
74+
$this->registerArgument('addQueryString', 'boolean', 'If set, the current query parameters will be kept in the URI', false, false);
75+
$this->registerArgument('argumentsToBeExcludedFromQueryString', 'array', 'arguments to be removed from the URI. Only active if $addQueryString = true', false, []);
76+
$this->registerArgument('useParentRequest', 'boolean', 'If set, the parent Request will be used instead of the current one. Note: using this argument can be a sign of undesired tight coupling, use with care', false, false);
77+
$this->registerArgument('absolute', 'boolean', 'By default this ViewHelper renders links with absolute URIs. If this is false, a relative URI is created instead', false, true);
78+
$this->registerArgument('useMainRequest', 'boolean', 'If set, the main Request will be used instead of the current one. Note: using this argument can be a sign of undesired tight coupling, use with care', false, false);
79+
$this->registerArgument('accountIdentifier', 'string', 'accountIdentifier to authenticate with', true);
6580
}
6681

6782
/**
6883
* Render the link.
6984
*
70-
* @param string $accountIdentifier AccountIdentifier to authenticate with
71-
* @param string $action Target action
72-
* @param array $arguments Arguments
73-
* @param string $controller Target controller. If NULL current controllerName is used
74-
* @param string $package Target package. if NULL current package is used
75-
* @param string $subpackage Target subpackage. if NULL current subpackage is used
76-
* @param string $section The anchor to be added to the URI
77-
* @param string $format The requested format, e.g. ".html"
78-
* @param array $additionalParams additional query parameters that won't be prefixed like $arguments (overrule $arguments)
79-
* @param boolean $addQueryString If set, the current query parameters will be kept in the URI
80-
* @param array $argumentsToBeExcludedFromQueryString arguments to be removed from the URI. Only active if $addQueryString = TRUE
81-
* @param boolean $useParentRequest If set, the parent Request will be used instead of the current one. Note: using this argument can be a sign of undesired tight coupling, use with care
82-
* @param boolean $absolute By default this ViewHelper renders links with absolute URIs. If this is FALSE, a relative URI is created instead
83-
* @param boolean $useMainRequest If set, the main Request will be used instead of the current one. Note: using this argument can be a sign of undesired tight coupling, use with care
8485
* @return string The rendered link
8586
* @throws ViewHelper\Exception
8687
* @api
8788
*/
88-
public function render($accountIdentifier, $action, $arguments = array(), $controller = null, $package = null, $subpackage = null, $section = '', $format = '', array $additionalParams = array(), $addQueryString = false, array $argumentsToBeExcludedFromQueryString = array(), $useParentRequest = false, $absolute = true, $useMainRequest = false)
89+
public function render()
8990
{
9091
$uriBuilder = $this->controllerContext->getUriBuilder();
91-
if ($useParentRequest) {
92+
if ($this->arguments['useParentRequest']) {
9293
$request = $this->controllerContext->getRequest();
9394
if ($request->isMainRequest()) {
9495
throw new ViewHelper\Exception('You can\'t use the parent Request, you are already in the MainRequest.', 1360163536);
9596
}
97+
$parentRequest = $request->getParentRequest();
98+
if (!$parentRequest instanceof ActionRequest) {
99+
throw new ViewHelper\Exception('The parent requests was unexpectedly empty, probably the current request is broken.', 1565948237);
100+
}
101+
96102
$uriBuilder = clone $uriBuilder;
97-
$uriBuilder->setRequest($request->getParentRequest());
98-
} elseif ($useMainRequest === true) {
103+
$uriBuilder->setRequest($parentRequest);
104+
} elseif ($this->arguments['useMainRequest'] === true) {
99105
$request = $this->controllerContext->getRequest();
100106
if (!$request->isMainRequest()) {
101107
$uriBuilder = clone $uriBuilder;
@@ -105,22 +111,22 @@ public function render($accountIdentifier, $action, $arguments = array(), $contr
105111

106112
$uriBuilder
107113
->reset()
108-
->setSection($section)
109-
->setCreateAbsoluteUri($absolute)
110-
->setArguments($additionalParams)
111-
->setAddQueryString($addQueryString)
112-
->setArgumentsToBeExcludedFromQueryString($argumentsToBeExcludedFromQueryString)
113-
->setFormat($format);
114+
->setSection($this->arguments['section'])
115+
->setCreateAbsoluteUri($this->arguments['absolute'])
116+
->setArguments($this->arguments['additionalParams'])
117+
->setAddQueryString($this->arguments['addQueryString'])
118+
->setArgumentsToBeExcludedFromQueryString($this->arguments['argumentsToBeExcludedFromQueryString'])
119+
->setFormat($this->arguments['format']);
114120
try {
115-
$uri = $uriBuilder->uriFor($action, $arguments, $controller, $package, $subpackage);
121+
$uri = $uriBuilder->uriFor($this->arguments['action'], $this->arguments['arguments'], $this->arguments['controller'], $this->arguments['package'], $this->arguments['subpackage']);
116122
} catch (\Exception $exception) {
117123
throw new ViewHelper\Exception($exception->getMessage(), $exception->getCode(), $exception);
118124
}
119125

120-
$authenticationQueryPart = $this->hmacService->generateHmacAuthenticationQueryStringPart($accountIdentifier);
121-
$uri = $uri . (strpos($uri, '?') === FALSE ? '?' : '&' ) . $authenticationQueryPart;
126+
$authenticationQueryPart = $this->hmacService->generateHmacAuthenticationQueryStringPart($this->arguments['accountIdentifier']);
127+
$uri = $uri . (strpos($uri, '?') === FALSE ? '?' : '&' ) . $authenticationQueryPart;
122128

123-
$this->tag->addAttribute('href', $uri);
129+
$this->tag->addAttribute('href', $uri);
124130
$this->tag->setContent($this->renderChildren());
125131
$this->tag->forceClosingTag(true);
126132

Classes/ViewHelpers/Uri/AuthenticatedActionViewHelper.php

Lines changed: 76 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
*
77
*/
88

9+
use Neos\Flow\Mvc\ActionRequest;
910
use Neos\FluidAdaptor\Core\ViewHelper\AbstractViewHelper;
1011
use Neos\FluidAdaptor\Core\ViewHelper;
1112
use Neos\Flow\Annotations as Flow;
@@ -36,68 +37,83 @@
3637
class AuthenticatedActionViewHelper extends AbstractViewHelper
3738
{
3839

39-
/**
40-
* @Flow\Inject
41-
* @var \FormatD\HmacAuthentication\Service\HmacService
42-
*/
43-
protected $hmacService;
40+
/**
41+
* @Flow\Inject
42+
* @var \FormatD\HmacAuthentication\Service\HmacService
43+
*/
44+
protected $hmacService;
4445

45-
/**
46-
* Render the Uri.
47-
*
48-
* @param string $accountIdentifier AccountIdentifier to authenticate with
49-
* @param string $action Target action
50-
* @param array $arguments Arguments
51-
* @param string $controller Target controller. If NULL current controllerName is used
52-
* @param string $package Target package. if NULL current package is used
53-
* @param string $subpackage Target subpackage. if NULL current subpackage is used
54-
* @param string $section The anchor to be added to the URI
55-
* @param string $format The requested format, e.g. ".html"
56-
* @param array $additionalParams additional query parameters that won't be prefixed like $arguments (overrule $arguments)
57-
* @param boolean $absolute If set, an absolute URI is rendered
58-
* @param boolean $addQueryString If set, the current query parameters will be kept in the URI
59-
* @param array $argumentsToBeExcludedFromQueryString arguments to be removed from the URI. Only active if $addQueryString = TRUE
60-
* @param boolean $useParentRequest If set, the parent Request will be used instead of the current one. Note: using this argument can be a sign of undesired tight coupling, use with care
61-
* @param boolean $useMainRequest If set, the main Request will be used instead of the current one. Note: using this argument can be a sign of undesired tight coupling, use with care
62-
* @return string The rendered link
63-
* @throws ViewHelper\Exception
64-
* @api
65-
*/
66-
public function render($accountIdentifier, $action, array $arguments = array(), $controller = null, $package = null, $subpackage = null, $section = '', $format = '', array $additionalParams = array(), $absolute = false, $addQueryString = false, array $argumentsToBeExcludedFromQueryString = array(), $useParentRequest = false, $useMainRequest = false)
67-
{
68-
$uriBuilder = $this->controllerContext->getUriBuilder();
69-
if ($useParentRequest === true) {
70-
$request = $this->controllerContext->getRequest();
71-
if ($request->isMainRequest()) {
72-
throw new ViewHelper\Exception('You can\'t use the parent Request, you are already in the MainRequest.', 1360590758);
73-
}
74-
$uriBuilder = clone $uriBuilder;
75-
$uriBuilder->setRequest($request->getParentRequest());
76-
} elseif ($useMainRequest === true) {
77-
$request = $this->controllerContext->getRequest();
78-
if (!$request->isMainRequest()) {
79-
$uriBuilder = clone $uriBuilder;
80-
$uriBuilder->setRequest($request->getMainRequest());
81-
}
82-
}
46+
/**
47+
* Initialize arguments
48+
*
49+
* @return void
50+
* @api
51+
*/
52+
public function initializeArguments()
53+
{
54+
$this->registerArgument('action', 'string', 'Target action', true);
55+
$this->registerArgument('arguments', 'array', 'Arguments', false, []);
56+
$this->registerArgument('controller', 'string', 'Target controller. If NULL current controllerName is used', false, null);
57+
$this->registerArgument('package', 'string', 'Target package. if NULL current package is used', false, null);
58+
$this->registerArgument('subpackage', 'string', 'Target subpackage. if NULL current subpackage is used', false, null);
59+
$this->registerArgument('section', 'string', 'The anchor to be added to the URI', false, '');
60+
$this->registerArgument('format', 'string', 'The requested format, e.g. ".html"', false, '');
61+
$this->registerArgument('additionalParams', 'array', 'additional query parameters that won\'t be prefixed like $arguments (overrule $arguments)', false, []);
62+
$this->registerArgument('absolute', 'boolean', 'By default this ViewHelper renders links with absolute URIs. If this is false, a relative URI is created instead', false, false);
63+
$this->registerArgument('addQueryString', 'boolean', 'If set, the current query parameters will be kept in the URI', false, false);
64+
$this->registerArgument('argumentsToBeExcludedFromQueryString', 'array', 'arguments to be removed from the URI. Only active if $addQueryString = true', false, []);
65+
$this->registerArgument('useParentRequest', 'boolean', 'If set, the parent Request will be used instead of the current one. Note: using this argument can be a sign of undesired tight coupling, use with care', false, false);
66+
$this->registerArgument('useMainRequest', 'boolean', 'If set, the main Request will be used instead of the current one. Note: using this argument can be a sign of undesired tight coupling, use with care', false, false);
67+
$this->registerArgument('accountIdentifier', 'string', 'accountIdentifier to authenticate with', true);
68+
}
8369

84-
$uriBuilder
85-
->reset()
86-
->setSection($section)
87-
->setCreateAbsoluteUri($absolute)
88-
->setArguments($additionalParams)
89-
->setAddQueryString($addQueryString)
90-
->setArgumentsToBeExcludedFromQueryString($argumentsToBeExcludedFromQueryString)
91-
->setFormat($format);
92-
try {
93-
$uri = $uriBuilder->uriFor($action, $arguments, $controller, $package, $subpackage);
94-
} catch (\Exception $exception) {
95-
throw new ViewHelper\Exception($exception->getMessage(), $exception->getCode(), $exception);
96-
}
70+
/**
71+
* Render the Uri.
72+
*
73+
* @return string The rendered link
74+
* @throws ViewHelper\Exception
75+
* @api
76+
*/
77+
public function render()
78+
{
79+
$uriBuilder = $this->controllerContext->getUriBuilder();
80+
if ($this->arguments['useParentRequest'] === true) {
81+
$request = $this->controllerContext->getRequest();
82+
if ($request->isMainRequest()) {
83+
throw new ViewHelper\Exception('You can\'t use the parent Request, you are already in the MainRequest.', 1360590758);
84+
}
85+
$parentRequest = $request->getParentRequest();
86+
if (!$parentRequest instanceof ActionRequest) {
87+
throw new ViewHelper\Exception('The parent requests was unexpectedly empty, probably the current request is broken.', 1565948254);
88+
}
9789

98-
$authenticationQueryPart = $this->hmacService->generateHmacAuthenticationQueryStringPart($accountIdentifier);
99-
$uri = $uri . (strpos($uri, '?') === FALSE ? '?' : '&' ) . $authenticationQueryPart;
90+
$uriBuilder = clone $uriBuilder;
91+
$uriBuilder->setRequest($parentRequest);
92+
} elseif ($this->arguments['useMainRequest'] === true) {
93+
$request = $this->controllerContext->getRequest();
94+
if (!$request->isMainRequest()) {
95+
$uriBuilder = clone $uriBuilder;
96+
$uriBuilder->setRequest($request->getMainRequest());
97+
}
98+
}
10099

101-
return $uri;
102-
}
100+
$uriBuilder
101+
->reset()
102+
->setSection($this->arguments['section'])
103+
->setCreateAbsoluteUri($this->arguments['absolute'])
104+
->setArguments($this->arguments['additionalParams'])
105+
->setAddQueryString($this->arguments['addQueryString'])
106+
->setArgumentsToBeExcludedFromQueryString($this->arguments['argumentsToBeExcludedFromQueryString'])
107+
->setFormat($this->arguments['format']);
108+
try {
109+
$uri = $uriBuilder->uriFor($this->arguments['action'], $this->arguments['arguments'], $this->arguments['controller'], $this->arguments['package'], $this->arguments['subpackage']);
110+
} catch (\Exception $exception) {
111+
throw new ViewHelper\Exception($exception->getMessage(), $exception->getCode(), $exception);
112+
}
113+
114+
$authenticationQueryPart = $this->hmacService->generateHmacAuthenticationQueryStringPart($this->arguments['accountIdentifier']);
115+
$uri = $uri . (strpos($uri, '?') === FALSE ? '?' : '&' ) . $authenticationQueryPart;
116+
117+
return $uri;
118+
}
103119
}

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"type": "neos-package",
55
"license": "MIT",
66
"require": {
7-
"neos/flow": ">=4.0 <6.0"
7+
"neos/flow": "^6.0 || ^7.0"
88
},
99
"suggest": {
1010
},

0 commit comments

Comments
 (0)