mirror of
https://github.com/retailcrm/NelmioApiDocBundle.git
synced 2025-02-02 23:59:26 +03:00
80 lines
1.7 KiB
PHP
80 lines
1.7 KiB
PHP
<?php
|
|
|
|
/*
|
|
* 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.
|
|
*/
|
|
|
|
namespace Nelmio\ApiDocBundle\Formatter;
|
|
|
|
use Nelmio\ApiDocBundle\Annotation\ApiDoc;
|
|
use Symfony\Component\Routing\Route;
|
|
use Symfony\Component\Templating\EngineInterface;
|
|
|
|
class HtmlFormatter extends AbstractFormatter
|
|
{
|
|
/**
|
|
* @var string
|
|
*/
|
|
private $apiName;
|
|
|
|
/**
|
|
* @var \Symfony\Component\Templating\EngineInterface
|
|
*/
|
|
private $engine;
|
|
|
|
/**
|
|
* @param string $apiName
|
|
*/
|
|
public function setApiName($apiName)
|
|
{
|
|
$this->apiName = $apiName;
|
|
}
|
|
|
|
/**
|
|
* @param EngineInterface $engine
|
|
*/
|
|
public function setTemplatingEngine(EngineInterface $engine)
|
|
{
|
|
$this->engine = $engine;
|
|
}
|
|
|
|
/**
|
|
* {@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,
|
|
'date' => date(DATE_RFC822),
|
|
'css' => file_get_contents(__DIR__ . '/../Resources/public/css/screen.css'),
|
|
);
|
|
}
|
|
}
|