Merge pull request #1161 from dbu/phpdocumentor-soft-dependency

do not fail if phpdocumentor is not available
This commit is contained in:
Guilhem N 2017-12-29 14:13:08 +01:00 committed by GitHub
commit 3fa79bd2b2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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
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)
->setPublic(false)
->setArguments([
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'),
])
->setArguments($arguments)
->addTag('nelmio_api_doc.model_describer', ['priority' => 50]);
}

View File

@ -41,7 +41,7 @@ class JMSModelDescriber implements ModelDescriberInterface, ModelRegistryAwareIn
MetadataFactoryInterface $factory,
PropertyNamingStrategyInterface $namingStrategy,
SwaggerPropertyAnnotationReader $swaggerPropertyAnnotationReader,
PhpdocPropertyAnnotationReader $phpdocPropertyAnnotationReader
PhpdocPropertyAnnotationReader $phpdocPropertyAnnotationReader = null
) {
$this->factory = $factory;
$this->namingStrategy = $namingStrategy;
@ -107,7 +107,9 @@ class JMSModelDescriber implements ModelDescriberInterface, ModelRegistryAwareIn
// read property options from Swagger Property annotation if it exists
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);
}
}