2012-04-12 12:48:36 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Nelmio\ApiBundle\Formatter;
|
|
|
|
|
|
|
|
use Nelmio\ApiBundle\Annotation\ApiDoc;
|
|
|
|
use Symfony\Component\Routing\Route;
|
|
|
|
|
|
|
|
class HtmlFormatter extends AbstractFormatter
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* {@inheritdoc}
|
|
|
|
*/
|
|
|
|
public function formatOne(ApiDoc $apiDoc, Route $route)
|
|
|
|
{
|
2012-04-12 17:24:38 +02:00
|
|
|
extract(array('content' => parent::formatOne($apiDoc, $route)));
|
|
|
|
|
|
|
|
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 17:24:38 +02:00
|
|
|
extract(array('content' => $content));
|
2012-04-12 12:48:36 +02:00
|
|
|
|
|
|
|
ob_start();
|
|
|
|
include __DIR__ . '/../Resources/views/formatter_layout.html.php';
|
|
|
|
|
|
|
|
return ob_get_clean();
|
|
|
|
}
|
|
|
|
}
|