mirror of
https://github.com/retailcrm/NelmioApiDocBundle.git
synced 2025-02-02 15:51:48 +03:00
cca97cf6af
Move logic to extract data in the Extractor Remove logic in the AbstractFormatter Use ApiDoc class as data container Update tests Add test to prove the bug with FOSRestBundle annotations (\\d+ instead of \d+)
234 lines
4.3 KiB
PHP
234 lines
4.3 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\Annotation;
|
||
|
||
use Symfony\Component\Routing\Route;
|
||
|
||
/**
|
||
* @Annotation
|
||
*/
|
||
class ApiDoc
|
||
{
|
||
/**
|
||
* @var array
|
||
*/
|
||
private $filters = array();
|
||
|
||
/**
|
||
* @var string
|
||
*/
|
||
private $formType = null;
|
||
|
||
/**
|
||
* @var string
|
||
*/
|
||
private $description = null;
|
||
|
||
/**
|
||
* @var string
|
||
*/
|
||
private $documentation = null;
|
||
|
||
/**
|
||
* @var Boolean
|
||
*/
|
||
private $isResource = false;
|
||
|
||
/**
|
||
* @var array
|
||
*/
|
||
private $requirements = array();
|
||
|
||
/**
|
||
* @var string
|
||
*/
|
||
private $method;
|
||
|
||
/**
|
||
* @var string
|
||
*/
|
||
private $uri;
|
||
|
||
/**
|
||
* @var array
|
||
*/
|
||
private $parameters = array();
|
||
|
||
/**
|
||
* @var Route
|
||
*/
|
||
private $route;
|
||
|
||
public function __construct(array $data)
|
||
{
|
||
if (isset($data['formType'])) {
|
||
$this->formType = $data['formType'];
|
||
} elseif (isset($data['filters'])) {
|
||
foreach ($data['filters'] as $filter) {
|
||
if (!isset($filter['name'])) {
|
||
throw new \InvalidArgumentException('A "filter" element has to contain a "name" attribute');
|
||
}
|
||
|
||
$name = $filter['name'];
|
||
unset($filter['name']);
|
||
|
||
$this->addFilter($name, $filter);
|
||
}
|
||
}
|
||
|
||
if (isset($data['description'])) {
|
||
$this->description = $data['description'];
|
||
}
|
||
|
||
$this->isResource = isset($data['resource']) && $data['resource'];
|
||
}
|
||
|
||
/**
|
||
* @param string $name
|
||
* @param array $filter
|
||
*/
|
||
public function addFilter($name, array $filter)
|
||
{
|
||
$this->filters[$name] = $filter;
|
||
}
|
||
|
||
/**
|
||
* @param string $name
|
||
* @param array $requirement
|
||
*/
|
||
public function addRequirement($name, array $requirement)
|
||
{
|
||
$this->requirements[$name] = $requirement;
|
||
}
|
||
|
||
/**
|
||
* @param array $requirements
|
||
*/
|
||
public function setRequirements(array $requirements)
|
||
{
|
||
$this->requirements = array_merge($this->requirements, $requirements);
|
||
}
|
||
|
||
/**
|
||
* @return string|null
|
||
*/
|
||
public function getFormType()
|
||
{
|
||
return $this->formType;
|
||
}
|
||
|
||
/**
|
||
* @return string
|
||
*/
|
||
public function getDescription()
|
||
{
|
||
return $this->description;
|
||
}
|
||
|
||
/**
|
||
* @param string $description
|
||
*/
|
||
public function setDescription($description)
|
||
{
|
||
$this->description = $description;
|
||
}
|
||
|
||
/**
|
||
* @param string $documentation
|
||
*/
|
||
public function setDocumentation($documentation)
|
||
{
|
||
$this->documentation = $documentation;
|
||
}
|
||
|
||
/**
|
||
* @return Boolean
|
||
*/
|
||
public function isResource()
|
||
{
|
||
return $this->isResource;
|
||
}
|
||
|
||
/**
|
||
* @var string $method
|
||
*/
|
||
public function setMethod($method)
|
||
{
|
||
$this->method = $method;
|
||
}
|
||
|
||
/**
|
||
* @var string $uri
|
||
*/
|
||
public function setUri($uri)
|
||
{
|
||
$this->uri = $uri;
|
||
}
|
||
|
||
/**
|
||
* @param array $parameters
|
||
*/
|
||
public function setParameters(array $parameters)
|
||
{
|
||
$this->parameters = $parameters;
|
||
}
|
||
|
||
/**
|
||
* @param Route $route
|
||
*/
|
||
public function setRoute(Route $route)
|
||
{
|
||
$this->route = $route;
|
||
}
|
||
|
||
/**
|
||
* @return Route
|
||
*/
|
||
public function getRoute()
|
||
{
|
||
return $this->route;
|
||
}
|
||
|
||
/**
|
||
* @return array
|
||
*/
|
||
public function toArray()
|
||
{
|
||
$data = array(
|
||
'method' => $this->method,
|
||
'uri' => $this->uri,
|
||
);
|
||
|
||
if ($description = $this->description) {
|
||
$data['description'] = $description;
|
||
}
|
||
|
||
if ($documentation = $this->documentation) {
|
||
$data['documentation'] = $documentation;
|
||
}
|
||
|
||
if ($filters = $this->filters) {
|
||
$data['filters'] = $filters;
|
||
}
|
||
|
||
if ($parameters = $this->parameters) {
|
||
$data['parameters'] = $parameters;
|
||
}
|
||
|
||
if ($requirements = $this->requirements) {
|
||
$data['requirements'] = $requirements;
|
||
}
|
||
|
||
return $data;
|
||
}
|
||
}
|