do not fail if phpdocumentor is not available

This commit is contained in:
David Buchmann 2017-12-28 10:46:05 +01:00
parent ccf7a75ec5
commit f4a9ad7ef7
2 changed files with 14 additions and 8 deletions

View File

@ -88,14 +88,18 @@ final class NelmioApiDocExtension extends Extension implements PrependExtensionI
// JMS metadata support // JMS metadata support
if ($config['models']['use_jms']) { if ($config['models']['use_jms']) {
$arguments = [
new Reference('jms_serializer.metadata_factory'),
new Reference('jms_serializer.naming_strategy'),
new Reference('nelmio_api_doc.model_describers.swagger_property_annotation_reader'),
];
// phpdocumentor is not a hard requirement, only use if available
if (class_exists(DocBlockFactory::class)) {
$arguments[] = new Reference('nelmio_api_doc.model_describers.phpdoc_property_annotation_reader');
}
$container->register('nelmio_api_doc.model_describers.jms', JMSModelDescriber::class) $container->register('nelmio_api_doc.model_describers.jms', JMSModelDescriber::class)
->setPublic(false) ->setPublic(false)
->setArguments([ ->setArguments($arguments)
new Reference('jms_serializer.metadata_factory'),
new Reference('jms_serializer.naming_strategy'),
new Reference('nelmio_api_doc.model_describers.swagger_property_annotation_reader'),
new Reference('nelmio_api_doc.model_describers.phpdoc_property_annotation_reader'),
])
->addTag('nelmio_api_doc.model_describer', ['priority' => 50]); ->addTag('nelmio_api_doc.model_describer', ['priority' => 50]);
} }

View File

@ -41,7 +41,7 @@ class JMSModelDescriber implements ModelDescriberInterface, ModelRegistryAwareIn
MetadataFactoryInterface $factory, MetadataFactoryInterface $factory,
PropertyNamingStrategyInterface $namingStrategy, PropertyNamingStrategyInterface $namingStrategy,
SwaggerPropertyAnnotationReader $swaggerPropertyAnnotationReader, SwaggerPropertyAnnotationReader $swaggerPropertyAnnotationReader,
PhpdocPropertyAnnotationReader $phpdocPropertyAnnotationReader PhpdocPropertyAnnotationReader $phpdocPropertyAnnotationReader = null
) { ) {
$this->factory = $factory; $this->factory = $factory;
$this->namingStrategy = $namingStrategy; $this->namingStrategy = $namingStrategy;
@ -107,7 +107,9 @@ class JMSModelDescriber implements ModelDescriberInterface, ModelRegistryAwareIn
// read property options from Swagger Property annotation if it exists // read property options from Swagger Property annotation if it exists
if (null !== $item->reflection) { if (null !== $item->reflection) {
$this->phpdocPropertyAnnotationsReader->updateWithPhpdoc($item->reflection, $realProp); if ($this->phpdocPropertyAnnotationsReader) {
$this->phpdocPropertyAnnotationsReader->updateWithPhpdoc($item->reflection, $realProp);
}
$this->swaggerPropertyAnnotationReader->updateWithSwaggerPropertyAnnotation($item->reflection, $realProp); $this->swaggerPropertyAnnotationReader->updateWithSwaggerPropertyAnnotation($item->reflection, $realProp);
} }
} }