Skip to content

Commit f1108c4

Browse files
committed
Add Abstract- prefix and -Interface suffix for corresponding classes
1 parent b594e32 commit f1108c4

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+251
-277
lines changed

CHANGELOG.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,23 +39,23 @@ This is the changelog between releases of PHPWord. Releases are listed in revers
3939
- `createHeader` replaced by `addHeader`
4040
- `createFooter` replaced by `addFooter`
4141
- `createSection` replaced by `addSection`
42-
- `Element\Footnote::getReferenceId` replaced by `Container\Container::getRelationId`
43-
- `Element\Footnote::setReferenceId` replaced by `Container\Container::setRelationId`
42+
- `Element\Footnote::getReferenceId` replaced by `Element\AbstractElement::getRelationId`
43+
- `Element\Footnote::setReferenceId` replaced by `Element\AbstractElement::setRelationId`
4444
- `Footnote::addFootnoteLinkElement` replaced by `Media::addElement`
4545
- `Footnote::getFootnoteLinkElements` replaced by `Media::getElements`
4646
- All current methods on `Media`
4747

4848
### Miscellaneous
4949

5050
- Documentation: Simplify page level docblock - @ivanlanin GH-179
51-
- Writer: Refactor writer classes and make a new Writer abstract class - @ivanlanin GH-160
52-
- Reader: Rename AbstractReader > Reader - @ivanlanin
53-
- General: Refactor folders: Element, Container, and Exception - @ivanlanin GH-187
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
5453
- General: Remove legacy HashTable and ZipStreamWrapper and all related properties/methods - @ivanlanin GH-187
55-
- Container: Create new Container abstract class - @ivanlanin GH-187
56-
- Element: Create new Element abstract class - @ivanlanin GH-187
54+
- Element: Create new AbstractElement abstract class - @ivanlanin GH-187
5755
- Media: Refactor media class to use one method for all docPart (section, header, footer, footnote) - @ivanlanin GH-187
58-
- General: Remove underscore prefix from all private properties name
56+
- General: Remove underscore prefix from all private properties name - @ivanlanin GH-187
57+
- General: Move Section Settings to Style\Section - @ivanlanin GH-187
58+
- 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
5959

6060
## 0.9.1 - 27 Mar 2014
6161

src/PhpWord/Element/AbstractElement.php

Lines changed: 123 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
88
*/
99

10-
namespace PhpOffice\PhpWord\Container;
10+
namespace PhpOffice\PhpWord\Element;
1111

