File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 44
55namespace BowlOfSoup \NormalizerBundle \Service \Extractor ;
66
7+ use Doctrine \Persistence \Proxy ;
8+
79class MethodExtractor extends AbstractExtractor
810{
911 /** @var string */
@@ -13,11 +15,21 @@ class MethodExtractor extends AbstractExtractor
1315 * Extract all annotations for a (reflected) class method.
1416 *
1517 * @param string|object $annotation
18+ *
19+ * @throws \ReflectionException
1620 */
1721 public function extractMethodAnnotations (\ReflectionMethod $ objectMethod , $ annotation ): array
1822 {
1923 $ annotations = [];
2024
25+ if ($ objectMethod ->getDeclaringClass ()->implementsInterface (Proxy::class)
26+ && false !== $ objectMethod ->getDeclaringClass ()->getParentClass ()
27+ && empty ($ this ->annotationReader ->getMethodAnnotations ($ objectMethod ))
28+ && $ objectMethod ->getDeclaringClass ()->getParentClass ()->hasMethod ($ objectMethod ->getName ())
29+ ) {
30+ $ objectMethod = $ objectMethod ->getDeclaringClass ()->getParentClass ()->getMethod ($ objectMethod ->getName ());
31+ }
32+
2133 $ methodAnnotations = $ this ->annotationReader ->getMethodAnnotations ($ objectMethod );
2234 foreach ($ methodAnnotations as $ methodAnnotation ) {
2335 if ($ methodAnnotation instanceof $ annotation ) {
Original file line number Diff line number Diff line change @@ -63,6 +63,9 @@ public function normalize(
6363 return $ normalizedMethods ;
6464 }
6565
66+ /**
67+ * @throws \ReflectionException
68+ */
6669 private function getMethodAnnotations (string $ objectName , \ReflectionMethod $ classMethod , string $ annotationClass ): array
6770 {
6871 $ methodName = $ classMethod ->getName ();
Original file line number Diff line number Diff line change 1111use BowlOfSoup \NormalizerBundle \Tests \assets \HobbyType ;
1212use BowlOfSoup \NormalizerBundle \Tests \assets \Person ;
1313use BowlOfSoup \NormalizerBundle \Tests \assets \ProxyObject ;
14+ use BowlOfSoup \NormalizerBundle \Tests \assets \ProxySocial ;
1415use BowlOfSoup \NormalizerBundle \Tests \assets \Social ;
1516use BowlOfSoup \NormalizerBundle \Tests \assets \SomeClass ;
1617use BowlOfSoup \NormalizerBundle \Tests \assets \TelephoneNumbers ;
@@ -489,6 +490,16 @@ public function testNormalizeWithTranslation(): void
489490 ], $ result );
490491 }
491492
493+ public function testNormalizeProxyWithMethods (): void
494+ {
495+ $ socialProxy = new ProxySocial ();
496+ $ socialProxy ->setFacebook ('foo ' );
497+
498+ $ this ->assertSame ([
499+ 'facebook ' => 'foo '
500+ ], $ this ->normalizer ->normalize ($ socialProxy , 'proxy-method ' ));
501+ }
502+
492503 private function getDummyDataSet (): Person
493504 {
494505 $ groupCollection = new ArrayCollection ();
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ declare (strict_types=1 );
4+
5+ namespace BowlOfSoup \NormalizerBundle \Tests \assets ;
6+
7+ use Doctrine \Common \Persistence \Proxy ;
8+
9+ class ProxySocial extends Social implements Proxy
10+ {
11+ /**
12+ * {@inheritdoc}
13+ */
14+ public function __load ()
15+ {
16+ }
17+
18+ /**
19+ * {@inheritdoc}
20+ */
21+ public function __isInitialized ()
22+ {
23+ }
24+
25+ /**
26+ * {@inheritdoc}
27+ */
28+ public function getFacebook ()
29+ {
30+ return parent ::getFacebook ();
31+ }
32+ }
Original file line number Diff line number Diff line change @@ -71,6 +71,8 @@ public function setId($id)
7171
7272 /**
7373 * @return string
74+ *
75+ * @Bos\Normalize(name="facebook", group={"proxy-method"})
7476 */
7577 public function getFacebook ()
7678 {
You can’t perform that action at this time.
0 commit comments