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-12 18:37:42 +02:00
|
|
|
use Nelmio\ApiDocBundle\Annotation\ApiDoc;
|
2012-04-12 12:48:36 +02:00
|
|
|
use Symfony\Component\Routing\Route;
|
|
|
|
|
|
|
|
class HtmlFormatter extends AbstractFormatter
|
|
|
|
{
|
2012-04-12 20:34:19 +02:00
|
|
|
/**
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
private $apiName;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param string $apiName
|
|
|
|
*/
|
|
|
|
public function setApiName($apiName)
|
|
|
|
{
|
|
|
|
$this->apiName = $apiName;
|
|
|
|
}
|
|
|
|
|
2012-04-12 12:48:36 +02:00
|
|
|
/**
|
|
|
|
* {@inheritdoc}
|
|
|
|
*/
|
|
|
|
public function formatOne(ApiDoc $apiDoc, Route $route)
|
|
|
|
{
|
2012-04-12 19:17:03 +02:00
|
|
|
$data = $this->getData($apiDoc, $route);
|
|
|
|
$data['display_content'] = true;
|
|
|
|
|
|
|
|
extract(array('content' => $this->renderOne($data)));
|
2012-04-12 17:24:38 +02:00
|
|
|
|
|
|
|
ob_start();
|
|
|
|
include __DIR__ . '/../Resources/views/formatter_resource_section.html.php';
|
|
|
|
|
|
|
|
return $this->renderWithLayout(ob_get_clean());
|
2012-04-12 12:48:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* {@inheritdoc}
|
|
|
|
*/
|
|
|
|
protected function renderOne(array $data)
|
|
|
|
{
|
|
|
|
extract($data);
|
|
|
|
|
|
|
|
ob_start();
|
|
|
|
include __DIR__ . '/../Resources/views/formatter.html.php';
|
|
|
|
|
|
|
|
return ob_get_clean();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* {@inheritdoc}
|
|
|
|
*/
|
2012-04-12 17:24:38 +02:00
|
|
|
protected function renderResourceSection($resource, array $arrayOfData)
|
2012-04-12 12:48:36 +02:00
|
|
|
{
|
|
|
|
$content = '';
|
2012-04-12 17:24:38 +02:00
|
|
|
foreach ($arrayOfData as $data) {
|
2012-04-12 12:48:36 +02:00
|
|
|
$content .= $this->renderOne($data);
|
|
|
|
}
|
|
|
|
|
2012-04-12 17:24:38 +02:00
|
|
|
extract(array('content' => $content));
|
|
|
|
|
|
|
|
ob_start();
|
|
|
|
include __DIR__ . '/../Resources/views/formatter_resource_section.html.php';
|
|
|
|
|
|
|
|
return ob_get_clean();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* {@inheritdoc}
|
|
|
|
*/
|
|
|
|
protected function render(array $collection)
|
|
|
|
{
|
|
|
|
$content = '';
|
|
|
|
foreach ($collection as $resource => $arrayOfData) {
|
|
|
|
$content .= $this->renderResourceSection($resource, $arrayOfData);
|
|
|
|
}
|
|
|
|
|
2012-04-12 12:48:36 +02:00
|
|
|
return $this->renderWithLayout($content);
|
|
|
|
}
|
|
|
|
|
|
|
|
private function renderWithLayout($content)
|
|
|
|
{
|
2012-04-12 20:34:19 +02:00
|
|
|
extract(array('api_name' => $this->apiName, 'content' => $content));
|
2012-04-12 12:48:36 +02:00
|
|
|
|
|
|
|
ob_start();
|
|
|
|
include __DIR__ . '/../Resources/views/formatter_layout.html.php';
|
|
|
|
|
|
|
|
return ob_get_clean();
|
|
|
|
}
|
|
|
|
}
|