Skip to content

Commit 6456255

Browse files
committed
Merge branch '#160-element-container' into xml-reader
2 parents dadfc29 + cd2dba0 commit 6456255

27 files changed

+234
-360
lines changed

CHANGELOG.md

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ This is the changelog between releases of PHPWord. Releases are listed in revers
44

55
## 0.9.2 - Not yet released
66

7+
This release marked heavy refactorings on internal code structure with the creation of some abstract classes to reduce code duplication. `Element` subnamespace is introduced in this release to replace `Section`.
8+
79
### Features
810

911
- Image: Get image dimensions without EXIF extension - @andrew-kzoo GH-184
@@ -48,14 +50,16 @@ This is the changelog between releases of PHPWord. Releases are listed in revers
4850
### Miscellaneous
4951

5052
- Documentation: Simplify page level docblock - @ivanlanin GH-179
51-
- Writer: Refactor writer classes and make a new AbstractWriter abstract class - @ivanlanin GH-160
52-
- General: Refactor folders: Element and Exception - @ivanlanin GH-187
53-
- General: Remove legacy HashTable and ZipStreamWrapper and all related properties/methods - @ivanlanin GH-187
54-
- Element: Create new AbstractElement abstract class - @ivanlanin GH-187
53+
- Writer: Refactor writer classes and create a new `Write\AbstractWriter` abstract class - @ivanlanin GH-160
54+
- General: Refactor folders: `Element` and `Exception` - @ivanlanin GH-187
55+
- General: Remove legacy `HashTable` and `Shared\ZipStreamWrapper` and all related properties/methods - @ivanlanin GH-187
56+
- Element: New `AbstractElement` abstract class - @ivanlanin GH-187
5557
- Media: Refactor media class to use one method for all docPart (section, header, footer, footnote) - @ivanlanin GH-187
5658
- General: Remove underscore prefix from all private properties name - @ivanlanin GH-187
57-
- General: Move Section Settings to Style\Section - @ivanlanin GH-187
59+
- General: Move Section `Settings` to `Style\Section` - @ivanlanin GH-187
5860
- General: Give `Abstract` prefix and `Interface` suffix for all abstract classes and interfaces as per [PHP-FIG recommendation](https://github.com/php-fig/fig-standards/blob/master/bylaws/002-psr-naming-conventions.md) - @ivanlanin GH-187
61+
- Style: New `Style\AbstractStyle` abstract class - @ivanlanin GH-187
62+
- Writer: New 'ODText\Base` class - @ivanlanin GH-187
5963

6064
## 0.9.1 - 27 Mar 2014
6165

src/PhpWord/Element/AbstractElement.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99

1010
namespace PhpOffice\PhpWord\Element;
1111

12-
use PhpOffice\PhpWord\Exception\InvalidImageException;
1312
use PhpOffice\PhpWord\Exception\InvalidObjectException;
1413
use PhpOffice\PhpWord\Media;
1514
use PhpOffice\PhpWord\Style;
@@ -482,7 +481,6 @@ private function checkValidity($method)
482481
'table' => array('section', 'header', 'footer'),
483482
'footnote' => array('section', 'textrun', 'cell'),
484483
'preservetext' => array('header', 'footer', 'cell'),
485-
'relationid' => array('header', 'footer', 'footnote'),
486484
'title' => array('section'),
487485
);
488486
// Special condition, e.g. preservetext can only exists in cell when

src/PhpWord/Element/Image.php

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,6 @@ class Image extends AbstractElement
3232
*/
3333
private $style;
3434

35-
/**
36-
* Image relation ID specific only for DOCX
37-
*
38-
* @var string
39-
*/
40-
private $rId;
41-
4235
/**
4336
* Is watermark
4437
*
@@ -155,26 +148,6 @@ public function getStyle()
155148
return $this->style;
156149
}
157150

158-
/**
159-
* Get image relation ID
160-
*
161-
* @return int
162-
*/
163-
public function getRelationId()
164-
{
165-
return $this->rId;
166-
}
167-
168-
/**
169-
* Set image relation ID
170-
*
171-
* @param int $rId
172-
*/
173-
public function setRelationId($rId)
174-
{
175-
$this->rId = $rId;
176-
}
177-
178151
/**
179152
* Get image source
180153
*

src/PhpWord/Element/Link.php

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,6 @@ class Link extends AbstractElement
3131
*/
3232
private $name;
3333

