mirror of
https://github.com/retailcrm/NelmioApiDocBundle.git
synced 2025-02-02 15:51:48 +03:00
implementing all stof comments :)
This commit is contained in:
parent
63b0f8e4da
commit
76b85938c6
37
DependencyInjection/ExtractorHandlerCompilerPass.php
Normal file
37
DependencyInjection/ExtractorHandlerCompilerPass.php
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
<?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\DependencyInjection;
|
||||||
|
|
||||||
|
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||||
|
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
|
||||||
|
use Symfony\Component\DependencyInjection\Reference;
|
||||||
|
|
||||||
|
|
||||||
|
class ExtractorHandlerCompilerPass implements CompilerPassInterface
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
public function process(ContainerBuilder $container)
|
||||||
|
{
|
||||||
|
$handlers = array();
|
||||||
|
foreach ($container->findTaggedServiceIds('nelmio_api_doc.extractor.handler') as $id => $attributes) {
|
||||||
|
|
||||||
|
// Adding handlers from tagged services
|
||||||
|
$handlers[] = new Reference($id);
|
||||||
|
}
|
||||||
|
$definition = $container->getDefinition(
|
||||||
|
'nelmio_api_doc.extractor.api_doc_extractor'
|
||||||
|
);
|
||||||
|
$definition->replaceArgument(4, $handlers);
|
||||||
|
}
|
||||||
|
}
|
@ -49,18 +49,5 @@ class NelmioApiDocExtension extends Extension
|
|||||||
if (isset($config['sandbox']['authentication'])) {
|
if (isset($config['sandbox']['authentication'])) {
|
||||||
$container->setParameter('nelmio_api_doc.sandbox.authentication', $config['sandbox']['authentication']);
|
$container->setParameter('nelmio_api_doc.sandbox.authentication', $config['sandbox']['authentication']);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Adding handlers from tagged services
|
|
||||||
$definition = $container->getDefinition(
|
|
||||||
'nelmio_api_doc.extractor.api_doc_extractor'
|
|
||||||
);
|
|
||||||
$taggedServices = $container->findTaggedServiceIds(
|
|
||||||
'nelmio_api_doc.extractor.handler'
|
|
||||||
);
|
|
||||||
$handlers = array();
|
|
||||||
foreach ($taggedServices as $id => $attributes) {
|
|
||||||
$handlers[] = new Reference($id);
|
|
||||||
}
|
|
||||||
$definition->replaceArgument(4, $handlers);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -19,7 +19,6 @@ use Symfony\Component\Routing\RouterInterface;
|
|||||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||||
use Symfony\Component\HttpFoundation\Request;
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
use Nelmio\ApiDocBundle\Util\DocCommentExtractor;
|
use Nelmio\ApiDocBundle\Util\DocCommentExtractor;
|
||||||
use Nelmio\ApiDocBundle\Extractor\Handler\HandlerInterface;
|
|
||||||
|
|
||||||
class ApiDocExtractor
|
class ApiDocExtractor
|
||||||
{
|
{
|
||||||
@ -55,7 +54,7 @@ class ApiDocExtractor
|
|||||||
*/
|
*/
|
||||||
protected $handlers;
|
protected $handlers;
|
||||||
|
|
||||||
public function __construct(ContainerInterface $container, RouterInterface $router, Reader $reader, DocCommentExtractor $commentExtractor, $handlers)
|
public function __construct(ContainerInterface $container, RouterInterface $router, Reader $reader, DocCommentExtractor $commentExtractor, array $handlers)
|
||||||
{
|
{
|
||||||
$this->container = $container;
|
$this->container = $container;
|
||||||
$this->router = $router;
|
$this->router = $router;
|
||||||
@ -360,7 +359,7 @@ class ApiDocExtractor
|
|||||||
{
|
{
|
||||||
$annots = $this->reader->getMethodAnnotations($method);
|
$annots = $this->reader->getMethodAnnotations($method);
|
||||||
foreach ($this->handlers as $handler) {
|
foreach ($this->handlers as $handler) {
|
||||||
$handler->handle($annotation, $annots);
|
$handler->handle($annotation, $annots, $route, $method);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,22 +0,0 @@
|
|||||||
<?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;
|
|
||||||
use \Nelmio\ApiDocBundle\Annotation\ApiDoc;
|
|
||||||
|
|
||||||
class EmptyHandler implements HandlerInterface
|
|
||||||
{
|
|
||||||
public function handle(ApiDoc $annotation, $annotations)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
}
|
|
@ -12,16 +12,25 @@
|
|||||||
namespace Nelmio\ApiDocBundle\Extractor\Handler;
|
namespace Nelmio\ApiDocBundle\Extractor\Handler;
|
||||||
|
|
||||||
use Nelmio\ApiDocBundle\Extractor\HandlerInterface;
|
use Nelmio\ApiDocBundle\Extractor\HandlerInterface;
|
||||||
use \Nelmio\ApiDocBundle\Annotation\ApiDoc;
|
use Nelmio\ApiDocBundle\Annotation\ApiDoc;
|
||||||
|
use Symfony\Component\Routing\Route;
|
||||||
|
|
||||||
class FosRestQueryParamHandler implements HandlerInterface
|
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';
|
const FOS_REST_QUERY_PARAM_CLASS = 'FOS\\RestBundle\\Controller\\Annotations\\QueryParam';
|
||||||
|
|
||||||
public function handle(ApiDoc $annotation, $annotations)
|
public function handle(ApiDoc $annotation, $annotations, Route $route, \ReflectionMethod $method)
|
||||||
{
|
{
|
||||||
foreach ($annotations as $annot) {
|
foreach ($annotations as $annot) {
|
||||||
if (is_a($annot, self::FOS_REST_QUERY_PARAM_CLASS)) {
|
if (is_a($annot, self::FOS_REST_REQUEST_PARAM_CLASS)) {
|
||||||
|
$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)) {
|
||||||
if ($annot->strict && $annot->default === null) {
|
if ($annot->strict && $annot->default === null) {
|
||||||
$annotation->addRequirement($annot->name, array(
|
$annotation->addRequirement($annot->name, array(
|
||||||
'requirement' => $annot->requirements,
|
'requirement' => $annot->requirements,
|
@ -1,34 +0,0 @@
|
|||||||
<?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;
|
|
||||||
use \Nelmio\ApiDocBundle\Annotation\ApiDoc;
|
|
||||||
|
|
||||||
class FosRestRequestParamHandler implements HandlerInterface
|
|
||||||
{
|
|
||||||
const FOS_REST_REQUEST_PARAM_CLASS = 'FOS\\RestBundle\\Controller\\Annotations\\RequestParam';
|
|
||||||
|
|
||||||
public function handle(ApiDoc $annotation, $annotations)
|
|
||||||
{
|
|
||||||
foreach ($annotations as $annot) {
|
|
||||||
if (is_a($annot, self::FOS_REST_REQUEST_PARAM_CLASS)) {
|
|
||||||
$annotation->addParameter($annot->name, array(
|
|
||||||
'required' => $annot->strict && $annot->default === null,
|
|
||||||
'dataType' => $annot->requirements,
|
|
||||||
'description' => $annot->description,
|
|
||||||
'readonly' => false
|
|
||||||
));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -12,13 +12,14 @@
|
|||||||
namespace Nelmio\ApiDocBundle\Extractor\Handler;
|
namespace Nelmio\ApiDocBundle\Extractor\Handler;
|
||||||
|
|
||||||
use Nelmio\ApiDocBundle\Extractor\HandlerInterface;
|
use Nelmio\ApiDocBundle\Extractor\HandlerInterface;
|
||||||
use \Nelmio\ApiDocBundle\Annotation\ApiDoc;
|
use Nelmio\ApiDocBundle\Annotation\ApiDoc;
|
||||||
|
use Symfony\Component\Routing\Route;
|
||||||
|
|
||||||
class JmsSecurityExtraSecureHandler implements HandlerInterface
|
class JmsSecurityExtraHandler implements HandlerInterface
|
||||||
{
|
{
|
||||||
const JMS_SECURITY_EXTRA_SECURE_CLASS = 'JMS\\SecurityExtraBundle\\Annotation\\Secure';
|
const JMS_SECURITY_EXTRA_SECURE_CLASS = 'JMS\\SecurityExtraBundle\\Annotation\\Secure';
|
||||||
|
|
||||||
public function handle(ApiDoc $annotation, $annotations)
|
public function handle(ApiDoc $annotation, $annotations, Route $route, \ReflectionMethod $method)
|
||||||
{
|
{
|
||||||
foreach ($annotations as $annot) {
|
foreach ($annotations as $annot) {
|
||||||
if (is_a($annot, self::JMS_SECURITY_EXTRA_SECURE_CLASS)) {
|
if (is_a($annot, self::JMS_SECURITY_EXTRA_SECURE_CLASS)) {
|
@ -12,13 +12,14 @@
|
|||||||
namespace Nelmio\ApiDocBundle\Extractor\Handler;
|
namespace Nelmio\ApiDocBundle\Extractor\Handler;
|
||||||
|
|
||||||
use Nelmio\ApiDocBundle\Extractor\HandlerInterface;
|
use Nelmio\ApiDocBundle\Extractor\HandlerInterface;
|
||||||
use \Nelmio\ApiDocBundle\Annotation\ApiDoc;
|
use Nelmio\ApiDocBundle\Annotation\ApiDoc;
|
||||||
|
use Symfony\Component\Routing\Route;
|
||||||
|
|
||||||
class SensioFrameworkExtraCacheHandler implements HandlerInterface
|
class SensioFrameworkExtraHandler implements HandlerInterface
|
||||||
{
|
{
|
||||||
const CACHE_ANNOTATION_CLASS = 'Sensio\\Bundle\\FrameworkExtraBundle\\Configuration\\Cache';
|
const CACHE_ANNOTATION_CLASS = 'Sensio\\Bundle\\FrameworkExtraBundle\\Configuration\\Cache';
|
||||||
|
|
||||||
public function handle(ApiDoc $annotation, $annotations)
|
public function handle(ApiDoc $annotation, $annotations, Route $route, \ReflectionMethod $method)
|
||||||
{
|
{
|
||||||
foreach ($annotations as $annot) {
|
foreach ($annotations as $annot) {
|
||||||
if (is_a($annot, self::CACHE_ANNOTATION_CLASS)) {
|
if (is_a($annot, self::CACHE_ANNOTATION_CLASS)) {
|
@ -13,7 +13,9 @@ namespace Nelmio\ApiDocBundle\Extractor;
|
|||||||
|
|
||||||
use Nelmio\ApiDocBundle\Annotation\ApiDoc;
|
use Nelmio\ApiDocBundle\Annotation\ApiDoc;
|
||||||
|
|
||||||
|
use Symfony\Component\Routing\Route;
|
||||||
|
|
||||||
interface HandlerInterface
|
interface HandlerInterface
|
||||||
{
|
{
|
||||||
public function handle(ApiDoc $annotation, $annotations);
|
public function handle(ApiDoc $annotation, $annotations, Route $route, \ReflectionMethod $method);
|
||||||
}
|
}
|
||||||
|
@ -6,6 +6,7 @@ use Symfony\Component\HttpKernel\Bundle\Bundle;
|
|||||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||||
use Nelmio\ApiDocBundle\DependencyInjection\RegisterJmsParserPass;
|
use Nelmio\ApiDocBundle\DependencyInjection\RegisterJmsParserPass;
|
||||||
use Nelmio\ApiDocBundle\DependencyInjection\RegisterExtractorParsersPass;
|
use Nelmio\ApiDocBundle\DependencyInjection\RegisterExtractorParsersPass;
|
||||||
|
use Nelmio\ApiDocBundle\DependencyInjection\ExtractorHandlerCompilerPass;
|
||||||
|
|
||||||
class NelmioApiDocBundle extends Bundle
|
class NelmioApiDocBundle extends Bundle
|
||||||
{
|
{
|
||||||
@ -15,5 +16,6 @@ class NelmioApiDocBundle extends Bundle
|
|||||||
|
|
||||||
$container->addCompilerPass(new RegisterJmsParserPass());
|
$container->addCompilerPass(new RegisterJmsParserPass());
|
||||||
$container->addCompilerPass(new RegisterExtractorParsersPass());
|
$container->addCompilerPass(new RegisterExtractorParsersPass());
|
||||||
|
$container->addCompilerPass(new ExtractorHandlerCompilerPass());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -9,10 +9,9 @@
|
|||||||
<parameter key="nelmio_api_doc.twig.extension.extra_markdown.class">Nelmio\ApiDocBundle\Twig\Extension\MarkdownExtension</parameter>
|
<parameter key="nelmio_api_doc.twig.extension.extra_markdown.class">Nelmio\ApiDocBundle\Twig\Extension\MarkdownExtension</parameter>
|
||||||
<parameter key="nelmio_api_doc.doc_comment_extractor.class">Nelmio\ApiDocBundle\Util\DocCommentExtractor</parameter>
|
<parameter key="nelmio_api_doc.doc_comment_extractor.class">Nelmio\ApiDocBundle\Util\DocCommentExtractor</parameter>
|
||||||
|
|
||||||
<parameter key="nelmio_api_doc.extractor.handler.fos_rest_query_param.class">Nelmio\ApiDocBundle\Extractor\Handler\FosRestQueryParamHandler</parameter>
|
<parameter key="nelmio_api_doc.extractor.handler.fos_rest.class">Nelmio\ApiDocBundle\Extractor\Handler\FosRestHandler</parameter>
|
||||||
<parameter key="nelmio_api_doc.extractor.handler.fos_rest_request_param.class">Nelmio\ApiDocBundle\Extractor\Handler\FosRestRequestParamHandler</parameter>
|
<parameter key="nelmio_api_doc.extractor.handler.jms_security.class">Nelmio\ApiDocBundle\Extractor\Handler\JmsSecurityExtraHandler</parameter>
|
||||||
<parameter key="nelmio_api_doc.extractor.handler.jms_security_secure.class">Nelmio\ApiDocBundle\Extractor\Handler\JmsSecurityExtraSecureHandler</parameter>
|
<parameter key="nelmio_api_doc.extractor.handler.sensio_framework_extra.class">Nelmio\ApiDocBundle\Extractor\Handler\SensioFrameworkExtraHandler</parameter>
|
||||||
<parameter key="nelmio_api_doc.extractor.handler.sensio_cache.class">Nelmio\ApiDocBundle\Extractor\Handler\SensioFrameworkExtraCacheHandler</parameter>
|
|
||||||
</parameters>
|
</parameters>
|
||||||
|
|
||||||
<services>
|
<services>
|
||||||
@ -36,19 +35,15 @@
|
|||||||
|
|
||||||
<!-- Extractor Annotation Handlers -->
|
<!-- Extractor Annotation Handlers -->
|
||||||
|
|
||||||
<service id="nelmio_api_doc.extractor.handler.fos_rest_query_param" class="%nelmio_api_doc.extractor.handler.fos_rest_query_param.class%">
|
<service id="nelmio_api_doc.extractor.handler.fos_rest" class="%nelmio_api_doc.extractor.handler.fos_rest.class%" public="false">
|
||||||
<tag name="nelmio_api_doc.extractor.handler"/>
|
<tag name="nelmio_api_doc.extractor.handler"/>
|
||||||
</service>
|
</service>
|
||||||
|
|
||||||
<service id="nelmio_api_doc.extractor.handler.fos_rest_request_param" class="%nelmio_api_doc.extractor.handler.fos_rest_request_param.class%">
|
<service id="nelmio_api_doc.extractor.handler.jms_security" class="%nelmio_api_doc.extractor.handler.jms_security.class%" public="false">
|
||||||
<tag name="nelmio_api_doc.extractor.handler"/>
|
<tag name="nelmio_api_doc.extractor.handler"/>
|
||||||
</service>
|
</service>
|
||||||
|
|
||||||
<service id="nelmio_api_doc.extractor.handler.jms_security_secure" class="%nelmio_api_doc.extractor.handler.jms_security_secure.class%">
|
<service id="nelmio_api_doc.extractor.handler.sensio_framework_extra" class="%nelmio_api_doc.extractor.handler.sensio_framework_extra.class%" public="false">
|
||||||
<tag name="nelmio_api_doc.extractor.handler"/>
|
|
||||||
</service>
|
|
||||||
|
|
||||||
<service id="nelmio_api_doc.extractor.handler.sension_cache" class="%nelmio_api_doc.extractor.handler.sensio_cache.class%">
|
|
||||||
<tag name="nelmio_api_doc.extractor.handler"/>
|
<tag name="nelmio_api_doc.extractor.handler"/>
|
||||||
</service>
|
</service>
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user