Implement Tags for functions.

This commit is contained in:
Sandro Meier 2014-05-27 13:33:50 +02:00
parent dfb089f993
commit dfd094371d
4 changed files with 75 additions and 0 deletions

View File

@ -135,6 +135,11 @@ class ApiDoc
*/ */
private $statusCodes = array(); private $statusCodes = array();
/**
* @var array
*/
private $tags = array();
public function __construct(array $data) public function __construct(array $data)
{ {
$this->resource = !empty($data['resource']) ? $data['resource'] : false; $this->resource = !empty($data['resource']) ? $data['resource'] : false;
@ -223,6 +228,16 @@ class ApiDoc
$this->deprecated = $data['deprecated']; $this->deprecated = $data['deprecated'];
} }
if (isset($data['tags'])) {
$tags = $data['tags'];
if (!is_array($tags)) {
$tags = array($tags);
}
$this->tags = $tags;
}
if (isset($data['https'])) { if (isset($data['https'])) {
$this->https = $data['https']; $this->https = $data['https'];
} }
@ -507,6 +522,14 @@ class ApiDoc
return $this->requirements; return $this->requirements;
} }
/**
* @return array
*/
public function getTags()
{
return $this->tags;
}
/** /**
* @param boolean $deprecated * @param boolean $deprecated
*/ */
@ -571,6 +594,10 @@ class ApiDoc
$data['cache'] = $cache; $data['cache'] = $cache;
} }
if ($tags = $this->tags) {
$data['tags'] = $tags;
}
$data['https'] = $this->https; $data['https'] = $this->https;
$data['authentication'] = $this->authentication; $data['authentication'] = $this->authentication;
$data['authenticationRoles'] = $this->authenticationRoles; $data['authenticationRoles'] = $this->authenticationRoles;

View File

@ -296,6 +296,18 @@ li.operation a.heading h3 span.path {
padding-left: 5px; padding-left: 5px;
} }
li.operation a.heading h3 span.tag {
color: #FFFFFF;
font-size: 0.7em;
vertical-align: baseline;
background-color: #d9534f;
padding-bottom: 3px;
padding-left: 6px;
padding-right: 6px;
padding-top: 2px;
border-radius: 4px;
}
li.operation div.content { li.operation div.content {
border: 1px solid #ddd; border: 1px solid #ddd;
padding: 10px; padding: 10px;

View File

@ -25,6 +25,11 @@
{% endif -%} {% endif -%}
{{ data.uri }} {{ data.uri }}
</span> </span>
{% if data.tags is defined %}
{% for tag in data.tags %}
<span class="tag">{{ tag }}</span>
{% endfor %}
{% endif %}
</h3> </h3>
<ul class="options"> <ul class="options">
{% if data.description is defined %} {% if data.description is defined %}

View File

@ -288,4 +288,35 @@ class ApiDocTest extends TestCase
$this->assertTrue(isset($array['parameters']['fooId'])); $this->assertTrue(isset($array['parameters']['fooId']));
$this->assertTrue(isset($array['parameters']['fooId']['dataType'])); $this->assertTrue(isset($array['parameters']['fooId']['dataType']));
} }
public function testConstructWithOneTag()
{
$data = array(
'tags' => 'beta'
);
$annot = new ApiDoc($data);
$array = $annot->toArray();
$this->assertTrue(is_array($array));
$this->assertTrue(is_array($array['tags']), 'Single tag should be put in array');
$this->assertEquals(array('beta'), $array['tags']);
}
public function testConstructWithMultipleTags()
{
$data = array(
'tags' => array(
'experimental',
'alpha'
)
);
$annot = new ApiDoc($data);
$array = $annot->toArray();
$this->assertTrue(is_array($array));
$this->assertTrue(is_array($array['tags']), 'Tags should be in array');
$this->assertEquals($data['tags'], $array['tags']);
}
} }