for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
declare(strict_types=1);
/*
* This file is part of the humbug/php-scoper package.
*
* Copyright (c) 2017 Théo FIDRY <[email protected]>,
* Pádraic Brady <[email protected]>
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Humbug\PhpScoper\Patcher;
use function Safe\preg_replace;
use function Safe\sprintf;
use function strpos;
final class SymfonyPatcher
{
private const PATHS = [
'src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php',
'symfony/dependency-injection/Dumper/PhpDumper.php',
];
public function __invoke(string $filePath, string $prefix, string $contents): string
if (!self::isSupportedFile($filePath)) {
return $contents;
}
return (string) preg_replace(
'/use (Symfony(\\\\(?:\\\\)?)Component\\\\.+?;)/',
sprintf(
'use %s$2$1',
$prefix
),
$contents
);
private static function isSupportedFile(string $filePath): bool
foreach (self::PATHS as $path) {
if (false !== strpos($filePath, $path)) {
return true;
return false;