[Flow] Re: Action Validation of Model
Benjamin Robichaud
b.robichaud at gmail.com
Fri Nov 8 22:16:31 CET 2013
For anyone that might stumble upon this issue, here's an Aspect I created to bypass validation alltogheter on safe requests (e.g. GET, HEAD). Since all data is validated upon unsafe requests (POST, PUT), I don't see the need to re-validate again on unsafe requests since no data can be written to the database anyway (in Flow 2.0).
<code>
use TYPO3\Flow\Annotations as Flow;
/**
* ActionControllerAspect
*
* @Flow\Aspect
*/
class ActionControllerAspect {
/**
* @Flow\Inject
* @var \TYPO3\Flow\Object\ObjectManagerInterface
*/
protected $objectManager;
/**
* An aspect which skips validation completely for an actionj if it is safe
*
* @Flow\Around("method(TYPO3\Flow\Mvc\Controller\ActionController->initializeActionMethodValidators())")
* @param \TYPO3\Flow\Aop\JoinPointInterface $joinPoint The current joinpoint
* @return void
*/
public function initializeActionMethodValidators(\TYPO3\Flow\Aop\JoinPointInterface $joinPoint) {
/** @var \TYPO3\Flow\Mvc\Controller\ActionController $actionController */
$actionController = $joinPoint->getProxy();
/** @var \TYPO3\Flow\Mvc\ActionRequest $request */
$request = \TYPO3\Flow\Reflection\ObjectAccess::getProperty($actionController, 'request', TRUE);
if ($request->getHttpRequest()->isMethodSafe() === FALSE) {
$joinPoint->getAdviceChain()->proceed($joinPoint);
}
}
}
</code>
More information about the Flow
mailing list