Skip to content

Commit 4a3400c

Browse files
committed
Refactor: Create writers' Part folders and remove all static parts
1 parent 23db6fa commit 4a3400c

Some content is hidden

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

48 files changed

+459
-451
lines changed

src/PhpWord/Element/AbstractContainer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ public function addObject($src, $style = null)
277277
if (strlen($ext) == 4 && strtolower(substr($ext, -1)) == 'x') {
278278
$ext = substr($ext, 0, -1);
279279
}
280-
$icon = realpath(__DIR__ . "/../_staticDocParts/_{$ext}.png");
280+
$icon = realpath(__DIR__ . "/../resources/{$ext}.png");
281281
$rId = Media::addElement($elementDocPart, 'object', $src);
282282
$object->setRelationId($rId);
283283
$rIdimg = Media::addElement($elementDocPart, 'image', $icon, new Image($icon));

src/PhpWord/Reader/ODText/AbstractPart.php

Lines changed: 16 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -9,59 +9,42 @@
99

1010
namespace PhpOffice\PhpWord\Reader\ODText;
1111

12-
use PhpOffice\PhpWord\PhpWord;
1312
use PhpOffice\PhpWord\Shared\XMLReader;
1413

1514
/**
1615
* Abstract part reader
1716
*/
18-
abstract class AbstractPart
17+
abstract class AbstractPart extends \PhpOffice\PhpWord\Reader\Word2007\AbstractPart
1918
{
2019
/**
21-
* Document file
20+
* Read w:r (override)
2221
*
23-
* @var string
22+
* @param mixed $parent
23+
* @param string $docPart
24+
* @param mixed $pStyle
2425
*/
25-
protected $docFile;
26-
27-
/**
28-
* XML file
29-
*
30-
* @var string
31-
*/
32-
protected $xmlFile;
33-
34-
/**
35-
* Part relationships
36-
*
37-
* @var array
38-
*/
39-
protected $rels = array();
26+
protected function readRun(XMLReader $xmlReader, \DOMElement $domNode, &$parent, $docPart, $pStyle = null)
27+
{
28+
}
4029

4130
/**
42-
* Read part
31+
* Read w:pPr (override)
4332
*/
44-
abstract public function read(PhpWord &$phpWord);
33+
protected function readParagraphStyle(XMLReader $xmlReader, \DOMElement $domNode)
34+
{
35+
}
4536

4637
/**
47-
* Create new instance
48-
*
49-
* @param string $docFile
50-
* @param string $xmlFile
38+
* Read w:rPr (override)
5139
*/
52-
public function __construct($docFile, $xmlFile)
40+
protected function readFontStyle(XMLReader $xmlReader, \DOMElement $domNode)
5341
{
54-
$this->docFile = $docFile;
55-
$this->xmlFile = $xmlFile;
5642
}
5743

5844
/**
59-
* Set relationships
60-
*
61-
* @param array $value
45+
* Read w:tblPr (override)
6246
*/
63-
public function setRels($value)
47+
protected function readTableStyle(XMLReader $xmlReader, \DOMElement $domNode)
6448
{
65-
$this->rels = $value;
6649
}
6750
}

src/PhpWord/Writer/ODText.php

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,6 @@
1212
use PhpOffice\PhpWord\Media;
1313
use PhpOffice\PhpWord\PhpWord;
1414
use PhpOffice\PhpWord\Exception\Exception;
15-
use PhpOffice\PhpWord\Writer\ODText\Content;
16-
use PhpOffice\PhpWord\Writer\ODText\Manifest;
17-
use PhpOffice\PhpWord\Writer\ODText\Meta;
18-
use PhpOffice\PhpWord\Writer\ODText\Mimetype;
19-
use PhpOffice\PhpWord\Writer\ODText\Styles;
2015

