mirror of
https://github.com/retailcrm/NelmioApiDocBundle.git
synced 2025-02-09 02:59:27 +03:00
[ExtractorHandler] cleaning code
This commit is contained in:
parent
76b85938c6
commit
7f79ddc065
@ -16,7 +16,6 @@ use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\Config\Definition\Processor;
|
||||
use Symfony\Component\Config\FileLocator;
|
||||
use Symfony\Component\DependencyInjection\Reference;
|
||||
|
||||
class NelmioApiDocExtension extends Extension
|
||||
{
|
||||
|
@ -14,23 +14,22 @@ namespace Nelmio\ApiDocBundle\Extractor\Handler;
|
||||
use Nelmio\ApiDocBundle\Extractor\HandlerInterface;
|
||||
use Nelmio\ApiDocBundle\Annotation\ApiDoc;
|
||||
use Symfony\Component\Routing\Route;
|
||||
use FOS\RestBundle\Controller\Annotations\RequestParam;
|
||||
use FOS\RestBundle\Controller\Annotations\QueryParam;
|
||||
|
||||
class FosRestHandler implements HandlerInterface
|
||||
{
|
||||
const FOS_REST_REQUEST_PARAM_CLASS = 'FOS\\RestBundle\\Controller\\Annotations\\RequestParam';
|
||||
const FOS_REST_QUERY_PARAM_CLASS = 'FOS\\RestBundle\\Controller\\Annotations\\QueryParam';
|
||||
|
||||
public function handle(ApiDoc $annotation, $annotations, Route $route, \ReflectionMethod $method)
|
||||
{
|
||||
foreach ($annotations as $annot) {
|
||||
if (is_a($annot, self::FOS_REST_REQUEST_PARAM_CLASS)) {
|
||||
if ($annot instanceof RequestParam) {
|
||||
$annotation->addParameter($annot->name, array(
|
||||
'required' => $annot->strict && $annot->default === null,
|
||||
'dataType' => $annot->requirements,
|
||||
'description' => $annot->description,
|
||||
'readonly' => false
|
||||
));
|
||||
} elseif (is_a($annot, self::FOS_REST_QUERY_PARAM_CLASS)) {
|
||||
} elseif ($annot instanceof QueryParam) {
|
||||
if ($annot->strict && $annot->default === null) {
|
||||
$annotation->addRequirement($annot->name, array(
|
||||
'requirement' => $annot->requirements,
|
||||
|
@ -14,15 +14,14 @@ namespace Nelmio\ApiDocBundle\Extractor\Handler;
|
||||
use Nelmio\ApiDocBundle\Extractor\HandlerInterface;
|
||||
use Nelmio\ApiDocBundle\Annotation\ApiDoc;
|
||||
use Symfony\Component\Routing\Route;
|
||||
use JMS\SecurityExtraBundle\Annotation\Secure;
|
||||
|
||||
class JmsSecurityExtraHandler implements HandlerInterface
|
||||
{
|
||||
const JMS_SECURITY_EXTRA_SECURE_CLASS = 'JMS\\SecurityExtraBundle\\Annotation\\Secure';
|
||||
|
||||
public function handle(ApiDoc $annotation, $annotations, Route $route, \ReflectionMethod $method)
|
||||
{
|
||||
foreach ($annotations as $annot) {
|
||||
if (is_a($annot, self::JMS_SECURITY_EXTRA_SECURE_CLASS)) {
|
||||
if ($annot instanceof Secure) {
|
||||
$annotation->setAuthentication(true);
|
||||
}
|
||||
}
|
||||
|
@ -14,15 +14,14 @@ namespace Nelmio\ApiDocBundle\Extractor\Handler;
|
||||
use Nelmio\ApiDocBundle\Extractor\HandlerInterface;
|
||||
use Nelmio\ApiDocBundle\Annotation\ApiDoc;
|
||||
use Symfony\Component\Routing\Route;
|
||||
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Cache;
|
||||
|
||||
class SensioFrameworkExtraHandler implements HandlerInterface
|
||||
{
|
||||
const CACHE_ANNOTATION_CLASS = 'Sensio\\Bundle\\FrameworkExtraBundle\\Configuration\\Cache';
|
||||
|
||||
public function handle(ApiDoc $annotation, $annotations, Route $route, \ReflectionMethod $method)
|
||||
{
|
||||
foreach ($annotations as $annot) {
|
||||
if (is_a($annot, self::CACHE_ANNOTATION_CLASS)) {
|
||||
if ($annot instanceof Cache) {
|
||||
$annotation->setCache($annot->getMaxAge());
|
||||
}
|
||||
}
|
||||
|
@ -17,5 +17,13 @@ use Symfony\Component\Routing\Route;
|
||||
|
||||
interface HandlerInterface
|
||||
{
|
||||
/**
|
||||
* Parse route parameters in order to populate ApiDoc.
|
||||
*
|
||||
* @param Nelmio\ApiDocBundle\Annotation\ApiDoc $annotation
|
||||
* @param array $annotations
|
||||
* @param Symfony\Component\Routing\Route $route
|
||||
* @param ReflectionMethod $method
|
||||
*/
|
||||
public function handle(ApiDoc $annotation, $annotations, Route $route, \ReflectionMethod $method);
|
||||
}
|
||||
|
@ -238,7 +238,9 @@ You can also define your own motd content (above methods list). All you have to
|
||||
|
||||
## Using your own annotations ##
|
||||
|
||||
If you have developped your own project-related annotations, and you want to parse them to populate the ApiDoc, you can provide custom handlers as services. You juste have to implements the `Nelmio\ApiDocBundle\Extractor\HandlerInterface` and tag it as `nelmio_api_doc.extractor.handler`.
|
||||
If you have developped your own project-related annotations, and you want to parse them to populate the ApiDoc,
|
||||
you can provide custom handlers as services. You juste have to implements the
|
||||
`Nelmio\ApiDocBundle\Extractor\HandlerInterface` and tag it as `nelmio_api_doc.extractor.handler`.
|
||||
|
||||
#app/config/config.yml
|
||||
services:
|
||||
|
Loading…
x
Reference in New Issue
Block a user