2012-04-12 12:48:36 +02:00
|
|
|
|
<?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;
|
2012-04-12 12:48:36 +02:00
|
|
|
|
|
2012-04-13 11:24:57 +02:00
|
|
|
|
use Symfony\Component\Templating\EngineInterface;
|
2012-04-12 12:48:36 +02:00
|
|
|
|
|
|
|
|
|
class HtmlFormatter extends AbstractFormatter
|
|
|
|
|
{
|
2012-08-10 13:55:35 +02:00
|
|
|
|
/**
|
2012-11-17 17:38:35 +01:00
|
|
|
|
* @var string
|
2012-08-10 13:55:35 +02:00
|
|
|
|
*/
|
2012-11-17 17:38:35 +01:00
|
|
|
|
protected $apiName;
|
2012-08-10 13:55:35 +02:00
|
|
|
|
|
2012-04-12 20:34:19 +02:00
|
|
|
|
/**
|
|
|
|
|
* @var string
|
|
|
|
|
*/
|
2012-11-17 17:38:35 +01:00
|
|
|
|
protected $endpoint;
|
2012-04-12 20:34:19 +02:00
|
|
|
|
|
2012-05-24 01:22:45 +02:00
|
|
|
|
/**
|
|
|
|
|
* @var string
|
|
|
|
|
*/
|
2012-11-17 17:38:35 +01:00
|
|
|
|
protected $defaultRequestFormat;
|
2012-07-18 13:18:26 +02:00
|
|
|
|
|
|
|
|
|
/**
|
2012-11-17 17:38:35 +01:00
|
|
|
|
* @var EngineInterface
|
2012-07-18 13:18:26 +02:00
|
|
|
|
*/
|
2012-11-17 17:38:35 +01:00
|
|
|
|
protected $engine;
|
2012-05-24 01:22:45 +02:00
|
|
|
|
|
2012-04-13 11:24:57 +02:00
|
|
|
|
/**
|
2012-11-17 17:38:35 +01:00
|
|
|
|
* @var boolean
|
2012-04-13 11:24:57 +02:00
|
|
|
|
*/
|
2012-11-17 17:38:35 +01:00
|
|
|
|
private $enableSandbox;
|
2012-04-13 11:24:57 +02:00
|
|
|
|
|
2012-10-16 23:41:16 +04:00
|
|
|
|
/**
|
|
|
|
|
* @var string
|
|
|
|
|
*/
|
2012-10-17 15:15:35 +04:00
|
|
|
|
private $requestFormatMethod;
|
2012-10-16 23:41:16 +04:00
|
|
|
|
|
2012-12-11 17:59:03 -08:00
|
|
|
|
/**
|
|
|
|
|
* @var string
|
|
|
|
|
*/
|
|
|
|
|
private $acceptType;
|
|
|
|
|
|
2012-10-17 15:27:20 +04:00
|
|
|
|
/**
|
2012-11-17 17:38:35 +01:00
|
|
|
|
* @var array
|
2012-10-17 15:27:20 +04:00
|
|
|
|
*/
|
2012-11-17 17:38:35 +01:00
|
|
|
|
private $authentication;
|
2012-10-17 15:27:20 +04:00
|
|
|
|
|
2012-08-10 13:55:35 +02:00
|
|
|
|
/**
|
|
|
|
|
* @param array $authentication
|
|
|
|
|
*/
|
|
|
|
|
public function setAuthentication(array $authentication = null)
|
|
|
|
|
{
|
|
|
|
|
$this->authentication = $authentication;
|
|
|
|
|
}
|
|
|
|
|
|
2012-04-12 20:34:19 +02:00
|
|
|
|
/**
|
|
|
|
|
* @param string $apiName
|
|
|
|
|
*/
|
|
|
|
|
public function setApiName($apiName)
|
|
|
|
|
{
|
|
|
|
|
$this->apiName = $apiName;
|
|
|
|
|
}
|
|
|
|
|
|
2012-05-24 01:22:45 +02:00
|
|
|
|
/**
|
2012-07-18 13:18:26 +02:00
|
|
|
|
* @param string $endpoint
|
|
|
|
|
*/
|
|
|
|
|
public function setEndpoint($endpoint)
|
|
|
|
|
{
|
|
|
|
|
$this->endpoint = $endpoint;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @param boolean $enableSandbox
|
2012-05-24 01:22:45 +02:00
|
|
|
|
*/
|
2012-07-18 13:18:26 +02:00
|
|
|
|
public function setEnableSandbox($enableSandbox)
|
2012-05-24 01:22:45 +02:00
|
|
|
|
{
|
2012-07-18 13:18:26 +02:00
|
|
|
|
$this->enableSandbox = $enableSandbox;
|
2012-05-24 01:22:45 +02:00
|
|
|
|
}
|
|
|
|
|
|
2012-04-12 12:48:36 +02:00
|
|
|
|
/**
|
2012-04-13 11:24:57 +02:00
|
|
|
|
* @param EngineInterface $engine
|
2012-04-12 12:48:36 +02:00
|
|
|
|
*/
|
2012-04-13 11:24:57 +02:00
|
|
|
|
public function setTemplatingEngine(EngineInterface $engine)
|
2012-04-12 12:48:36 +02:00
|
|
|
|
{
|
2012-04-13 11:24:57 +02:00
|
|
|
|
$this->engine = $engine;
|
2012-04-12 12:48:36 +02:00
|
|
|
|
}
|
|
|
|
|
|
2012-12-11 17:59:03 -08:00
|
|
|
|
/**
|
|
|
|
|
* @param string $acceptType
|
|
|
|
|
*/
|
|
|
|
|
public function setAcceptType($acceptType)
|
|
|
|
|
{
|
|
|
|
|
$this->acceptType = $acceptType;
|
|
|
|
|
}
|
|
|
|
|
|
2012-10-16 23:41:16 +04:00
|
|
|
|
/**
|
|
|
|
|
* @param string $method
|
|
|
|
|
*/
|
2012-10-17 15:15:35 +04:00
|
|
|
|
public function setRequestFormatMethod($method)
|
2012-10-16 23:41:16 +04:00
|
|
|
|
{
|
2012-10-17 15:15:35 +04:00
|
|
|
|
$this->requestFormatMethod = $method;
|
2012-10-16 23:41:16 +04:00
|
|
|
|
}
|
|
|
|
|
|
2012-11-15 21:58:09 +01:00
|
|
|
|
/**
|
|
|
|
|
* @param string $format
|
|
|
|
|
*/
|
2012-10-17 15:27:20 +04:00
|
|
|
|
public function setDefaultRequestFormat($format)
|
|
|
|
|
{
|
|
|
|
|
$this->defaultRequestFormat = $format;
|
|
|
|
|
}
|
|
|
|
|
|
2012-04-12 12:48:36 +02:00
|
|
|
|
/**
|
|
|
|
|
* {@inheritdoc}
|
|
|
|
|
*/
|
|
|
|
|
protected function renderOne(array $data)
|
|
|
|
|
{
|
2012-04-13 11:24:57 +02:00
|
|
|
|
return $this->engine->render('NelmioApiDocBundle::resource.html.twig', array_merge(
|
2012-11-15 21:58:09 +01:00
|
|
|
|
array(
|
|
|
|
|
'data' => $data,
|
|
|
|
|
'displayContent' => true,
|
|
|
|
|
),
|
2012-04-13 11:24:57 +02:00
|
|
|
|
$this->getGlobalVars()
|
|
|
|
|
));
|
2012-04-12 12:48:36 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* {@inheritdoc}
|
|
|
|
|
*/
|
2012-04-13 11:24:57 +02:00
|
|
|
|
protected function render(array $collection)
|
2012-04-12 12:48:36 +02:00
|
|
|
|
{
|
2012-04-13 11:24:57 +02:00
|
|
|
|
return $this->engine->render('NelmioApiDocBundle::resources.html.twig', array_merge(
|
2012-11-15 21:58:09 +01:00
|
|
|
|
array(
|
|
|
|
|
'resources' => $collection,
|
|
|
|
|
),
|
2012-04-13 11:24:57 +02:00
|
|
|
|
$this->getGlobalVars()
|
|
|
|
|
));
|
2012-04-12 17:24:38 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2012-04-13 11:24:57 +02:00
|
|
|
|
* @return array
|
2012-04-12 17:24:38 +02:00
|
|
|
|
*/
|
2012-04-13 11:24:57 +02:00
|
|
|
|
private function getGlobalVars()
|
2012-04-12 12:48:36 +02:00
|
|
|
|
{
|
2012-04-13 11:24:57 +02:00
|
|
|
|
return array(
|
2012-10-17 15:27:20 +04:00
|
|
|
|
'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,
|
2012-10-17 15:27:20 +04:00
|
|
|
|
'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'),
|
2012-04-13 11:24:57 +02:00
|
|
|
|
);
|
2012-04-12 12:48:36 +02:00
|
|
|
|
}
|
|
|
|
|
}
|