Permalink
Browse files

bug #21370 [FrameworkBundle] Execute the PhpDocExtractor earlier (Gui…

…lhemN)

This PR was submitted for the master branch but it was merged into the 2.8 branch instead (closes #21370).

Discussion
----------

[FrameworkBundle] Execute the PhpDocExtractor earlier

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | yes, but safer to apply on master
| New feature?  | no
| BC breaks?    | is changing a priority a bc break?
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #21367
| License       | MIT
| Doc PR        |

Fixes #21367.

> I wonder if this is logical to execute the PhpDocExtractor after the ReflectionExtractor: when you use phpdocs it's because they are more precise than php type hints.
This causes an issue in NelmioApiDocBundle, for example you can't use int[] with a setter as the type mixed[] will be returned instead of int[].
>
> ~~Would you accept bumping its priority to -999?~~

This PR changes the priority of the `ReflectionExtractor` to `-1002` to make sure it is executed after the `PhpDocExtractor`.

Commits
-------

0425e05 [FrameworkBundle] Execute the PhpDocExtractor earlier
  • Loading branch information...
2 parents 5bc83c4 + 0425e05 commit f4693be339960ff9378cdda74b0295fd3ce4eb31 @fabpot fabpot committed Jan 30, 2017
@@ -15,7 +15,7 @@
<!-- Extractor -->
<service id="property_info.reflection_extractor" class="Symfony\Component\PropertyInfo\Extractor\ReflectionExtractor" public="false">
<tag name="property_info.list_extractor" priority="-1000" />
- <tag name="property_info.type_extractor" priority="-1000" />
+ <tag name="property_info.type_extractor" priority="-1002" />
<tag name="property_info.access_extractor" priority="-1000" />
</service>
</services>
@@ -0,0 +1,35 @@
+<?php
+
+/*
+ * This file is part of the Symfony package.
+ *
+ * (c) Fabien Potencier <fabien@symfony.com>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace Symfony\Bundle\FrameworkBundle\Tests\Functional;
+
+use Symfony\Component\PropertyInfo\Type;
+
+class PropertyInfoTest extends WebTestCase
+{
+ public function testPhpDocPriority()
+ {
+ static::bootKernel(array('test_case' => 'Serializer'));
+ $container = static::$kernel->getContainer();
+
+ $this->assertEquals(array(new Type(Type::BUILTIN_TYPE_ARRAY, false, null, true, new Type(Type::BUILTIN_TYPE_INT), new Type(Type::BUILTIN_TYPE_INT))), $container->get('property_info')->getTypes(Dummy::class, 'codes'));
+ }
+}
+
+class Dummy
+{
+ /**
+ * @param int[] $codes
+ */
+ public function setCodes(array $codes)
+ {
+ }
+}

0 comments on commit f4693be

Please sign in to comment.