public function createService(ServiceLocatorInterface $serviceLocator)
 {
     /** @var \Zend\Mvc\Application $app */
     $app = $serviceLocator->get('Application');
     /** @var \Zend\Mvc\Router\Http\RouteMatch $routeMatch */
     $routeMatch = $app->getMvcEvent()->getRouteMatch();
     if ($routeMatch->getParam('response')) {
         $response = $serviceLocator->get($routeMatch->getParam('response'));
         if (!$response instanceof ResponseInterface) {
             throw new \RuntimeException('Response must be instance of ' . ResponseInterface::class);
         }
     } else {
         $response = new Response();
     }
     $redirectTo = $routeMatch->getParam('redirectTo');
     if (!empty($redirectTo) && !is_string($redirectTo)) {
         throw new \RuntimeException('Parameter redirectTo must be string');
     }
     $response->setRedirectTo($redirectTo);
     return $response;
 }
Пример #2
0
 public function testToArray()
 {
     $response = new Response();
     $criteria = ['some' => 'criteria'];
     $changes = ['key' => 'value'];
     $criteriaError = ['some' => 'error'];
     $changesError = ['some' => 'error'];
     $result = ['some' => 'result'];
     $response->setResult($result);
     $response->setCriteriaErrors($criteriaError);
     $response->setChangesErrors($changesError);
     $response->setCriteria($criteria);
     $response->setValidCriteria($criteria);
     $response->setChanges($changes);
     $response->setValidChanges($changes);
     $resultArray = $response->toArray();
     $this->assertEquals(['result' => $result, 'criteriaErrors' => $criteriaError, 'changesErrors' => $changesError, 'criteria' => $criteria, 'changes' => $changes, 'validCriteria' => $criteria, 'validChanges' => $changes], $resultArray);
 }