Migration tool keep variables containing $PHPExcel untouched

Fixes #598
Fixes #609
This commit is contained in:
Andrew Siegman 2018-07-20 11:13:01 -05:00 committed by Adrien Crivelli
parent 048947e390
commit adf95bcc0e
No known key found for this signature in database
GPG Key ID: B182FD79DC6DE92E
2 changed files with 6 additions and 1 deletions

View File

@ -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) - 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) - 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) - 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 ## [1.3.1] - 2018-06-12

View File

@ -204,7 +204,6 @@ class Migrator
'PHPExcel_Settings' => \PhpOffice\PhpSpreadsheet\Settings::class, 'PHPExcel_Settings' => \PhpOffice\PhpSpreadsheet\Settings::class,
'PHPExcel_Style' => \PhpOffice\PhpSpreadsheet\Style\Style::class, 'PHPExcel_Style' => \PhpOffice\PhpSpreadsheet\Style\Style::class,
'PHPExcel_Worksheet' => \PhpOffice\PhpSpreadsheet\Worksheet\Worksheet::class, 'PHPExcel_Worksheet' => \PhpOffice\PhpSpreadsheet\Worksheet\Worksheet::class,
'PHPExcel' => \PhpOffice\PhpSpreadsheet\Spreadsheet::class,
]; ];
$methods = [ $methods = [
@ -272,6 +271,11 @@ class Migrator
$original = file_get_contents($file); $original = file_get_contents($file);
$converted = str_replace($from, $to, $original); $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) { if ($original !== $converted) {
echo $file . " converted\n"; echo $file . " converted\n";
file_put_contents($file, $converted); file_put_contents($file, $converted);