From 870d8640f525bc282bfa7908c994483342f4f9a0 Mon Sep 17 00:00:00 2001 From: Adrien Crivelli Date: Fri, 21 Apr 2017 14:46:17 +0900 Subject: [PATCH] Enforce writer parts parent to be concrete writer We used to type hint against IWriter for writer part parent, but this was not respected in writer part who often coded against the implementation instead of the interface. With this change we make it a requirement for writer parts to use their respective writer implementation instead of an interface. This give legitimate access to all `BaseWriter` methods amongst other things. --- src/PhpSpreadsheet/Writer/Ods/WriterPart.php | 30 ++++++++++++++++- src/PhpSpreadsheet/Writer/Xlsx/WriterPart.php | 33 +++++-------------- 2 files changed, 37 insertions(+), 26 deletions(-) diff --git a/src/PhpSpreadsheet/Writer/Ods/WriterPart.php b/src/PhpSpreadsheet/Writer/Ods/WriterPart.php index dee7532c..b07b38cb 100644 --- a/src/PhpSpreadsheet/Writer/Ods/WriterPart.php +++ b/src/PhpSpreadsheet/Writer/Ods/WriterPart.php @@ -24,6 +24,34 @@ namespace PhpOffice\PhpSpreadsheet\Writer\Ods; * @copyright Copyright (c) 2006 - 2015 PhpSpreadsheet (https://github.com/PHPOffice/PhpSpreadsheet) * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL */ -abstract class WriterPart extends \PhpOffice\PhpSpreadsheet\Writer\Xlsx\WriterPart +abstract class WriterPart { + /** + * Parent Ods object. + * + * @var \PhpOffice\PhpSpreadsheet\Writer\Ods + */ + private $parentWriter; + + /** + * Get Ods writer. + * + * @throws \PhpOffice\PhpSpreadsheet\Writer\Exception + * + * @return \PhpOffice\PhpSpreadsheet\Writer\Ods + */ + public function getParentWriter() + { + return $this->parentWriter; + } + + /** + * Set parent Ods writer. + * + * @param \PhpOffice\PhpSpreadsheet\Writer\Ods $writer + */ + public function __construct(\PhpOffice\PhpSpreadsheet\Writer\Ods $writer) + { + $this->parentWriter = $writer; + } } diff --git a/src/PhpSpreadsheet/Writer/Xlsx/WriterPart.php b/src/PhpSpreadsheet/Writer/Xlsx/WriterPart.php index 881683db..a743ab12 100644 --- a/src/PhpSpreadsheet/Writer/Xlsx/WriterPart.php +++ b/src/PhpSpreadsheet/Writer/Xlsx/WriterPart.php @@ -27,47 +27,30 @@ namespace PhpOffice\PhpSpreadsheet\Writer\Xlsx; abstract class WriterPart { /** - * Parent IWriter object. + * Parent Xlsx object. * - * @var \PhpOffice\PhpSpreadsheet\Writer\IWriter + * @var \PhpOffice\PhpSpreadsheet\Writer\Xlsx */ private $parentWriter; /** - * Set parent IWriter object. - * - * @param \PhpOffice\PhpSpreadsheet\Writer\IWriter $pWriter - * - * @throws \PhpOffice\PhpSpreadsheet\Writer\Exception - */ - public function setParentWriter(\PhpOffice\PhpSpreadsheet\Writer\IWriter $pWriter) - { - $this->parentWriter = $pWriter; - } - - /** - * Get parent IWriter object. + * Get parent Xlsx object. * * @throws \PhpOffice\PhpSpreadsheet\Writer\Exception * - * @return \PhpOffice\PhpSpreadsheet\Writer\IWriter + * @return \PhpOffice\PhpSpreadsheet\Writer\Xlsx */ public function getParentWriter() { - if (!is_null($this->parentWriter)) { - return $this->parentWriter; - } - throw new \PhpOffice\PhpSpreadsheet\Writer\Exception('No parent \\PhpOffice\\PhpSpreadsheet\\Writer\\IWriter assigned.'); + return $this->parentWriter; } /** - * Set parent IWriter object. + * Set parent Xlsx object. * - * @param \PhpOffice\PhpSpreadsheet\Writer\IWriter $pWriter - * - * @throws \PhpOffice\PhpSpreadsheet\Writer\Exception + * @param \PhpOffice\PhpSpreadsheet\Writer\Xlsx $pWriter */ - public function __construct(\PhpOffice\PhpSpreadsheet\Writer\IWriter $pWriter) + public function __construct(\PhpOffice\PhpSpreadsheet\Writer\Xlsx $pWriter) { $this->parentWriter = $pWriter; }