Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow
custom processors
through tagged services (#2149)
* POC for custom processors * Theoretically, there could be more than one ApiDocGenerator * Register the Generator as a dependency * Register the Generator as a proper service * Register the "Before" attribute in the custom processor pass * Update Tests * Code Style enhancements. * ID has to be a reference * Prefix the service tag for better namespacing * Make the generator optional... * Move the generator for BC Co-authored-by: Djordy Koert <djordy.koert@live.nl> * remove spaces --------- Co-authored-by: Djordy Koert <djordy.koert@live.nl> Co-authored-by: Djordy Koert <djordy.koert@gmail.com>
- Loading branch information
1 parent
5130757
commit aa162b7
Showing
5 changed files
with
101 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the NelmioApiDocBundle package. | ||
* | ||
* (c) Nelmio | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Nelmio\ApiDocBundle\DependencyInjection\Compiler; | ||
|
||
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; | ||
use Symfony\Component\DependencyInjection\ContainerBuilder; | ||
use Symfony\Component\DependencyInjection\Reference; | ||
|
||
/** | ||
* Compiler Pass to identify and register custom processors. | ||
* * | ||
* @internal | ||
*/ | ||
final class CustomProcessorPass implements CompilerPassInterface | ||
{ | ||
/** | ||
* Process services tagged as 'swagger.processor'. | ||
* | ||
* @param ContainerBuilder $container The container builder | ||
*/ | ||
public function process(ContainerBuilder $container): void | ||
{ | ||
// Find the OpenAPI generator service. | ||
$definition = $container->findDefinition('nelmio_api_doc.open_api.generator'); | ||
|
||
foreach ($container->findTaggedServiceIds('nelmio_api_doc.swagger.processor') as $id => $tags) { | ||
/** | ||
* Before which processor should this processor be run? | ||
* | ||
* @var string|null | ||
*/ | ||
$before = null; | ||
|
||
// See if the processor has a 'before' attribute. | ||
foreach ($tags as $tag) { | ||
if (isset($tag['before'])) { | ||
$before = $tag['before']; | ||
} | ||
} | ||
|
||
$definition->addMethodCall('addProcessor', [new Reference($id), $before]); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters