[ApiBundle] Added more comments

This commit is contained in:
William DURAND 2012-04-12 17:48:21 +02:00
parent bfaa0c6adf
commit 6285ecebb0
6 changed files with 71 additions and 5 deletions

View File

@ -51,21 +51,33 @@ class ApiDoc
$this->isResource = isset($data['resource']); $this->isResource = isset($data['resource']);
} }
/**
* @return array|null
*/
public function getFilters() public function getFilters()
{ {
return $this->filters; return $this->filters;
} }
/**
* @return string|null
*/
public function getFormType() public function getFormType()
{ {
return $this->formType; return $this->formType;
} }
/**
* @return string|null
*/
public function getDescription() public function getDescription()
{ {
return $this->description; return $this->description;
} }
/**
* @return Boolean
*/
public function isResource() public function isResource()
{ {
return $this->isResource; return $this->isResource;

View File

@ -12,7 +12,7 @@ class DumpCommand extends ContainerAwareCommand
/** /**
* @var array * @var array
*/ */
protected $availableFormats = array('markdown', 'json'); protected $availableFormats = array('markdown', 'json', 'html');
protected function configure() protected function configure()
{ {
@ -35,16 +35,20 @@ class DumpCommand extends ContainerAwareCommand
if (!$input->hasOption('format') || in_array($format, array('json'))) { if (!$input->hasOption('format') || in_array($format, array('json'))) {
$formatter = $this->getContainer()->get('nelmio.api.formatter.simple_formatter'); $formatter = $this->getContainer()->get('nelmio.api.formatter.simple_formatter');
} else { } else {
if (!in_array($format, $this->availableFormats)) {
throw new \RuntimeException(sprintf('Format "%s" not supported.', $format));
}
$formatter = $this->getContainer()->get(sprintf('nelmio.api.formatter.%s_formatter', $format)); $formatter = $this->getContainer()->get(sprintf('nelmio.api.formatter.%s_formatter', $format));
} }
$extractedDoc = $this->getContainer()->get('nelmio.api.extractor.api_doc_extractor')->all(); $extractedDoc = $this->getContainer()->get('nelmio.api.extractor.api_doc_extractor')->all();
$result = $formatter->format($extractedDoc); $formattedDoc = $formatter->format($extractedDoc);
if ('json' === $format) { if ('json' === $format) {
$output->writeln(json_encode($result)); $output->writeln(json_encode($formattedDoc));
} else { } else {
$output->writeln($result); $output->writeln($formattedDoc);
} }
} }
} }

View File

@ -11,8 +11,14 @@ use Symfony\Component\HttpKernel\Event\GetResponseEvent;
class RequestListener class RequestListener
{ {
/**
* @var \Nelmio\ApiBundle\Extractor\ApiDocExtractor
*/
protected $extractor; protected $extractor;
/**
* @var \Nelmio\ApiBundle\Formatter\FormatterInterface
*/
protected $formatter; protected $formatter;
public function __construct(ApiDocExtractor $extractor, FormatterInterface $formatter) public function __construct(ApiDocExtractor $extractor, FormatterInterface $formatter)

View File

@ -10,7 +10,7 @@ class ApiDocExtractor
const ANNOTATION_CLASS = 'Nelmio\\ApiBundle\\Annotation\\ApiDoc'; const ANNOTATION_CLASS = 'Nelmio\\ApiBundle\\Annotation\\ApiDoc';
/** /**
* @var * @var \ymfony\Component\Routing\RouterInterface
*/ */
private $router; private $router;
@ -25,6 +25,14 @@ class ApiDocExtractor
$this->reader = $reader; $this->reader = $reader;
} }
/**
* Returns an array of data where each data is an array with the following keys:
* - annotation
* - route
* - resource
*
* @return array
*/
public function all() public function all()
{ {
$array = array(); $array = array();
@ -76,6 +84,15 @@ class ApiDocExtractor
return $array; return $array;
} }
/**
* Returns an array containing two values with the following keys:
* - annotation
* - route
*
* @param string $controller
* @param Route $route
* @return array|null
*/
public function get($controller, $route) public function get($controller, $route)
{ {
preg_match('#(.+)::([\w]+)#', $controller, $matches); preg_match('#(.+)::([\w]+)#', $controller, $matches);

View File

@ -7,7 +7,20 @@ use Symfony\Component\Routing\Route;
interface FormatterInterface interface FormatterInterface
{ {
/**
* Format a collection of documentation data.
*
* @param array $collection
* @return string|array
*/
function format(array $collection); function format(array $collection);
/**
* Format documentation data for one route.
*
* @param ApiDoc $apiDoc
* @param Route $route
* return string|array
*/
function formatOne(ApiDoc $apiDoc, Route $route); function formatOne(ApiDoc $apiDoc, Route $route);
} }

View File

@ -8,8 +8,14 @@ use Symfony\Component\Form\FormFactoryInterface;
class FormTypeParser class FormTypeParser
{ {
/**
* @var \Symfony\Component\Form\FormFactoryInterface
*/
protected $formFactory; protected $formFactory;
/**
* @var array
*/
protected $mapTypes = array( protected $mapTypes = array(
'text' => 'string', 'text' => 'string',
'date' => 'date', 'date' => 'date',
@ -26,6 +32,14 @@ class FormTypeParser
$this->formFactory = $formFactory; $this->formFactory = $formFactory;
} }
/**
* Returns an array of data where each data is an array with the following keys:
* - dataType
* - required
*
* @param AbstractType $type
* @return array
*/
public function parse(AbstractType $type) public function parse(AbstractType $type)
{ {
$builder = $this->formFactory->createBuilder($type); $builder = $this->formFactory->createBuilder($type);