Added support for host parameter

This commit is contained in:
Benjamin Laugueux 2013-04-11 22:03:40 +02:00
parent 0b7e734594
commit 5cc7cf212d
4 changed files with 35 additions and 1 deletions

View File

@ -80,6 +80,11 @@ class ApiDoc
*/
private $method;
/**
* @var string
*/
private $host;
/**
* @var string
*/
@ -302,6 +307,7 @@ class ApiDoc
public function setRoute(Route $route)
{
$this->route = $route;
$this->host = $route->getHost() ?: null;
$this->uri = $route->getPattern();
$this->method = $route->getRequirement('_method') ?: 'ANY';
}
@ -314,6 +320,22 @@ class ApiDoc
return $this->route;
}
/**
* @return string
*/
public function getHost()
{
return $this->host;
}
/**
* @param string $host
*/
public function setHost($host)
{
$this->host = $host;
}
/**
* @return boolean
*/
@ -389,6 +411,10 @@ class ApiDoc
'uri' => $this->uri,
);
if ($host = $this->host) {
$data['host'] = $host;
}
if ($description = $this->description) {
$data['description'] = $description;
}

View File

@ -19,6 +19,10 @@
{% endif %}
<span class="path">
{% if data.host is defined -%}
{{ data.https ? 'https://' : 'http://' -}}
{{ data.host -}}
{% endif -%}
{{ data.uri }}
</span>
</h3>
@ -29,7 +33,7 @@
</ul>
</div>
<div class="content" style="display: {% if displayContent is defined and displayContent == true %}display{% else %}none{% endif %};">
<div class="content" style="display: {% if displayContent is defined and displayContent == true %}display{% else %}none{% endif %};">
<ul class="tabs">
<li class="selected" data-pane="content">Documentation</li>
{% if enableSandbox %}

View File

@ -6,6 +6,7 @@ test_route_1:
test_route_2:
pattern: /tests.{_format}
host: api.test.dev
defaults: { _controller: NelmioApiDocTestBundle:Test:postTest, _format: json }
requirements:
_method: POST
@ -76,6 +77,7 @@ test_service_route_1:
test_service_route_2:
pattern: /tests.{_format}
host: api.test.dev
defaults: { _controller: nemlio.test.controller:postTestAction, _format: json }
requirements:
_method: POST

View File

@ -100,6 +100,7 @@ class SimpleFormatterTest extends WebTestCase
array (
'method' => 'POST',
'uri' => '/tests.{_format}',
'host' => 'api.test.dev',
'description' => 'create test',
'parameters' =>
array (
@ -142,6 +143,7 @@ class SimpleFormatterTest extends WebTestCase
array (
'method' => 'POST',
'uri' => '/tests.{_format}',
'host' => 'api.test.dev',
'description' => 'create test',
'parameters' =>
array (