1 | <?php |
||
2 | |||
3 | declare(strict_types=1); |
||
4 | |||
5 | /* |
||
6 | * This file is part of the humbug/php-scoper package. |
||
7 | * |
||
8 | * Copyright (c) 2017 Théo FIDRY <[email protected]>, |
||
9 | * Pádraic Brady <[email protected]> |
||
10 | * |
||
11 | * For the full copyright and license information, please view the LICENSE |
||
12 | * file that was distributed with this source code. |
||
13 | */ |
||
14 | |||
15 | namespace Humbug\PhpScoper\Patcher; |
||
16 | |||
17 | use function Safe\preg_replace; |
||
18 | use function Safe\sprintf; |
||
19 | use function strpos; |
||
20 | |||
21 | final class SymfonyPatcher implements Patcher |
||
22 | { |
||
23 | private const PATHS = [ |
||
24 | 'src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php', |
||
25 | 'symfony/dependency-injection/Dumper/PhpDumper.php', |
||
26 | ]; |
||
27 | 21 | ||
28 | public function __invoke(string $filePath, string $prefix, string $contents): string |
||
29 | 21 | { |
|
30 | 9 | if (!self::isSupportedFile($filePath)) { |
|
31 | return $contents; |
||
32 | } |
||
33 | 12 | ||
34 | 12 | return (string) preg_replace( |
|
35 | 12 | '/use (Symfony(\\\\(?:\\\\)?)Component\\\\.+?;)/', |
|
36 | 12 | sprintf( |
|
0 ignored issues
–
show
|
|||
37 | 12 | 'use %s$2$1', |
|
38 | $prefix, |
||
39 | 12 | ), |
|
40 | $contents, |
||
41 | ); |
||
42 | } |
||
43 | 21 | ||
44 | private static function isSupportedFile(string $filePath): bool |
||
45 | 21 | { |
|
46 | 21 | foreach (self::PATHS as $path) { |
|
47 | 12 | if (false !== strpos($filePath, $path)) { |
|
48 | return true; |
||
49 | } |
||
50 | } |
||
51 | 9 | ||
52 | return false; |
||
53 | } |
||
54 | } |
||
55 |
This function has been deprecated. The supplier of the function has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.