From b9718f3400680eda983eb0829de57fc15fae7fc9 Mon Sep 17 00:00:00 2001 From: Alan Poulain Date: Sat, 1 Jun 2019 15:34:59 +0200 Subject: [PATCH] Compatibility with Symfony 4.3 (#1524) * Use twig instead of templating * Fix at least one suite test in Travis * Use Twig namespace (Twig > 1.10 and TwigBundle > 2.2) --- .travis.yml | 2 ++ DependencyInjection/Configuration.php | 2 +- Formatter/HtmlFormatter.php | 11 ++++++----- Resources/config/formatters.xml | 2 +- Resources/doc/configuration-reference.rst | 2 +- Resources/views/method.html.twig | 2 +- Resources/views/resource.html.twig | 4 ++-- Resources/views/resources.html.twig | 4 ++-- Tests/Formatter/testFormat-result-no-dunglas.markdown | 3 +++ Tests/Formatter/testFormat-result.markdown | 3 +++ 10 files changed, 22 insertions(+), 13 deletions(-) diff --git a/.travis.yml b/.travis.yml index 37fdc85..3f69eaa 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,3 +1,5 @@ +dist: trusty + language: php sudo: false diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php index 2baac26..c71e330 100644 --- a/DependencyInjection/Configuration.php +++ b/DependencyInjection/Configuration.php @@ -31,7 +31,7 @@ class Configuration implements ConfigurationInterface ->arrayNode('motd') ->addDefaultsIfNotSet() ->children() - ->scalarNode('template')->defaultValue('NelmioApiDocBundle::Components/motd.html.twig')->end() + ->scalarNode('template')->defaultValue('@NelmioApiDoc/Components/motd.html.twig')->end() ->end() ->end() ->arrayNode('request_listener') diff --git a/Formatter/HtmlFormatter.php b/Formatter/HtmlFormatter.php index 94ab16f..ec2c90c 100644 --- a/Formatter/HtmlFormatter.php +++ b/Formatter/HtmlFormatter.php @@ -12,6 +12,7 @@ namespace Nelmio\ApiDocBundle\Formatter; use Symfony\Component\Templating\EngineInterface; +use Twig\Environment as TwigEnvironment; class HtmlFormatter extends AbstractFormatter { @@ -31,7 +32,7 @@ class HtmlFormatter extends AbstractFormatter protected $defaultRequestFormat; /** - * @var EngineInterface + * @var EngineInterface|TwigEnvironment */ protected $engine; @@ -113,9 +114,9 @@ class HtmlFormatter extends AbstractFormatter } /** - * @param EngineInterface $engine + * @param EngineInterface|TwigEnvironment $engine */ - public function setTemplatingEngine(EngineInterface $engine) + public function setTemplatingEngine($engine) { $this->engine = $engine; } @@ -197,7 +198,7 @@ class HtmlFormatter extends AbstractFormatter */ protected function renderOne(array $data) { - return $this->engine->render('NelmioApiDocBundle::resource.html.twig', array_merge( + return $this->engine->render('@NelmioApiDoc/resource.html.twig', array_merge( array( 'data' => $data, 'displayContent' => true, @@ -211,7 +212,7 @@ class HtmlFormatter extends AbstractFormatter */ protected function render(array $collection) { - return $this->engine->render('NelmioApiDocBundle::resources.html.twig', array_merge( + return $this->engine->render('@NelmioApiDoc/resources.html.twig', array_merge( array( 'resources' => $collection, ), diff --git a/Resources/config/formatters.xml b/Resources/config/formatters.xml index 9d55d21..54f5eb5 100644 --- a/Resources/config/formatters.xml +++ b/Resources/config/formatters.xml @@ -21,7 +21,7 @@ - + %nelmio_api_doc.motd.template% diff --git a/Resources/doc/configuration-reference.rst b/Resources/doc/configuration-reference.rst index a4cbddb..d72ba35 100644 --- a/Resources/doc/configuration-reference.rst +++ b/Resources/doc/configuration-reference.rst @@ -8,7 +8,7 @@ Configuration Reference exclude_sections: [] default_sections_opened: true motd: - template: 'NelmioApiDocBundle::Components/motd.html.twig' + template: '@NelmioApiDoc/Components/motd.html.twig' request_listener: enabled: true parameter: _doc diff --git a/Resources/views/method.html.twig b/Resources/views/method.html.twig index 54fafeb..25fdd84 100644 --- a/Resources/views/method.html.twig +++ b/Resources/views/method.html.twig @@ -189,7 +189,7 @@ {{ name }} {{ infos.dataType }} - {% include 'NelmioApiDocBundle:Components:version.html.twig' with {'sinceVersion': infos.sinceVersion, 'untilVersion': infos.untilVersion} only %} + {% include '@NelmioApiDoc/Components/version.html.twig' with {'sinceVersion': infos.sinceVersion, 'untilVersion': infos.untilVersion} only %} {{ infos.description }} {% endfor %} diff --git a/Resources/views/resource.html.twig b/Resources/views/resource.html.twig index 1a51099..07230e2 100644 --- a/Resources/views/resource.html.twig +++ b/Resources/views/resource.html.twig @@ -1,11 +1,11 @@ -{% extends "NelmioApiDocBundle::layout.html.twig" %} +{% extends "@NelmioApiDoc/layout.html.twig" %} {% block content %}
      • - {% include 'NelmioApiDocBundle::method.html.twig' %} + {% include '@NelmioApiDoc/method.html.twig' %}
    diff --git a/Resources/views/resources.html.twig b/Resources/views/resources.html.twig index 997153d..a6d2ca7 100644 --- a/Resources/views/resources.html.twig +++ b/Resources/views/resources.html.twig @@ -1,4 +1,4 @@ -{% extends "NelmioApiDocBundle::layout.html.twig" %} +{% extends "@NelmioApiDoc/layout.html.twig" %} {% block content %}
    @@ -33,7 +33,7 @@
    • {% for data in methods %} - {% include 'NelmioApiDocBundle::method.html.twig' %} + {% include '@NelmioApiDoc/method.html.twig' %} {% endfor %}
  • diff --git a/Tests/Formatter/testFormat-result-no-dunglas.markdown b/Tests/Formatter/testFormat-result-no-dunglas.markdown index 5739788..281df3f 100644 --- a/Tests/Formatter/testFormat-result-no-dunglas.markdown +++ b/Tests/Formatter/testFormat-result-no-dunglas.markdown @@ -622,6 +622,9 @@ dependency_type[a]: _This method is useful to test if the getDocComment works._ +This method is useful to test if the getDocComment works. +And, it supports multilines until the first '@' char. + #### Requirements #### **id** diff --git a/Tests/Formatter/testFormat-result.markdown b/Tests/Formatter/testFormat-result.markdown index cf3f8d9..2c16f07 100644 --- a/Tests/Formatter/testFormat-result.markdown +++ b/Tests/Formatter/testFormat-result.markdown @@ -706,6 +706,9 @@ dependency_type[a]: _This method is useful to test if the getDocComment works._ +This method is useful to test if the getDocComment works. +And, it supports multilines until the first '@' char. + #### Requirements #### **id**