diff --git a/DependencyInjection/NelmioApiDocExtension.php b/DependencyInjection/NelmioApiDocExtension.php index 6298f78..ce10263 100644 --- a/DependencyInjection/NelmioApiDocExtension.php +++ b/DependencyInjection/NelmioApiDocExtension.php @@ -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 { diff --git a/Extractor/Handler/FosRestHandler.php b/Extractor/Handler/FosRestHandler.php index 8ad2602..a3b3373 100644 --- a/Extractor/Handler/FosRestHandler.php +++ b/Extractor/Handler/FosRestHandler.php @@ -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, diff --git a/Extractor/Handler/JmsSecurityExtraHandler.php b/Extractor/Handler/JmsSecurityExtraHandler.php index 6dfca7a..2c639b4 100644 --- a/Extractor/Handler/JmsSecurityExtraHandler.php +++ b/Extractor/Handler/JmsSecurityExtraHandler.php @@ -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); } } diff --git a/Extractor/Handler/SensioFrameworkExtraHandler.php b/Extractor/Handler/SensioFrameworkExtraHandler.php index e92f143..55eac5c 100644 --- a/Extractor/Handler/SensioFrameworkExtraHandler.php +++ b/Extractor/Handler/SensioFrameworkExtraHandler.php @@ -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()); } } diff --git a/Extractor/HandlerInterface.php b/Extractor/HandlerInterface.php index 00557e1..ae2f475 100644 --- a/Extractor/HandlerInterface.php +++ b/Extractor/HandlerInterface.php @@ -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); } diff --git a/README.md b/README.md index a146aa2..13ba96e 100644 --- a/README.md +++ b/README.md @@ -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: