Skip to content

Commit

Permalink
careful treatment of string PHPExcel in migrator
Browse files Browse the repository at this point in the history
  • Loading branch information
blunket committed Jul 20, 2018
1 parent 3028c60 commit 0ddab94
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/PhpSpreadsheet/Helper/Migrator.php
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,6 @@ public function getMapping()
'PHPExcel_Settings' => \PhpOffice\PhpSpreadsheet\Settings::class,
'PHPExcel_Style' => \PhpOffice\PhpSpreadsheet\Style\Style::class,
'PHPExcel_Worksheet' => \PhpOffice\PhpSpreadsheet\Worksheet\Worksheet::class,
'PHPExcel' => \PhpOffice\PhpSpreadsheet\Spreadsheet::class,
];

$methods = [
Expand Down Expand Up @@ -266,12 +265,16 @@ private function recursiveReplace($path)
foreach (glob($path . $pattern) as $file) {
if (strpos($path, '/vendor/') !== false) {
echo $file . " skipped\n";

continue;
}
$original = file_get_contents($file);
$converted = str_replace($from, $to, $original);

// The string "PHPExcel" gets special treatment because of how common it might be.
// This regex requires a word boundary around the string, and it can't be
// preceded by $ or -> (goal is to filter out cases where a variable is named $PHPExcel or similar)
$converted = preg_replace('/(?<!\$|->)\bPHPExcel\b/', \PhpOffice\PhpSpreadsheet\Spreadsheet::class, $original);

if ($original !== $converted) {
echo $file . " converted\n";
file_put_contents($file, $converted);
Expand Down

0 comments on commit 0ddab94

Please sign in to comment.