1212
use PhpOffice\PhpWord\Exception\InvalidImageException;
1313
use PhpOffice\PhpWord\Exception\InvalidObjectException;
@@ -35,7 +35,7 @@
3535
*
3636
* @since 0.9.2
3737
*/
38-
abstract class Container extends Element
38+
abstract class AbstractElement
3939
{
4040
/**
4141
* Container type section|header|footer|cell|textrun|footnote
@@ -51,6 +51,28 @@ abstract class Container extends Element
5151
*/
5252
protected $sectionId;
5353

54+
/**
55+
* Document part type: section|header|footer
56+
*
57+
* Used by textrun and cell container to determine where the element is
58+
* located because it will affect the availability of other element,
59+
* e.g. footnote will not be available when $docPart is header or footer.
60+
*
61+
* @var string
62+
*/
63+
private $docPart = 'section';
64+
65+
/**
66+
* Document part Id
67+
*
68+
* For header and footer, this will be = ($sectionId - 1) * 3 + $index
69+
* because the max number of header/footer in every page is 3, i.e.
70+
* AUTO, FIRST, and EVEN (AUTO = ODD)
71+
*
72+
* @var integer
73+
*/
74+
private $docPartId = 1;
75+
5476
/**
5577
* Elements collection
5678
*
@@ -340,6 +362,38 @@ public function getSectionId()
340362
return $this->sectionId;
341363
}
342364

365+
/**
366+
* Set doc part
367+
*
368+
* @param string $docPart
369+
* @param integer $docPartId
370+
*/
371+
public function setDocPart($docPart, $docPartId = 1)
372+
{
373+
$this->docPart = $docPart;
374+
$this->docPartId = $docPartId;
375+
}
376+
377+
/**
378+
* Get doc part
379+
*
380+
* @return string
381+
*/
382+
public function getDocPart()
383+
{
384+
return $this->docPart;
385+
}
386+
387+
/**
388+
* Get doc part Id
389+
*
390+
* @return integer
391+
*/
392+
public function getDocPartId()
393+
{
394+
return $this->docPartId;
395+
}
396+
343397
/**
344398
* Get all elements
345399
*
@@ -373,40 +427,37 @@ public function setRelationId($rId)
373427
}
374428

375429
/**
376-
* Add memory image element
430+
* Check if element is located in section doc part (as opposed to header/footer)
377431
*
378-
* @param string $src
379-
* @param mixed $style
380-
* @deprecated 0.9.0
381-
* @codeCoverageIgnore
432+
* @return boolean
382433
*/
383-
public function addMemoryImage($src, $style = null)
434+
public function isInSection()
384435
{
385-
return $this->addImage($src, $style);
436+
return ($this->docPart == 'section');
386437
}
387438

388439
/**
389-
* Create textrun element
440+
* Set style value
390441
*
391-
* @param mixed $paragraphStyle
392-
* @deprecated 0.9.2
393-
* @codeCoverageIgnore
442+
* @param mixed $styleObject Style object
443+
* @param mixed $styleValue Style value
444+
* @param boolean $returnObject Always return object
394445
*/
395-
public function createTextRun($paragraphStyle = null)
446+
protected function setStyle($styleObject, $styleValue = null, $returnObject = false)
396447
{
397-
return $this->addTextRun($paragraphStyle);
398-
}
448+
if (!is_null($styleValue) && is_array($styleValue)) {
449+
foreach ($styleValue as $key => $value) {
450+
if (substr($key, 0, 1) == '_') {
451+
$key = substr($key, 1);
452+
}
453+
$styleObject->setStyleValue($key, $value);
454+
}
455+
$style = $styleObject;
456+
} else {
457+
$style = $returnObject ? $styleObject : $styleValue;
458+
}
399459

400-
/**
401-
* Create footnote element
402-
*
403-
* @param mixed $paragraphStyle
404-
* @deprecated 0.9.2
405-
* @codeCoverageIgnore
406-
*/
407-
public function createFootnote($paragraphStyle = null)
408-
{
409-
return $this->addFootnote($paragraphStyle);
460+
return $style;
410461
}
411462

412463
/**
@@ -417,13 +468,14 @@ public function createFootnote($paragraphStyle = null)
417468
*/
418469
private function checkValidity($method)
419470
{
420-
// Empty array means the element can be accepted by all containers
471+
// Valid containers for each element
472+
$allContainers = array('section', 'header', 'footer', 'cell', 'textrun', 'footnote');
421473
$validContainers = array(
422-
'text' => array(),
423-
'link' => array(),
424-
'textbreak' => array(),
425-
'image' => array(),
426-
'object' => array(),
474+
'text' => $allContainers,
475+
'link' => $allContainers,
476+
'textbreak' => $allContainers,
477+
'image' => $allContainers,
478+
'object' => $allContainers,
427479
'textrun' => array('section', 'header', 'footer', 'cell'),
428480
'listitem' => array('section', 'header', 'footer', 'cell'),
429481
'checkbox' => array('section', 'header', 'footer', 'cell'),
@@ -442,10 +494,8 @@ private function checkValidity($method)
442494

443495
// Check if a method is valid for current container
444496
if (array_key_exists($method, $validContainers)) {
445-
if (!empty($validContainers[$method])) {
446-
if (!in_array($this->container, $validContainers[$method])) {
447-
throw new \BadMethodCallException();
448-
}
497+
if (!in_array($this->container, $validContainers[$method])) {
498+
throw new \BadMethodCallException();
449499
}
450500
}
451501
// Check if a method is valid for current container, located in other container
@@ -475,4 +525,41 @@ private function checkElementDocPart()
475525

476526
return $inHeaderFooter ? $docPart . $docPartId : $docPart;
477527
}
528+
529+
/**
530+
* Add memory image element
531+
*
532+
* @param string $src
533+
* @param mixed $style
534+
* @deprecated 0.9.0
535+
* @codeCoverageIgnore
536+
*/
537+
public function addMemoryImage($src, $style = null)
538+
{
539+
return $this->addImage($src, $style);
540+
}
541+
542+
/**
543+
* Create textrun element
544+
*
545+
* @param mixed $paragraphStyle
546+
* @deprecated 0.9.2
547+
* @codeCoverageIgnore
548+
*/
549+
public function createTextRun($paragraphStyle = null)
550+
{
551+
return $this->addTextRun($paragraphStyle);
552+
}
553+
554+
/**
555+
* Create footnote element
556+
*
557+
* @param mixed $paragraphStyle
558+
* @deprecated 0.9.2
559+
* @codeCoverageIgnore
560+
*/
561+
public function createFootnote($paragraphStyle = null)
562+
{
563+
return $this->addFootnote($paragraphStyle);
564+
}
478565
}

src/PhpWord/Element/Cell.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,12 @@
99

1010
namespace PhpOffice\PhpWord\Element;
1111

12-
use PhpOffice\PhpWord\Container\Container;
1312
use PhpOffice\PhpWord\Style\Cell as CellStyle;
1413

1514
/**
1615
* Table cell element
1716
*/
18-
class Cell extends Container
17+
class Cell extends AbstractElement
1918
{
2019
/**
2120
* Cell width

src/PhpWord/Element/CheckBox.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
/**
1616
* Check box element
1717
*/
18-
class CheckBox extends Element
18+
class CheckBox extends AbstractElement
1919
{
2020
/**
2121
* Name content

src/PhpWord/Element/Element.php

Lines changed: 0 additions & 106 deletions
This file was deleted.

0 commit comments

Comments
 (0)