NelmioApiDocBundle/Formatter/HtmlFormatter.php

232 lines
4.8 KiB
PHP
Raw Normal View History

<?php
2012-04-13 11:03:05 +02:00
/*
* This file is part of the NelmioApiDocBundle.
*
* (c) Nelmio <hello@nelm.io>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
2012-04-12 18:37:42 +02:00
namespace Nelmio\ApiDocBundle\Formatter;
use Symfony\Component\Templating\EngineInterface;
class HtmlFormatter extends AbstractFormatter
{
/**
2012-11-17 17:38:35 +01:00
* @var string
*/
2012-11-17 17:38:35 +01:00
protected $apiName;
/**
* @var string
*/
2012-11-17 17:38:35 +01:00
protected $endpoint;
/**
* @var string
*/
2012-11-17 17:38:35 +01:00
protected $defaultRequestFormat;
/**
2012-11-17 17:38:35 +01:00
* @var EngineInterface
*/
2012-11-17 17:38:35 +01:00
protected $engine;
/**
2012-11-17 17:38:35 +01:00
* @var boolean
*/
2012-11-17 17:38:35 +01:00
private $enableSandbox;
2014-05-17 22:45:30 +02:00
/**
* @var array
*/
private $requestFormats;
/**
* @var string
*/
2012-10-17 15:15:35 +04:00
private $requestFormatMethod;
/**
* @var string
*/
private $acceptType;
/**
* @var array
*/
private $bodyFormats;
/**
* @var string
*/
private $defaultBodyFormat;
/**
2012-11-17 17:38:35 +01:00
* @var array
*/
2012-11-17 17:38:35 +01:00
private $authentication;
2013-04-08 11:44:43 +02:00
/**
* @var string
*/
private $motdTemplate;
/**
* @param array $authentication
*/
public function setAuthentication(array $authentication = null)
{
$this->authentication = $authentication;
}
/**
* @param string $apiName
*/
public function setApiName($apiName)
{
$this->apiName = $apiName;
}
/**
* @param string $endpoint
*/
public function setEndpoint($endpoint)
{
$this->endpoint = $endpoint;
}
/**
* @param boolean $enableSandbox
*/
public function setEnableSandbox($enableSandbox)
{
$this->enableSandbox = $enableSandbox;
}
/**
* @param EngineInterface $engine
*/
public function setTemplatingEngine(EngineInterface $engine)
{
$this->engine = $engine;
}
/**
* @param string $acceptType
*/
public function setAcceptType($acceptType)
{
$this->acceptType = $acceptType;
}
/**
* @param array $bodyFormats
*/
public function setBodyFormats(array $bodyFormats)
{
$this->bodyFormats = $bodyFormats;
}
/**
* @param string $defaultBodyFormat
*/
public function setDefaultBodyFormat($defaultBodyFormat)
{
$this->defaultBodyFormat = $defaultBodyFormat;
}
/**
* @param string $method
*/
2012-10-17 15:15:35 +04:00
public function setRequestFormatMethod($method)
{
2012-10-17 15:15:35 +04:00
$this->requestFormatMethod = $method;
}
2014-05-17 22:45:30 +02:00
/**
* @param array $formats
*/
public function setRequestFormats(array $formats)
{
$this->requestFormats = $formats;
}
/**
* @param string $format
*/
public function setDefaultRequestFormat($format)
{
$this->defaultRequestFormat = $format;
}
2013-04-08 11:44:43 +02:00
/**
* @param string $motdTemplate
*/
public function setMotdTemplate($motdTemplate)
{
$this->motdTemplate = $motdTemplate;
}
/**
* @return string
*/
public function getMotdTemplate()
{
return $this->motdTemplate;
}
/**
* {@inheritdoc}
*/
protected function renderOne(array $data)
{
return $this->engine->render('NelmioApiDocBundle::resource.html.twig', array_merge(
array(
'data' => $data,
'displayContent' => true,
),
$this->getGlobalVars()
));
}
/**
* {@inheritdoc}
*/
protected function render(array $collection)
{
return $this->engine->render('NelmioApiDocBundle::resources.html.twig', array_merge(
array(
'resources' => $collection,
),
$this->getGlobalVars()
));
}
/**
* @return array
*/
private function getGlobalVars()
{
return array(
'apiName' => $this->apiName,
'authentication' => $this->authentication,
'endpoint' => $this->endpoint,
'enableSandbox' => $this->enableSandbox,
'requestFormatMethod' => $this->requestFormatMethod,
2013-01-08 16:38:52 -08:00
'acceptType' => $this->acceptType,
'bodyFormats' => $this->bodyFormats,
'defaultBodyFormat' => $this->defaultBodyFormat,
2014-05-17 22:45:30 +02:00
'requestFormats' => $this->requestFormats,
'defaultRequestFormat' => $this->defaultRequestFormat,
'date' => date(DATE_RFC822),
'css' => file_get_contents(__DIR__ . '/../Resources/public/css/screen.css'),
'js' => file_get_contents(__DIR__ . '/../Resources/public/js/all.js'),
2013-04-08 11:44:43 +02:00
'motdTemplate' => $this->motdTemplate
);
}
}