34-
/**
35-
* Link Relation ID
36-
*
37-
* @var string
38-
*/
39-
private $relationId;
40-
4134
/**
4235
* Font style
4336
*
@@ -71,26 +64,6 @@ public function __construct($linkSrc, $linkName = null, $fontStyle = null, $para
7164
return $this;
7265
}
7366

74-
/**
75-
* Get Link Relation ID
76-
*
77-
* @return int
78-
*/
79-
public function getRelationId()
80-
{
81-
return $this->relationId;
82-
}
83-
84-
/**
85-
* Set Link Relation ID
86-
*
87-
* @param int $rId
88-
*/
89-
public function setRelationId($rId)
90-
{
91-
$this->relationId = $rId;
92-
}
93-
9467
/**
9568
* Get Link source
9669
*

src/PhpWord/Element/Object.php

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,6 @@ class Object extends AbstractElement
3030
*/
3131
private $style;
3232

33-
/**
34-
* Object Relation ID
35-
*
36-
* @var int
37-
*/
38-
private $relationId;
39-
4033
/**
4134
* Image Relation ID
4235
*
@@ -84,26 +77,6 @@ public function getSource()
8477
return $this->source;
8578
}
8679

87-
/**
88-
* Get Object Relation ID
89-
*
90-
* @return int
91-
*/
92-
public function getRelationId()
93-
{
94-
return $this->relationId;
95-
}
96-
97-
/**
98-
* Set Object Relation ID
99-
*
100-
* @param int $rId
101-
*/
102-
public function setRelationId($rId)
103-
{
104-
$this->relationId = $rId;
105-
}
106-
10780
/**
10881
* Get Image Relation ID
10982
*

src/PhpWord/Reader/AbstractReader.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,10 @@ public function canRead($pFilename)
9090
} catch (Exception $e) {
9191
return false;
9292
}
93-
fclose($this->fileHandle);
93+
if (is_resource($this->fileHandle)) {
94+
fclose($this->fileHandle);
95+
}
96+
9497
return true;
9598
}
9699
}

src/PhpWord/Style/AbstractStyle.php

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?php
2+
/**
3+
* PHPWord
4+
*
5+
* @link https://github.com/PHPOffice/PHPWord
6+
* @copyright 2014 PHPWord
7+
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
8+
*/
9+
10+
namespace PhpOffice\PhpWord\Style;
11+
12+
/**
13+
* Abstract style class
14+
*
15+
* @since 0.9.2
16+
*/
17+
abstract class AbstractStyle
18+
{
19+
/**
20+
* Set style value template method
21+
*
22+
* Some child classes have their own specific overrides
23+
*
24+
* @param string $key
25+
* @param string $value
26+
*
27+
* @todo Implement type check mechanism, e.g. boolean, integer, enum, defaults
28+
*/
29+
public function setStyleValue($key, $value)
30+
{
31+
// Backward compability check for versions < 0.9.2 which use underscore
32+
// prefix for their private properties
33+
if (substr($key, 0, 1) == '_') {
34+
$key = substr($key, 1);
35+
}
36+
37+
// Check if the set method is exists. Throws an exception?
38+
$method = 'set' . $key;
39+
if (method_exists($this, $method)) {
40+
$this->$method($value);
41+
}
42+
}
43+
}

