Skip to content

Commit 400a8e6

Browse files
SailorMaxtroosan
authored andcommitted
rename 'Object' classes to 'ObjectElement' (php 7.2 compatibility) (#1185)
merge develop branch
1 parent 709ea1e commit 400a8e6

File tree

10 files changed

+34
-25
lines changed

10 files changed

+34
-25
lines changed

.travis.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@ matrix:
1616
- php: 5.6
1717
env: COVERAGE=1
1818
allow_failures:
19+
<<<<<<< HEAD
20+
=======
21+
- php: 7.0
22+
- php: 7.1
23+
>>>>>>> branch 'php72_support_object_classes' of https://github.com/SailorMax/PHPWord
1924
- php: 7.2
2025

2126
cache:

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ This version brings compatibility with PHP 7.0 & 7.1
3737
### Fixed
3838
- Loosen dependency to Zend
3939
- Images are not being printed when generating PDF - @hubertinio #1074 #431
40-
- Fixed some PHP 7 warnings - @likeuntomurphy #927
40+
- Fixed some PHP 7 warnings - @ likeuntomurphy #927
41+
- Fixed PHP 7.2 compatibility (renamed `Object` class names to `ObjectElement`) - @SailorMax #1185
4142
- Fixed Word 97 reader - @alsofronie @Benpxpx @mario-rivera #912 #920 #892
4243
- Fixed image loading over https - @troosan #988
4344
- Impossibility to set different even and odd page headers - @troosan #981

src/PhpWord/Element/AbstractContainer.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
* @method PageBreak addPageBreak()
3838
* @method Table addTable(mixed $style = null)
3939
* @method Image addImage(string $source, mixed $style = null, bool $isWatermark = false)
40-
* @method \PhpOffice\PhpWord\Element\Object addObject(string $source, mixed $style = null)
40+
* @method \PhpOffice\PhpWord\Element\OLEObject addObject(string $source, mixed $style = null)
4141
* @method TextBox addTextBox(mixed $style = null)
4242
* @method Field addField(string $type = null, array $properties = array(), array $options = array(), mixed $text = null)
4343
* @method Line addLine(mixed $lineStyle = null)
@@ -87,7 +87,7 @@ public function __call($function, $args)
8787
);
8888
$functions = array();
8989
foreach ($elements as $element) {
90-
$functions['add' . strtolower($element)] = $element;
90+
$functions['add' . strtolower($element)] = $element == 'Object' ? 'OLEObject' : $element;
9191
}
9292

9393
// Run valid `add` command
@@ -193,7 +193,7 @@ private function checkValidity($method)
193193
'Link' => $generalContainers,
194194
'TextBreak' => $generalContainers,
195195
'Image' => $generalContainers,
196-
'Object' => $generalContainers,
196+
'OLEObject' => $generalContainers,
197197
'Field' => $generalContainers,
198198
'Line' => $generalContainers,
199199
'Shape' => $generalContainers,

