
Originally Posted by
kyberfabrikken
Yes, I think that would be nice if possible.
Alright. I modified them:
PHP Code:
interface IInputRule
{
/**
* Validate DataObject. Return true for success. Report errors to Logger.
* @param object DataObject
* @param object ILogger
* @return boolean is valid
*/
public function validate(DataObject $data, ILogger $logger);
}
class InputController implements IInputRule
{
(...)
}
class InputValidator implements IInputRule
{
(...)
}

Originally Posted by
Overunner
How is the Application Controller, Input Controller and Flow Controller related to each other? --By just looking at the code, I think the responsibilities of the Flow Controller overlap with the Input Controller.
As my code says, I intended the InputController to be an InputValidator+InputFilterChain facade. It's not an actual flow Controller as it doesn't even implement IHandler, but I couldn't come up with a more suitable name. So my IC is meant to be used by another Controller, and FlowController and InputController most certainly don't overlap.
For clarity, here's FlowController modified to my InputController:
PHP Code:
class FlowController implements IHandler
{
/**
* @var object IHandler
*/
protected $success = NULL;
/**
* @var object IHandler
*/
protected $failure = NULL;
/**
* @var object IInputRule
*/
protected $validator = NULL;
public function __construct(IHandler $success, IHandler $failure)
{
$this->success = $success;
$this->failure = $failure;
$this->validator = new InputController;
}
public function execute(Request $request, Response $response)
{
$logger = new Logger;
if ($this->validator->validate($request, $logger))
{
$this->success->execute($request, $response);
}
else
{
$this->request->set('errors', $logger->getMessages());
$this->failure->execute($request, $response);
}
}
public function addFilter($filter)
{
$this->validator->addFilter($filter);
}
public function addRule($rule)
{
$this->validator->addRule($rule);
}
}
Please don't take me for someone who's for the FlowController approach, I don't have an opinion here - I'm just trying to accommodate.
I repeat, my InputController isn't a flow controller. If you want InputController to have those abilities - I don't - then you should rename mine and have your class use it: the input filtering and validation part definitely needs to be a in separate class. Actually I'd be glad to have suggestions for a new name, as the current one is admittedly confusing.
Bookmarks