| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | /* | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  * This file is part of the PHP Translation package. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  |  * (c) PHP Translation team <[email protected]> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  |  * For the full copyright and license information, please view the LICENSE | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  |  * file that was distributed with this source code. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  | namespace Translation\Extractor\FileExtractor; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  | use Symfony\Component\Finder\SplFileInfo; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  | use Translation\Extractor\Model\SourceCollection; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  | use Translation\Extractor\Model\SourceLocation; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |  * @author Tobias Nyholm <[email protected]> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  | class BladeFileExtractor implements FileExtractor | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 | 3 |  |     public function getSourceLocations(SplFileInfo $file, SourceCollection $collection) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 | 3 |  |         $realPath = $file->getRealPath(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 | 3 |  |         $messages = $this->findTranslations($file); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 | 3 |  |         foreach ($messages as $message) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 | 3 |  |             $collection->addLocation(new SourceLocation($message, $realPath, 0)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 | 3 |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 | 3 |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |      * @author uusa35 and contributors to {@link https://github.com/barryvdh/laravel-translation-manager} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |      * @param SplFileInfo $file | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |      * @return string[] | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 38 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 39 | 3 |  |     public function findTranslations(SplFileInfo $file) | 
            
                                                                        
                            
            
                                    
            
            
                | 40 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 41 | 3 |  |         $keys = []; | 
            
                                                                        
                            
            
                                    
            
            
                | 42 | 3 |  |         $functions = ['trans', 'trans_choice', 'Lang::get', 'Lang::choice', 'Lang::trans', 'Lang::transChoice', '@lang', '@choice']; | 
            
                                                                        
                            
            
                                    
            
            
                | 43 |  |  |         $pattern = // See http://regexr.com/392hu | 
            
                                                                        
                            
            
                                    
            
            
                | 44 |  |  |             "[^\w|>]".// Must not have an alphanum or _ or > before real method | 
            
                                                                        
                            
            
                                    
            
            
                | 45 | 3 |  |             '('.implode('|', $functions).')'.// Must start with one of the functions | 
            
                                                                        
                            
            
                                    
            
            
                | 46 | 3 |  |             "\(".// Match opening parenthese | 
            
                                                                        
                            
            
                                    
            
            
                | 47 | 3 |  |             "[\'\"]".// Match " or ' | 
            
                                                                        
                            
            
                                    
            
            
                | 48 | 3 |  |             '('.// Start a new group to match: | 
            
                                                                        
                            
            
                                    
            
            
                | 49 | 3 |  |             '[a-zA-Z0-9_-]+'.// Must start with group | 
            
                                                                        
                            
            
                                    
            
            
                | 50 | 3 |  |             '([.][^\\1)]+)+'.// Be followed by one or more items/keys | 
            
                                                                        
                            
            
                                    
            
            
                | 51 | 3 |  |             ')'.// Close group | 
            
                                                                        
                            
            
                                    
            
            
                | 52 | 3 |  |             "[\'\"]".// Closing quote | 
            
                                                                        
                            
            
                                    
            
            
                | 53 | 3 |  |             "[\),]";                            // Close parentheses or new parameter | 
            
                                                                        
                            
            
                                    
            
            
                | 54 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 55 |  |  |         // Search the current file for the pattern | 
            
                                                                        
                            
            
                                    
            
            
                | 56 | 3 |  |         if (preg_match_all("/$pattern/siU", $file->getContents(), $matches)) { | 
            
                                                                        
                            
            
                                    
            
            
                | 57 |  |  |             // Get all matches | 
            
                                                                        
                            
            
                                    
            
            
                | 58 | 3 |  |             foreach ($matches[2] as $key) { | 
            
                                                                        
                            
            
                                    
            
            
                | 59 | 3 |  |                 $keys[] = $key; | 
            
                                                                        
                            
            
                                    
            
            
                | 60 | 3 |  |             } | 
            
                                                                        
                            
            
                                    
            
            
                | 61 | 3 |  |         } | 
            
                                                                        
                            
            
                                    
            
            
                | 62 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 63 | 3 |  |         return $keys; | 
            
                                                                        
                            
            
                                    
            
            
                | 64 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |     public function getType() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |         return 'blade'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 70 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 71 |  |  |  |