src/PhpWord/Element/AbstractElement.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -358,11 +358,14 @@ public function setParentContainer(AbstractElement $container)
358358
*/
359359
private function setMediaRelation()
360360
{
361-
if (!$this instanceof Link && !$this instanceof Image && !$this instanceof Object) {
361+
if (!$this instanceof Link && !$this instanceof Image && !$this instanceof OLEObject) {
362362
return;
363363
}
364364

365365
$elementName = substr(get_class($this), strrpos(get_class($this), '\\') + 1);
366+
if ($elementName == 'OLEObject') {
367+
$elementName = 'Object';
368+
}
366369
$mediaPart = $this->getMediaPart();
367370
$source = $this->getSource();
368371
$image = null;
@@ -372,7 +375,7 @@ private function setMediaRelation()
372375
$rId = Media::addElement($mediaPart, strtolower($elementName), $source, $image);
373376
$this->setRelationId($rId);
374377

375-
if ($this instanceof Object) {
378+
if ($this instanceof OLEObject) {
376379
$icon = $this->getIcon();
377380
$rId = Media::addElement($mediaPart, 'image', $icon, new Image($icon));
378381
$this->setImageRelationId($rId);

src/PhpWord/Element/Object.php renamed to src/PhpWord/Element/OLEObject.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@
2121
use PhpOffice\PhpWord\Style\Image as ImageStyle;
2222

2323
/**
24-
* Object element
24+
* OLEObject element
2525
*/
26-
class Object extends AbstractElement
26+
class OLEObject extends AbstractElement
2727
{
2828
/**
2929
* Ole-Object Src

src/PhpWord/Writer/Word2007/Element/Object.php renamed to src/PhpWord/Writer/Word2007/Element/OLEObject.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@
2020
use PhpOffice\PhpWord\Writer\Word2007\Style\Image as ImageStyleWriter;
2121

2222
/**
23-
* Object element writer
23+
* OLEObject element writer
2424
*
2525
* @since 0.10.0
2626
*/
27-
class Object extends AbstractElement
27+
class OLEObject extends AbstractElement
2828
{
2929
/**
3030
* Write object element.
@@ -33,7 +33,7 @@ public function write()
3333
{
3434
$xmlWriter = $this->getXmlWriter();
3535
$element = $this->getElement();
36-
if (!$element instanceof \PhpOffice\PhpWord\Element\Object) {
36+
if (!$element instanceof \PhpOffice\PhpWord\Element\OLEObject) {
3737
return;
3838
}
3939

tests/PhpWord/Element/CellTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ public function testAddObjectXLS()
181181
$element = $oCell->addObject($src);
182182

183183
$this->assertCount(1, $oCell->getElements());
184-
$this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Object', $element);
184+
$this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\OLEObject', $element);
185185
}
186186

187187
/**

tests/PhpWord/Element/ObjectTest.php

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@
1818
namespace PhpOffice\PhpWord\Element;
1919

2020
/**
21-
* Test class for PhpOffice\PhpWord\Element\Object
21+
* Test class for PhpOffice\PhpWord\Element\OLEObject
2222
*
23-
* @coversDefaultClass \PhpOffice\PhpWord\Element\Object
23+
* @coversDefaultClass \PhpOffice\PhpWord\Element\OLEObject
2424
* @runTestsInSeparateProcesses
2525
*/
2626
class ObjectTest extends \PHPUnit\Framework\TestCase
@@ -31,9 +31,9 @@ class ObjectTest extends \PHPUnit\Framework\TestCase
3131
public function testConstructWithSupportedFiles()
3232
{
3333
$src = __DIR__ . '/../_files/documents/reader.docx';
34-
$oObject = new Object($src);
34+
$oObject = new OLEObject($src);
3535

36-
$this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Object', $oObject);
36+
$this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\OLEObject', $oObject);
3737
$this->assertInstanceOf('PhpOffice\\PhpWord\\Style\\Image', $oObject->getStyle());
3838
$this->assertEquals($src, $oObject->getSource());
3939
}
@@ -44,9 +44,9 @@ public function testConstructWithSupportedFiles()
4444
public function testConstructWithSupportedFilesLong()
4545
{
4646
$src = __DIR__ . '/../_files/documents/sheet.xls';
47-
$oObject = new Object($src);
47+
$oObject = new OLEObject($src);
4848

49-
$this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Object', $oObject);
49+
$this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\OLEObject', $oObject);
5050
$this->assertInstanceOf('PhpOffice\\PhpWord\\Style\\Image', $oObject->getStyle());
5151
$this->assertEquals($src, $oObject->getSource());
5252
}
@@ -59,7 +59,7 @@ public function testConstructWithSupportedFilesLong()
5959
public function testConstructWithNotSupportedFiles()
6060
{
6161
$src = __DIR__ . '/../_files/xsl/passthrough.xsl';
62-
$oObject = new Object($src);
62+
$oObject = new OLEObject($src);
6363
$oObject->getSource();
6464
}
6565

@@ -69,9 +69,9 @@ public function testConstructWithNotSupportedFiles()
6969
public function testConstructWithSupportedFilesAndStyle()
7070
{
7171
$src = __DIR__ . '/../_files/documents/sheet.xls';
72-
$oObject = new Object($src, array('width' => '230px'));
72+
$oObject = new OLEObject($src, array('width' => '230px'));
7373

74-
$this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Object', $oObject);
74+
$this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\OLEObject', $oObject);
7575
$this->assertInstanceOf('PhpOffice\\PhpWord\\Style\\Image', $oObject->getStyle());
7676
$this->assertEquals($src, $oObject->getSource());
7777
}
@@ -82,7 +82,7 @@ public function testConstructWithSupportedFilesAndStyle()
8282
public function testRelationId()
8383
{
8484
$src = __DIR__ . '/../_files/documents/sheet.xls';
85-
$oObject = new Object($src);
85+
$oObject = new OLEObject($src);
8686

8787
$iVal = rand(1, 1000);
8888
$oObject->setRelationId($iVal);
@@ -95,7 +95,7 @@ public function testRelationId()
9595
public function testImageRelationId()
9696
{
9797
$src = __DIR__ . '/../_files/documents/sheet.xls';
98-
$oObject = new Object($src);
98+
$oObject = new OLEObject($src);
9999

100100
$iVal = rand(1, 1000);
101101
$oObject->setImageRelationId($iVal);

tests/PhpWord/Element/SectionTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public function testAddElements()
7070
'PageBreak',
7171
'Table',
7272
'ListItem',
73-
'Object',
73+
'OLEObject',
7474
'Image',
7575
'Title',
7676
'TextRun',

tests/PhpWord/Writer/Word2007/ElementTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public function testUnmatchedElements()
4444
{
4545
$elements = array(
4646
'CheckBox', 'Container', 'Footnote', 'Image', 'Link', 'ListItem', 'ListItemRun',
47-
'Object', 'PreserveText', 'Table', 'Text', 'TextBox', 'TextBreak', 'Title', 'TOC',
47+
'OLEObject', 'PreserveText', 'Table', 'Text', 'TextBox', 'TextBreak', 'Title', 'TOC',
4848
'Field', 'Line', 'Shape', 'Chart', 'FormField', 'SDT', 'Bookmark',
4949
);
5050
foreach ($elements as $element) {

0 commit comments

Comments
 (0)