Skip to content

Commit adf95bc

Browse files
blunketPowerKiKi
authored andcommitted
Migration tool keep variables containing $PHPExcel untouched
Fixes #598 Fixes #609
1 parent 048947e commit adf95bc

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
6666
- Exclude the vendor folder in migration - [#481](https://github.com/PHPOffice/PhpSpreadsheet/issues/481)
6767
- Chained operations on cell ranges involving borders operated on last cell only [#428](https://github.com/PHPOffice/PhpSpreadsheet/issues/428)
6868
- Avoid memory exhaustion when cloning worksheet with a drawing [#437](https://github.com/PHPOffice/PhpSpreadsheet/issues/437)
69+
- Migration tool keep variables containing $PHPExcel untouched [#598](https://github.com/PHPOffice/PhpSpreadsheet/issues/598)
6970

7071
## [1.3.1] - 2018-06-12
7172

src/PhpSpreadsheet/Helper/Migrator.php

+5-1
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,6 @@ public function getMapping()
204204
'PHPExcel_Settings' => \PhpOffice\PhpSpreadsheet\Settings::class,
205205
'PHPExcel_Style' => \PhpOffice\PhpSpreadsheet\Style\Style::class,
206206
'PHPExcel_Worksheet' => \PhpOffice\PhpSpreadsheet\Worksheet\Worksheet::class,
207-
'PHPExcel' => \PhpOffice\PhpSpreadsheet\Spreadsheet::class,
208207
];
209208

210209
$methods = [
@@ -272,6 +271,11 @@ private function recursiveReplace($path)
272271
$original = file_get_contents($file);
273272
$converted = str_replace($from, $to, $original);
274273

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

0 commit comments

Comments
 (0)