@@ -81,7 +81,7 @@ public function extract($resource, MessageCatalogue $catalog)
81
81
{
82
82
$ files = $ this ->extractFiles ($ resource );
83
83
foreach ($ files as $ file ) {
84
- $ this ->parseTokens (token_get_all (file_get_contents ($ file )), $ catalog );
84
+ $ this ->parseTokens (token_get_all (file_get_contents ($ file )), $ catalog, $ file );
85
85
86
86
gc_mem_caches ();
87
87
}
@@ -197,9 +197,15 @@ private function getValue(\Iterator $tokenIterator)
197
197
*
198
198
* @param array $tokens
199
199
* @param MessageCatalogue $catalog
200
+ * @param string $filename
200
201
*/
201
- protected function parseTokens ($ tokens , MessageCatalogue $ catalog )
202
+ protected function parseTokens ($ tokens , MessageCatalogue $ catalog/*, string $filename*/ )
202
203
{
204
+ if (\func_num_args () < 3 && __CLASS__ !== \get_class ($ this ) && __CLASS__ !== (new \ReflectionMethod ($ this , __FUNCTION__ ))->getDeclaringClass ()->getName () && !$ this instanceof \PHPUnit \Framework \MockObject \MockObject && !$ this instanceof \Prophecy \Prophecy \ProphecySubjectInterface) {
205
+ @trigger_error (sprintf ('The "%s()" method will have a new "string $filename" argument in version 5.0, not defining it is deprecated since Symfony 4.3. ' , __METHOD__ ), E_USER_DEPRECATED );
206
+ }
207
+ $ filename = 2 < \func_num_args () ? \func_get_arg (2 ) : '' ;
208
+
203
209
$ tokenIterator = new \ArrayIterator ($ tokens );
204
210
205
211
for ($ key = 0 ; $ key < $ tokenIterator ->count (); ++$ key ) {
@@ -236,6 +242,10 @@ protected function parseTokens($tokens, MessageCatalogue $catalog)
236
242
237
243
if ($ message ) {
238
244
$ catalog ->set ($ message , $ this ->prefix .$ message , $ domain );
245
+ $ metadata = $ catalog ->getMetadata ($ message , $ domain ) ?? [];
246
+ $ normalizedFilename = preg_replace ('{[ \\\\/]+} ' , '/ ' , $ filename );
247
+ $ metadata ['sources ' ][] = $ normalizedFilename .': ' .$ tokens [$ key ][2 ];
248
+ $ catalog ->setMetadata ($ message , $ metadata , $ domain );
239
249
break ;
240
250
}
241
251
}
0 commit comments