src/PhpWord/Style/Cell.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
/**
1313
* Table cell style
1414
*/
15-
class Cell
15+
class Cell extends AbstractStyle
1616
{
1717
const TEXT_DIR_BTLR = 'btLr';
1818
const TEXT_DIR_TBRL = 'tbRl';

src/PhpWord/Style/Font.php

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
/**
1616
* Font style
1717
*/
18-
class Font
18+
class Font extends AbstractStyle
1919
{
2020
const UNDERLINE_NONE = 'none';
2121
const UNDERLINE_DASH = 'dash';
@@ -202,23 +202,6 @@ public function setArrayStyle(array $style = array())
202202
return $this;
203203
}
204204

205-
/**
206-
* Set style value
207-
*
208-
* @param string $key
209-
* @param mixed $value
210-
*/
211-
public function setStyleValue($key, $value)
212-
{
213-
if (substr($key, 0, 1) == '_') {
214-
$key = substr($key, 1);
215-
}
216-
$method = 'set' . $key;
217-
if (method_exists($this, $method)) {
218-
$this->$method($value);
219-
}
220-
}
221-
222205
/**
223206
* Get font name
224207
*

src/PhpWord/Style/Image.php

Lines changed: 8 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
/**
1313
* Image and memory image style
1414
*/
15-
class Image
15+
class Image extends AbstractStyle
1616
{
1717
const WRAPPING_STYLE_INLINE = 'inline';
1818
const WRAPPING_STYLE_SQUARE = 'square';
@@ -41,13 +41,6 @@ class Image
4141
*/
4242
private $align;
4343

44-
/**
45-
* Wrapping style
46-
*
47-
* @var string
48-
*/
49-
private $wrappingStyle;
50-
5144
/**
5245
* Margin Top
5346
*
@@ -62,6 +55,13 @@ class Image
6255
*/
6356
private $marginLeft;
6457

58+
/**
59+
* Wrapping style
60+
*
61+
* @var string
62+
*/
63+
private $wrappingStyle;
64+
6565
/**
6666
* Create new image style
6767
*/
@@ -75,20 +75,6 @@ public function __construct()
7575
$this->setWrappingStyle(self::WRAPPING_STYLE_INLINE);
7676
}
7777

78-
/**
79-
* Set style value
80-
*
81-
* @param string $key
82-
* @param mixed $value
83-
*/
84-
public function setStyleValue($key, $value)
85-
{
86-
if (substr($key, 0, 1) == '_') {
87-
$key = substr($key, 1);
88-
}
89-
$this->$key = $value;
90-
}
91-
9278
/**
9379
* Get width
9480
*/

src/PhpWord/Style/ListItem.php

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
/**
1313
* List item style
1414
*/
15-
class ListItem
15+
class ListItem extends AbstractStyle
1616
{
1717
const TYPE_NUMBER = 7;
1818
const TYPE_NUMBER_NESTED = 8;
@@ -34,20 +34,6 @@ public function __construct()
3434
$this->listType = self::TYPE_BULLET_FILLED;
3535
}
3636

37-
/**
38-
* Set style value
39-
*
40-
* @param string $key
41-
* @param string $value
42-
*/
43-
public function setStyleValue($key, $value)
44-
{
45-
if (substr($key, 0, 1) == '_') {
46-
$key = substr($key, 1);
47-
}
48-
$this->$key = $value;
49-
}
50-
5137
/**
5238
* Set List Type
5339
*

src/PhpWord/Style/Paragraph.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
/**
1515
* Paragraph style
1616
*/
17-
class Paragraph
17+
class Paragraph extends AbstractStyle
1818
{
1919
const LINE_HEIGHT = 240;
2020

src/PhpWord/Style/Row.php

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
/**
1313
* Table row style
1414
*/
15-
class Row
15+
class Row extends AbstractStyle
1616
{
1717
/**
1818
* Repeat table row on every new page
@@ -42,20 +42,6 @@ public function __construct()
4242
{
4343
}
4444

45-
/**
46-
* Set style value
47-
*
48-
* @param string $key
49-
* @param mixed $value
50-
*/
51-
public function setStyleValue($key, $value)
52-
{
53-
if (substr($key, 0, 1) == '_') {
54-
$key = substr($key, 1);
55-
}
56-
$this->$key = $value;
57-
}
58-
5945
/**
6046
* Set tblHeader
6147
*

0 commit comments

Comments
 (0)