Skip to content
This repository has been archived by the owner on Mar 1, 2023. It is now read-only.

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
romm committed Sep 27, 2017
1 parent 1de75b1 commit c62ef3e
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 2 deletions.
1 change: 1 addition & 0 deletions Classes/Controller/FormController.php
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ protected function forwardToReferrer()
$this->request->setControllerExtensionName($referringRequest->getControllerExtensionName());
$this->request->setControllerName($referringRequest->getControllerName());
$this->request->setControllerActionName($referringRequest->getControllerActionName());
$this->request->setArguments($this->processor->getRequest()->getArguments());
$this->request->setOriginalRequest($originalRequest);

throw new StopActionException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
use Romm\Formz\Domain\Middleware\FieldValidation\FieldValidationSignal;
use Romm\Formz\Middleware\Application\OnBeginMiddleware;
use Romm\Formz\Middleware\PresetMiddlewareInterface;
use Romm\Formz\Middleware\Scope\ReadScope;
use Romm\Formz\Middleware\Signal\SendsSignal;
use Romm\Formz\Validation\Form\AbstractFormValidator;

Expand All @@ -41,6 +42,11 @@ class FormValidationMiddleware extends OnBeginMiddleware implements PresetMiddle
*/
protected $validator;

/**
* @var array
*/
protected static $defaultScopesBlackList = [ReadScope::class];

/**
* @see FormValidationMiddleware
*/
Expand Down
6 changes: 4 additions & 2 deletions Classes/Form/Definition/Middleware/MiddlewareScopes.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@
namespace Romm\Formz\Form\Definition\Middleware;

use Romm\Formz\Form\Definition\AbstractFormDefinitionComponent;
use Romm\Formz\Middleware\Scope\MainScope;

/**
* @todo: whitelist entries should not contain blacklist entries.
*/
class MiddlewareScopes extends AbstractFormDefinitionComponent
{
/**
Expand Down Expand Up @@ -47,7 +49,7 @@ class MiddlewareScopes extends AbstractFormDefinitionComponent
* @param array $whiteList
* @param array $blackList
*/
public function __construct(array $whiteList = [MainScope::class], array $blackList = [])
public function __construct(array $whiteList = [], array $blackList = [])
{
$this->whiteList = $whiteList;
$this->blackList = $blackList;
Expand Down
23 changes: 23 additions & 0 deletions Classes/Middleware/Application/AbstractMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
use Romm\Formz\Middleware\Processor\MiddlewareProcessor;
use Romm\Formz\Middleware\Request\Forward;
use Romm\Formz\Middleware\Request\Redirect;
use Romm\Formz\Middleware\Scope\MainScope;
use Romm\Formz\Middleware\Signal\After;
use Romm\Formz\Middleware\Signal\Before;
use Romm\Formz\Middleware\Signal\Element\MiddlewareSignalInterface;
Expand Down Expand Up @@ -65,6 +66,17 @@ abstract class AbstractMiddleware implements MiddlewareInterface, DataPreProcess
*/
protected $scopes = [];

/**
* @var array
*/
protected static $defaultScopesWhiteList = [];

/**
* @var array
*/
protected static $defaultScopesBlackList = [];


/**
* Can be overridden in child class with custom priority value.
*
Expand Down Expand Up @@ -260,6 +272,17 @@ public static function dataPreProcessor(DataPreProcessor $processor)
$data['scopes'] = [];
}

if (false === isset($data['scopes']['whiteList'])) {
$data['scopes']['whiteList'] = [MainScope::class];
}

if (false === isset($data['scopes']['blackList'])) {
$data['scopes']['blackList'] = [];
}

$data['scopes']['whiteList'] = array_unique(array_merge(static::$defaultScopesWhiteList, $data['scopes']['whiteList']));
$data['scopes']['blackList'] = array_unique(array_merge(static::$defaultScopesBlackList, $data['scopes']['blackList']));

$processor->setData($data);
}

Expand Down

0 comments on commit c62ef3e

Please sign in to comment.