diff --git a/CHANGELOG.md b/CHANGELOG.md index ce6da94e..803f974a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -66,6 +66,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/). - Exclude the vendor folder in migration - [#481](https://github.com/PHPOffice/PhpSpreadsheet/issues/481) - Chained operations on cell ranges involving borders operated on last cell only [#428](https://github.com/PHPOffice/PhpSpreadsheet/issues/428) - Avoid memory exhaustion when cloning worksheet with a drawing [#437](https://github.com/PHPOffice/PhpSpreadsheet/issues/437) +- Migration tool keep variables containing $PHPExcel untouched [#598](https://github.com/PHPOffice/PhpSpreadsheet/issues/598) ## [1.3.1] - 2018-06-12 diff --git a/src/PhpSpreadsheet/Helper/Migrator.php b/src/PhpSpreadsheet/Helper/Migrator.php index 93686626..4eb60633 100644 --- a/src/PhpSpreadsheet/Helper/Migrator.php +++ b/src/PhpSpreadsheet/Helper/Migrator.php @@ -204,7 +204,6 @@ class Migrator '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 = [ @@ -272,6 +271,11 @@ class Migrator $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);