2116
/**
2217
* ODText writer
@@ -35,14 +30,16 @@ public function __construct(PhpWord $phpWord = null)
3530
// Assign PhpWord
3631
$this->setPhpWord($phpWord);
3732

38-
// Set writer parts
39-
$this->writerParts['content'] = new Content();
40-
$this->writerParts['manifest'] = new Manifest();
41-
$this->writerParts['meta'] = new Meta();
42-
$this->writerParts['mimetype'] = new Mimetype();
43-
$this->writerParts['styles'] = new Styles();
44-
foreach ($this->writerParts as $writer) {
45-
$writer->setParentWriter($this);
33+
// Create parts
34+
$parts = array('Content', 'Manifest', 'Meta', 'Mimetype', 'Styles');
35+
foreach ($parts as $part) {
36+
$partName = strtolower($part);
37+
$partClass = 'PhpOffice\\PhpWord\\Writer\\ODText\\Part\\' . $part;
38+
if (class_exists($partClass)) {
39+
$partObject = new $partClass();
40+
$partObject->setParentWriter($this);
41+
$this->writerParts[$partName] = $partObject;
42+
}
4643
}
4744

4845
// Set package paths

src/PhpWord/Writer/ODText/AbstractWriterPart.php

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

src/PhpWord/Writer/ODText/Element/Element.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
use PhpOffice\PhpWord\Element\AbstractElement;
1313
use PhpOffice\PhpWord\Shared\XMLWriter;
14-
use PhpOffice\PhpWord\Writer\ODText\AbstractWriterPart;
14+
use PhpOffice\PhpWord\Writer\ODText\Part\AbstractPart;
1515

1616
/**
1717
* Generic element writer
@@ -30,7 +30,7 @@ class Element
3030
/**
3131
* Parent writer
3232
*
33-
* @var \PhpOffice\PhpWord\Writer\ODText\AbstractWriterPart
33+
* @var \PhpOffice\PhpWord\Writer\ODText\AbstractPart
3434
*/
3535
protected $parentWriter;
3636

@@ -53,7 +53,7 @@ class Element
5353
*
5454
* @param bool $withoutP
5555
*/
56-
public function __construct(XMLWriter $xmlWriter, AbstractWriterPart $parentWriter, AbstractElement $element, $withoutP = false)
56+
public function __construct(XMLWriter $xmlWriter, AbstractPart $parentWriter, AbstractElement $element, $withoutP = false)
5757
{
5858
$this->xmlWriter = $xmlWriter;
5959
$this->parentWriter = $parentWriter;

src/PhpWord/Writer/ODText/Element/TextRun.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
namespace PhpOffice\PhpWord\Writer\ODText\Element;
1111

1212
use PhpOffice\PhpWord\Element\Text as TextElement;
13+
use PhpOffice\PhpWord\Element\Link as LinkElement;
1314
use PhpOffice\PhpWord\Writer\ODText\Element\Element as ElementWriter;
1415

1516
/**

src/PhpWord/Writer/ODText/Base.php renamed to src/PhpWord/Writer/ODText/Part/AbstractPart.php

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

10-
namespace PhpOffice\PhpWord\Writer\ODText;
10+
namespace PhpOffice\PhpWord\Writer\ODText\Part;
1111

1212
use PhpOffice\PhpWord\PhpWord;
1313
use PhpOffice\PhpWord\Style;
1414
use PhpOffice\PhpWord\Style\Font;
1515
use PhpOffice\PhpWord\Shared\XMLWriter;
1616

1717
/**
18-
* ODT base part writer
19-
*
20-
* @since 0.10.0
18+
* ODText writer part abstract
2119
*/
22-
class Base extends AbstractWriterPart
20+
abstract class AbstractPart extends \PhpOffice\PhpWord\Writer\Word2007\Part\AbstractPart
2321
{
2422
/**
2523
* Write common root attributes

src/PhpWord/Writer/ODText/Content.php renamed to src/PhpWord/Writer/ODText/Part/Content.php

Lines changed: 2 additions & 2 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\Writer\ODText;
10+
namespace PhpOffice\PhpWord\Writer\ODText\Part;
1111

1212
use PhpOffice\PhpWord\Media;
1313
use PhpOffice\PhpWord\Style;
@@ -23,7 +23,7 @@
2323
/**
2424
* ODText content part writer
2525
*/
26-
class Content extends Base
26+
class Content extends AbstractPart
2727
{
2828
/**
2929
* Write content file to XML format

src/PhpWord/Writer/ODText/Manifest.php renamed to src/PhpWord/Writer/ODText/Part/Manifest.php

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

10-
namespace PhpOffice\PhpWord\Writer\ODText;
10+
namespace PhpOffice\PhpWord\Writer\ODText\Part;
1111

1212
use PhpOffice\PhpWord\Media;
1313

1414
/**
1515
* ODText manifest part writer
1616
*/
17-
class Manifest extends AbstractWriterPart
17+
class Manifest extends AbstractPart
1818
{
1919
/**
2020
* Write Manifest file to XML format

src/PhpWord/Writer/ODText/Meta.php renamed to src/PhpWord/Writer/ODText/Part/Meta.php

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

10-
namespace PhpOffice\PhpWord\Writer\ODText;
10+
namespace PhpOffice\PhpWord\Writer\ODText\Part;
1111

1212
use PhpOffice\PhpWord\Exception\Exception;
1313
use PhpOffice\PhpWord\PhpWord;
1414

1515
/**
1616
* ODText meta part writer
1717
*/
18-
class Meta extends AbstractWriterPart
18+
class Meta extends AbstractPart
1919
{
2020
/**
2121
* Write Meta file to XML format

0 commit comments

Comments
 (0)