NelmioApiDocBundle/Extractor/Handler/FosRestHandler.php

49 lines
1.7 KiB
PHP
Raw Normal View History

<?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\Extractor\Handler;
use Nelmio\ApiDocBundle\Extractor\HandlerInterface;
2013-04-16 13:46:15 +02:00
use Nelmio\ApiDocBundle\Annotation\ApiDoc;
use Symfony\Component\Routing\Route;
2013-04-17 13:41:28 +02:00
use FOS\RestBundle\Controller\Annotations\RequestParam;
use FOS\RestBundle\Controller\Annotations\QueryParam;
2013-04-16 13:46:15 +02:00
class FosRestHandler implements HandlerInterface
{
2013-04-17 14:24:45 +02:00
public function handle(ApiDoc $annotation, array $annotations, Route $route, \ReflectionMethod $method)
{
foreach ($annotations as $annot) {
2013-04-17 13:41:28 +02:00
if ($annot instanceof RequestParam) {
2013-04-16 13:46:15 +02:00
$annotation->addParameter($annot->name, array(
'required' => $annot->strict && $annot->default === null,
'dataType' => $annot->requirements,
'description' => $annot->description,
'readonly' => false
));
2013-04-17 13:41:28 +02:00
} elseif ($annot instanceof QueryParam) {
if ($annot->strict && $annot->default === null) {
$annotation->addRequirement($annot->name, array(
'requirement' => $annot->requirements,
'dataType' => '',
'description' => $annot->description,
));
} else {
$annotation->addFilter($annot->name, array(
'requirement' => $annot->requirements,
'description' => $annot->description,
));
}
}
}
}
}