I have a library /Web/
such as follows
/Web/
Builder/
Builder.php
Exceptions/
ExceptionHandler.php
JSONSerializer/
CategoryJSONSerializer.php
ProjectJSONSerializer.php
....
Module/
Category/
Controller/
Category.php
Service/
Category.php
I want to create a new class that will prepare any strings for insertion when being passed through the controller before being passed to the model for insertion.
public function putIndex()
{
try {
try {
$this->category->edit(
new CategoryVO($this->request->getParam('id'), $this->request->getParam('original')),
new CategoryVO($this->request->getParam('id'), $this->request->getParam('edited'))
);
http_response_code(204);
} catch (CategoryValidation $validationException) {
echo json_encode($this->service->prepareErrors(
$validationException
));
}
} catch(\Exception $e) {
http_response_code(500);
}
}
$this->request->getParam('id')
is called, at which point the HTTP request is checked and value for id
key is retrieved from the request header. I want to cleanse these strings, but I want this process to be testable (which my controllers currently aren't) and mockable if required.
I figured my Service/Category class could offer this service however as I mention later I require it across all controllers.
So I need to create a new class to escape strings, remove any special characters and remove any html. This to me sounds like multiple responsibilities, and was wondering if anybody could suggest a suitable way of achieving this.
Straight up I'm having difficulty even naming these class(es).
This service needs to be usable across all controllers, too. So I'd prefer to keep this class(es) in the /Web/
namespace.