@@ -98,15 +98,32 @@ public function getProtoNamespaces(): array
9898 $ contents ,
9999 $ matches
100100 ) && preg_match ('/namespace (.*);/ ' , $ contents , $ nsMatches )) {
101- // remove namespace (in case it's nested)
102- $ protoPackages [$ matches [1 ]] = str_replace (
103- str_replace ('. ' , '\\' , substr ($ matches [2 ], 0 , strrpos ($ matches [2 ], '. ' ))),
104- '' ,
105- $ nsMatches [1 ]
106- );
101+ $ protoNs = $ nsMatches [1 ];
102+ // remove nested namespaces
103+ if ($ nestedNs = str_replace ('. ' , '\\' , substr ($ matches [2 ], 0 , strrpos ($ matches [2 ], '. ' )))) {
104+ $ nestedNsPos = strrpos ($ protoNs , $ nestedNs );
105+ if (false === $ nestedNsPos ) {
106+ // this should only occur for "keywords" in PHP needing to be prefixed by "PB" (e.g. `PBString`)
107+ if (false === strpos ($ protoNs , '\\PB ' )) {
108+ throw new \Exception (sprintf ('Unexpected namespace found in %s: %s ' , $ protoNs , $ nestedNs ));
109+ }
110+ continue ; // skip this classs - use the others in the component instead
111+ }
112+ $ protoNs = substr_replace ($ protoNs , '' , $ nestedNsPos , strlen ($ nestedNs ));
113+ if (isset ($ protoPackages [$ matches [1 ]]) && $ protoPackages [$ matches [1 ]] !== $ protoNs ) {
114+ throw new \Exception (sprintf (
115+ 'Differing namespaces for "%s": %s and %s ' ,
116+ $ matches [1 ],
117+ $ protoPackages [$ matches [1 ]],
118+ $ protoNs
119+ ));
120+ }
121+ }
122+ $ protoPackages [$ matches [1 ]] = $ protoNs ;
107123 }
108124 }
109- return array_unique ($ protoPackages );
125+
126+ return $ protoPackages ;
110127 }
111128
112129 public function getBaseUri (): string
0 commit comments