Example #1
0
 public function outputWriter()
 {
     try {
         $csvConfig = array();
         if (true === \array_key_exists('csv', $this->_applicationConfig) && true === \is_array($this->_applicationConfig['csv'])) {
             $csvConfig = $this->_applicationConfig['csv'];
         }
         // create output writer
         $responseOutputWriterFactory = new SlimBootstrap\ResponseOutputWriter\Factory($this->_app->request, $this->_app->response, $this->_app->response->headers, $this->_applicationConfig['shortName'], $csvConfig);
         $this->_responseOutputWriter = $responseOutputWriterFactory->create($this->_app->request->headers->get('Accept'));
     } catch (SlimBootstrap\Exception $exception) {
         $this->_handleError($exception);
     }
 }
Example #2
0
 /**
  * @param object $endpoint
  * @param string $type
  * @param array  $params
  *
  * @throws Slim\Exception\Stop
  */
 private function _handleEndpointCall($endpoint, $type, array $params)
 {
     if ($endpoint instanceof SlimBootstrap\Endpoint\InjectClientId) {
         $endpoint->setClientId($this->_app->router()->getCurrentRoute()->getParam('clientId'));
     }
     try {
         $outputWriter =& $this->_hook->getResponseOutputWriter();
         if ($endpoint instanceof SlimBootstrap\Endpoint\ForceDefaultMimeType) {
             $csvConfig = array();
             if (true === \array_key_exists('csv', $this->_applicationConfig) && true === \is_array($this->_applicationConfig['csv'])) {
                 $csvConfig = $this->_applicationConfig['csv'];
             }
             // create output writer
             $responseOutputWriterFactory = new SlimBootstrap\ResponseOutputWriter\Factory($this->_app->request, $this->_app->response, $this->_app->response->headers, $this->_applicationConfig['shortName'], $csvConfig);
             $outputWriter = $responseOutputWriterFactory->create($endpoint->getDefaultMimeType());
         }
         if ($endpoint instanceof SlimBootstrap\Endpoint\Streamable) {
             if ($outputWriter instanceof SlimBootstrap\ResponseOutputWriterStreamable) {
                 $endpoint->setOutputWriter($outputWriter);
                 \ob_start();
                 $endpoint->{$type}($params, $this->_app->request->{$type}());
                 \ob_end_clean();
             } else {
                 throw new SlimBootstrap\Exception('media type does not support streaming', 406, Slim\Log::WARN);
             }
         } else {
             $data = $endpoint->{$type}($params, $this->_app->request->{$type}());
             if ($endpoint instanceof SlimBootstrap\Endpoint\PlainData) {
                 if ($outputWriter instanceof SlimBootstrap\ResponseOutputWriterPlainData) {
                     $outputWriter->writePlain($data);
                 } else {
                     throw new SlimBootstrap\Exception('media type does not support plain data writing', 406, Slim\Log::WARN);
                 }
             } else {
                 $outputWriter->write($data);
             }
         }
     } catch (SlimBootstrap\Exception $e) {
         $this->_app->getLog()->log($e->getLogLevel(), $e->getCode() . ' - ' . $e->getMessage());
         $this->_app->response->setStatus($e->getCode());
         $this->_app->response->setBody($e->getMessage());
         $this->_app->stop();
     }
 }
Example #3
0
 /**
  * @param string $acceptHeader
  *
  * @dataProvider createFailureProvider
  *
  * @expectedException \SlimBootstrap\Exception
  * @expectedExceptionCode 406
  * @expectedExceptionMessage media type not supported (supported media types: application/hal+json, application/json, text/csv)
  */
 public function testCreateFailure($acceptHeader)
 {
     $this->_outputWriterFactory->create($acceptHeader);
 }