Skip to content

Instantly share code, notes, and snippets.

@spudro228
Created February 8, 2019 10:08
Show Gist options
  • Save spudro228/f6292ddb28a6aebd6fe23832763e1830 to your computer and use it in GitHub Desktop.
Save spudro228/f6292ddb28a6aebd6fe23832763e1830 to your computer and use it in GitHub Desktop.
<?php
declare(strict_types=1);
use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\Finder\Finder;
require_once 'vendor/autoload.php';
$fileSystem = new FileSystem();
$finder = new Finder();
$finder->files()->in(__DIR__ . '/src');
$re = '/((protected|public)\s+\$baseUrl\s+=\s+\'(?<url>[\/\w+]+)\');/m';
foreach ($finder as $fileInfo) {
if ($fileInfo->getExtension() !== 'php') {
continue;
}
\preg_match_all($re, $fileInfo->getContents(), $matches, PREG_SET_ORDER, 0);
if (\count($matches) === 0) {
continue;
}
$basePath = $matches[0]['url'];
$newContent = \preg_replace('/(\$this->baseUrl)/m', '\'' . $basePath . '\'', $fileInfo->getContents());
$newContent = \preg_replace($re, '', $newContent);
echo $fileInfo->getRealPath() . ' --- ' . $basePath . \PHP_EOL;
$fileObject = $fileInfo->openFile('wb');
$fileObject->fwrite($newContent);
// echo $newContent . PHP_EOL;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment