Created
February 8, 2019 10:08
-
-
Save spudro228/f6292ddb28a6aebd6fe23832763e1830 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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