Skip to content

Commit

Permalink
Migration tool keep variables containing $PHPExcel untouched
Browse files Browse the repository at this point in the history
Fixes #598
Fixes #609
  • Loading branch information
blunket authored and PowerKiKi committed Aug 5, 2018
1 parent 048947e commit adf95bc
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
6 changes: 5 additions & 1 deletion 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 @@ -272,6 +271,11 @@ private function recursiveReplace($path)
$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 adf95bc

Please sign in to comment.