From fff363078078753a2092b7e945514642309bccdc Mon Sep 17 00:00:00 2001 From: Adrien Crivelli Date: Mon, 25 Dec 2017 10:49:14 +0900 Subject: [PATCH] Support migration of prefixed classes --- docs/topics/migration-from-PHPExcel.md | 2 +- src/PhpSpreadsheet/Cell/Cell.php | 2 -- src/PhpSpreadsheet/Helper/Migrator.php | 27 ++++++++++++++++++++++++-- 3 files changed, 26 insertions(+), 5 deletions(-) diff --git a/docs/topics/migration-from-PHPExcel.md b/docs/topics/migration-from-PHPExcel.md index cb0025d6..7433741c 100644 --- a/docs/topics/migration-from-PHPExcel.md +++ b/docs/topics/migration-from-PHPExcel.md @@ -176,7 +176,7 @@ and are replaced by `IOFactory::registerWriter()` instead: - `PHPExcel_Settings::getPdfRenderer()` - `PHPExcel_Settings::setPdfRenderer()` - `PHPExcel_Settings::getPdfRendererName()` -- `PHPExcel_Settings::setPdfRendererName()` were renamed as `setDefaultPdfWriter()` +- `PHPExcel_Settings::setPdfRendererName()` Before: diff --git a/src/PhpSpreadsheet/Cell/Cell.php b/src/PhpSpreadsheet/Cell/Cell.php index fdf9815a..62cf4cfa 100644 --- a/src/PhpSpreadsheet/Cell/Cell.php +++ b/src/PhpSpreadsheet/Cell/Cell.php @@ -618,8 +618,6 @@ class Cell * Set value binder to use. * * @param IValueBinder $binder - * - * @throws Exception */ public static function setValueBinder(IValueBinder $binder) { diff --git a/src/PhpSpreadsheet/Helper/Migrator.php b/src/PhpSpreadsheet/Helper/Migrator.php index 6b2883a1..b6d5f2a6 100644 --- a/src/PhpSpreadsheet/Helper/Migrator.php +++ b/src/PhpSpreadsheet/Helper/Migrator.php @@ -12,7 +12,7 @@ class Migrator public function getMapping() { // Order matters here, we should have the deepest namespaces first (the most "unique" strings) - $mapping = [ + $classes = [ 'PHPExcel_Shared_Escher_DggContainer_BstoreContainer_BSE_Blip' => \PhpOffice\PhpSpreadsheet\Shared\Escher\DggContainer\BstoreContainer\BSE\Blip::class, 'PHPExcel_Shared_Escher_DgContainer_SpgrContainer_SpContainer' => \PhpOffice\PhpSpreadsheet\Shared\Escher\DgContainer\SpgrContainer\SpContainer::class, 'PHPExcel_Shared_Escher_DggContainer_BstoreContainer_BSE' => \PhpOffice\PhpSpreadsheet\Shared\Escher\DggContainer\BstoreContainer\BSE::class, @@ -205,7 +205,9 @@ class Migrator 'PHPExcel_Style' => \PhpOffice\PhpSpreadsheet\Style\Style::class, 'PHPExcel_Worksheet' => \PhpOffice\PhpSpreadsheet\Worksheet\Worksheet::class, 'PHPExcel' => \PhpOffice\PhpSpreadsheet\Spreadsheet::class, - // methods + ]; + + $methods = [ 'MINUTEOFHOUR' => 'MINUTE', 'SECONDOFMINUTE' => 'SECOND', 'DAYOFWEEK' => 'WEEKDAY', @@ -213,8 +215,28 @@ class Migrator 'ExcelToPHPObject' => 'excelToDateTimeObject', 'ExcelToPHP' => 'excelToTimestamp', 'FormattedPHPToExcel' => 'formattedPHPToExcel', + 'Cell::absoluteCoordinate' => 'Coordinate::absoluteCoordinate', + 'Cell::absoluteReference' => 'Coordinate::absoluteReference', + 'Cell::buildRange' => 'Coordinate::buildRange', + 'Cell::columnIndexFromString' => 'Coordinate::columnIndexFromString', + 'Cell::coordinateFromString' => 'Coordinate::coordinateFromString', + 'Cell::extractAllCellReferencesInRange' => 'Coordinate::extractAllCellReferencesInRange', + 'Cell::getRangeBoundaries' => 'Coordinate::getRangeBoundaries', + 'Cell::mergeRangesInCollection' => 'Coordinate::mergeRangesInCollection', + 'Cell::rangeBoundaries' => 'Coordinate::rangeBoundaries', + 'Cell::rangeDimension' => 'Coordinate::rangeDimension', + 'Cell::splitRange' => 'Coordinate::splitRange', + 'Cell::stringFromColumnIndex' => 'Coordinate::stringFromColumnIndex', ]; + // Keep '\' prefix for class names + $prefixedClasses = []; + foreach ($classes as $key => &$value) { + $value = str_replace('PhpOffice\\', '\\PhpOffice\\', $value); + $prefixedClasses['\\' . $key] = $value; + } + $mapping = $prefixedClasses + $classes + $methods; + return $mapping; } @@ -228,6 +250,7 @@ class Migrator $patterns = [ '/*.md', '/*.php', + '/*.phtml', '/*.txt', '/*.TXT', ];