/**
  * Retrieve Service Manager configuration
  *
  * Defines ZF\Hal\JsonStrategy service factory.
  *
  * @return array
  */
 public function getServiceConfig()
 {
     return array('factories' => array('ZF\\Hal\\MetadataMap' => function ($services) {
         $config = array();
         if ($services->has('config')) {
             $config = $services->get('config');
         }
         if ($services->has('HydratorManager')) {
             $hydrators = $services->get('HydratorManager');
         } else {
             $hydrators = new HydratorPluginManager();
         }
         $map = array();
         if (isset($config['zf-hal']) && isset($config['zf-hal']['metadata_map']) && is_array($config['zf-hal']['metadata_map'])) {
             $map = $config['zf-hal']['metadata_map'];
         }
         return new Metadata\MetadataMap($map, $hydrators);
     }, 'ZF\\Hal\\JsonRenderer' => function ($services) {
         $helpers = $services->get('ViewHelperManager');
         $apiProblemRenderer = $services->get('ZF\\ApiProblem\\ApiProblemRenderer');
         $config = $services->get('Config');
         $renderer = new View\HalJsonRenderer($apiProblemRenderer);
         $renderer->setHelperPluginManager($helpers);
         return $renderer;
     }, 'ZF\\Hal\\JsonStrategy' => function ($services) {
         $renderer = $services->get('ZF\\Hal\\JsonRenderer');
         return new View\HalJsonStrategy($renderer);
     }));
 }
 public function setupRenderer()
 {
     if (!$this->helpers) {
         $this->setupHelpers();
     }
     $this->renderer = $renderer = new HalJsonRenderer(new ApiProblemRenderer());
     $renderer->setHelperPluginManager($this->helpers);
 }
 /**
  * @param ContainerInterface $container
  * @return HalJsonRenderer
  */
 public function __invoke(ContainerInterface $container)
 {
     $helpers = $container->get('ViewHelperManager');
     $apiProblemRenderer = $container->get(ApiProblemRenderer::class);
     $renderer = new HalJsonRenderer($apiProblemRenderer);
     $renderer->setHelperPluginManager($helpers);
     return $renderer;
 }
 /**
  * @param  ServiceLocatorInterface $serviceLocator
  * @return HalJsonRenderer
  */
 public function createService(ServiceLocatorInterface $serviceLocator)
 {
     $helpers = $serviceLocator->get('ViewHelperManager');
     $apiProblemRenderer = $serviceLocator->get('ZF\\ApiProblem\\ApiProblemRenderer');
     $renderer = new HalJsonRenderer($apiProblemRenderer);
     $renderer->setHelperPluginManager($helpers);
     return $renderer;
 }
 public function testRenderGivenHalJsonModelReturningApiProblemShouldReturnApiProblemInJsonFormat()
 {
     $halCollection = new Collection([]);
     $model = new HalJsonModel(['payload' => $halCollection]);
     $apiProblem = new ApiProblem(500, 'error');
     $helperPluginManager = $this->getHelperPluginManager();
     $halPlugin = $helperPluginManager->get('Hal');
     $halPlugin->expects($this->once())->method('renderCollection')->with($halCollection)->will($this->returnValue($apiProblem));
     $this->renderer->setHelperPluginManager($helperPluginManager);
     $rendered = $this->renderer->render($model);
     $apiProblemData = ['type' => 'http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html', 'title' => 'Internal Server Error', 'status' => 500, 'detail' => 'error'];
     $this->assertEquals($apiProblemData, json_decode($rendered, true));
 }