/**
  * __invoke Magic Method
  *
  * @param Request  $request  Request
  * @param Response $response Response
  * @param callable $next     Next
  *
  * @return Response Response
  */
 public function __invoke(Request $request, Response $response, callable $next)
 {
     $config = $request->getRoute()->getMiddlewareConfig('validation');
     $input = $request->getMethod() === 'GET' ? $request->getQueryParams() : $request->getParams();
     try {
         $validator = $this->getValidator($config);
         $validator->assert($input);
     } catch (NestedValidationException $validation_exception) {
         $exception = new HttpMessages_Exception('Validation error.');
         $exception->setErrors($validation_exception->getMessages());
         $exception->setInput($input);
         throw $exception;
     }
     $response = $next($request, $response);
     return $response;
 }
 /**
  * Get Cache Key
  *
  * @param Request $request Request
  *
  * @return string Cache Key
  */
 private function getCacheKey(Request $request, $cache_duration)
 {
     $keys = array_merge($request->getQueryParams(), $request->getAttributes());
     $cache_key = $request->getUri();
     $cache_key .= $request->getMethod();
     $cache_key .= $cache_duration;
     $cache_key .= serialize($keys);
     return md5($cache_key);
 }