Skip to content

Commit 6f0579c

Browse files
committed
Fix Travis build error
1 parent 8a1d07f commit 6f0579c

File tree

9 files changed

+22
-24
lines changed

9 files changed

+22
-24
lines changed

src/PhpWord/Element/AbstractContainer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ abstract class AbstractContainer extends AbstractElement
3939
*/
4040
protected function addElement(AbstractElement $element)
4141
{
42-
// $type = basename(get_class($element));
42+
// $type = str_replace('PhpOffice\\PhpWord\\Element\\', '', get_class($element)));
4343
$element->setElementIndex($this->countElements() + 1);
4444
$element->setElementId();
4545
$element->setPhpWord($this->phpWord);

src/PhpWord/Writer/HTML/Element/Element.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,7 @@ public function __construct(HTML $parentWriter, AbstractElement $element, $witho
7373
public function write()
7474
{
7575
$content = '';
76-
$writerClass = substr(get_class($this), 0, strrpos(get_class($this), '\\')) . '\\' .
77-
basename(get_class($this->element));
76+
$writerClass = str_replace('\\Element\\', '\\Writer\\HTML\\Element\\', get_class($this->element));
7877
if (class_exists($writerClass)) {
7978
$writer = new $writerClass($this->parentWriter, $this->element, $this->withoutP);
8079
$content = $writer->write();

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,10 @@
2424
*/
2525
class Container extends \PhpOffice\PhpWord\Writer\Word2007\Element\Container
2626
{
27+
/**
28+
* Namespace; Can't use __NAMESPACE__ in inherited class (ODText)
29+
*
30+
* @var string
31+
*/
32+
protected $namespace = 'PhpOffice\\PhpWord\\Writer\\ODText\\Element';
2733
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ private function writeAutomaticStyles(XMLWriter $xmlWriter, PhpWord $phpWord)
101101
if (preg_match('#^T[0-9]+$#', $styleName) != 0
102102
|| preg_match('#^P[0-9]+$#', $styleName) != 0
103103
) {
104-
$styleClass = 'PhpOffice\\PhpWord\\Writer\\ODText\\Style\\' . basename(get_class($style));
104+
$styleClass = str_replace('\\Style\\', '\\Writer\\ODText\\Style\\', get_class($style));
105105
if (class_exists($styleClass)) {
106106
$styleWriter = new $styleClass($xmlWriter, $style);
107107
$styleWriter->setIsAuto(true);

src/PhpWord/Writer/ODText/Part/Styles.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ public function write()
9191
if (preg_match('#^T[0-9]+$#', $styleName) == 0
9292
&& preg_match('#^P[0-9]+$#', $styleName) == 0
9393
) {
94-
$styleClass = 'PhpOffice\\PhpWord\\Writer\\ODText\\Style\\' . basename(get_class($style));
94+
$styleClass = str_replace('\\Style\\', '\\Writer\\ODText\\Style\\', get_class($style));
9595
if (class_exists($styleClass)) {
9696
$styleWriter = new $styleClass($xmlWriter, $style);
9797
$styleWriter->write();

src/PhpWord/Writer/RTF/Element/Element.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,7 @@ public function __construct(RTF $parentWriter, AbstractElement $element, $withou
6868
public function write()
6969
{
7070
$content = '';
71-
$writerClass = substr(get_class($this), 0, strrpos(get_class($this), '\\')) . '\\' .
72-
basename(get_class($this->element));
71+
$writerClass = str_replace('\\Element\\', '\\Writer\\RTF\\Element\\', get_class($this->element));
7372
if (class_exists($writerClass)) {
7473
$writer = new $writerClass($this->parentWriter, $this->element, $this->withoutP);
7574
$content = $writer->write();

src/PhpWord/Writer/Word2007/Element/AbstractElement.php

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -84,12 +84,7 @@ protected function getXmlWriter()
8484
protected function getElement()
8585
{
8686
if (!is_null($this->element)) {
87-
$elementClass = 'PhpOffice\\PhpWord\\Element\\' . basename(get_class($this->element));
88-
if ($this->element instanceof $elementClass) {
89-
return $this->element;
90-
} else {
91-
throw new Exception('No valid element assigned.');
92-
}
87+
return $this->element;
9388
} else {
9489
throw new Exception('No element assigned.');
9590
}

src/PhpWord/Writer/Word2007/Element/Container.php

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,13 @@
2626
*/
2727
class Container extends AbstractElement
2828
{
29+
/**
30+
* Namespace; Can't use __NAMESPACE__ in inherited class (ODText)
31+
*
32+
* @var string
33+
*/
34+
protected $namespace = 'PhpOffice\\PhpWord\\Writer\\Word2007\\Element';
35+
2936
/**
3037
* Write element
3138
*/
@@ -35,13 +42,12 @@ public function write()
3542
$container = $this->getElement();
3643

3744
// Loop through subelements
38-
$containerClass = basename(get_class($container));
45+
$containerClass = substr(get_class($container), strrpos(get_class($this), '\\') + 1);
3946
$subelements = $container->getElements();
4047
$withoutP = in_array($containerClass, array('TextRun', 'Footnote', 'Endnote', 'TextBox')) ? true : false;
4148
if (count($subelements) > 0) {
4249
foreach ($subelements as $subelement) {
43-
$writerClass = substr(get_class($this), 0, strrpos(get_class($this), '\\')) . '\\' .
44-
basename(get_class($subelement));
50+
$writerClass = str_replace('PhpOffice\\PhpWord\\Element', $this->namespace, get_class($subelement));
4551
if (class_exists($writerClass)) {
4652
$writer = new $writerClass($xmlWriter, $subelement, $withoutP);
4753
$writer->write();
@@ -50,7 +56,7 @@ public function write()
5056
} else {
5157
// Special case for Cell: They have to contain a TextBreak at least
5258
if ($containerClass == 'Cell') {
53-
$writerClass = substr(get_class($this), 0, strrpos(get_class($this), '\\')) . '\\TextBreak';
59+
$writerClass = "{$this->namespace}\\TextBreak";
5460
$writer = new $writerClass($xmlWriter, new TextBreakElement(), $withoutP);
5561
$writer->write();
5662
}

src/PhpWord/Writer/Word2007/Style/AbstractStyle.php

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -75,13 +75,6 @@ protected function getXmlWriter()
7575
*/
7676
protected function getStyle()
7777
{
78-
if (!is_null($this->style)) {
79-
$styleClass = 'PhpOffice\\PhpWord\\Style\\' . basename(get_class($this->style));
80-
if (is_object($this->style) && (!$this->style instanceof $styleClass)) {
81-
throw new Exception('No valid style assigned.');
82-
}
83-
}
84-
8578
return $this->style;
8679
}
8780

0 commit comments

Comments
 (0)