Type checks on style writers
This commit is contained in:
parent
9567c6a972
commit
17e2f02817
|
|
@ -35,6 +35,9 @@ class Font extends AbstractStyle
|
|||
public function write()
|
||||
{
|
||||
$style = $this->getStyle();
|
||||
if (!$style instanceof \PhpOffice\PhpWord\Style\Font) {
|
||||
return;
|
||||
}
|
||||
$css = array();
|
||||
|
||||
$font = $style->getName();
|
||||
|
|
|
|||
|
|
@ -32,6 +32,9 @@ class Image extends AbstractStyle
|
|||
public function write()
|
||||
{
|
||||
$style = $this->getStyle();
|
||||
if (!$style instanceof \PhpOffice\PhpWord\Style\Image) {
|
||||
return;
|
||||
}
|
||||
$css = array();
|
||||
|
||||
$css['width'] = $this->getValueIf($style->getWidth(), $style->getWidth() . 'px');
|
||||
|
|
|
|||
|
|
@ -34,6 +34,9 @@ class Paragraph extends AbstractStyle
|
|||
public function write()
|
||||
{
|
||||
$style = $this->getStyle();
|
||||
if (!$style instanceof \PhpOffice\PhpWord\Style\Paragraph) {
|
||||
return;
|
||||
}
|
||||
$css = array();
|
||||
|
||||
// Alignment
|
||||
|
|
|
|||
|
|
@ -34,7 +34,8 @@ class Font extends AbstractStyle
|
|||
*/
|
||||
public function write()
|
||||
{
|
||||
if (is_null($style = $this->getStyle())) {
|
||||
$style = $this->getStyle();
|
||||
if (!$style instanceof \PhpOffice\PhpWord\Style\Font) {
|
||||
return;
|
||||
}
|
||||
$xmlWriter = $this->getXmlWriter();
|
||||
|
|
|
|||
|
|
@ -34,7 +34,8 @@ class Paragraph extends AbstractStyle
|
|||
*/
|
||||
public function write()
|
||||
{
|
||||
if (is_null($style = $this->getStyle())) {
|
||||
$style = $this->getStyle();
|
||||
if (!$style instanceof \PhpOffice\PhpWord\Style\Paragraph) {
|
||||
return;
|
||||
}
|
||||
$xmlWriter = $this->getXmlWriter();
|
||||
|
|
|
|||
|
|
@ -31,7 +31,8 @@ class Cell extends AbstractStyle
|
|||
*/
|
||||
public function write()
|
||||
{
|
||||
if (is_null($style = $this->getStyle())) {
|
||||
$style = $this->getStyle();
|
||||
if (!$style instanceof \PhpOffice\PhpWord\Style\Cell) {
|
||||
return;
|
||||
}
|
||||
$xmlWriter = $this->getXmlWriter();
|
||||
|
|
|
|||
|
|
@ -57,7 +57,8 @@ class Font extends AbstractStyle
|
|||
*/
|
||||
private function writeStyle()
|
||||
{
|
||||
if (is_null($style = $this->getStyle())) {
|
||||
$style = $this->getStyle();
|
||||
if (!$style instanceof \PhpOffice\PhpWord\Style\Font) {
|
||||
return;
|
||||
}
|
||||
$xmlWriter = $this->getXmlWriter();
|
||||
|
|
|
|||
|
|
@ -38,9 +38,11 @@ class Image extends AbstractStyle
|
|||
*/
|
||||
public function write()
|
||||
{
|
||||
if (!is_null($this->getStyle())) {
|
||||
$this->writeStyle();
|
||||
$style = $this->getStyle();
|
||||
if (!$style instanceof \PhpOffice\PhpWord\Style\Image) {
|
||||
return;
|
||||
}
|
||||
$this->writeStyle();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -29,7 +29,8 @@ class Indentation extends AbstractStyle
|
|||
*/
|
||||
public function write()
|
||||
{
|
||||
if (is_null($style = $this->getStyle())) {
|
||||
$style = $this->getStyle();
|
||||
if (!$style instanceof \PhpOffice\PhpWord\Style\Indentation) {
|
||||
return;
|
||||
}
|
||||
$xmlWriter = $this->getXmlWriter();
|
||||
|
|
|
|||
|
|
@ -31,7 +31,8 @@ class LineNumbering extends AbstractStyle
|
|||
*/
|
||||
public function write()
|
||||
{
|
||||
if (is_null($style = $this->getStyle())) {
|
||||
$style = $this->getStyle();
|
||||
if (!$style instanceof \PhpOffice\PhpWord\Style\LineNumbering) {
|
||||
return;
|
||||
}
|
||||
$xmlWriter = $this->getXmlWriter();
|
||||
|
|
|
|||
|
|
@ -29,14 +29,14 @@ class MarginBorder extends AbstractStyle
|
|||
*
|
||||
* @var int[]
|
||||
*/
|
||||
private $sizes;
|
||||
private $sizes = array();
|
||||
|
||||
/**
|
||||
* Colors
|
||||
*
|
||||
* @var string[]
|
||||
*/
|
||||
private $colors;
|
||||
private $colors = array();
|
||||
|
||||
/**
|
||||
* Other attributes
|
||||
|
|
|
|||
|
|
@ -66,7 +66,8 @@ class Paragraph extends AbstractStyle
|
|||
*/
|
||||
private function writeStyle()
|
||||
{
|
||||
if (is_null($style = $this->getStyle())) {
|
||||
$style = $this->getStyle();
|
||||
if (!$style instanceof \PhpOffice\PhpWord\Style\Paragraph) {
|
||||
return;
|
||||
}
|
||||
$xmlWriter = $this->getXmlWriter();
|
||||
|
|
|
|||
|
|
@ -31,7 +31,8 @@ class Section extends AbstractStyle
|
|||
*/
|
||||
public function write()
|
||||
{
|
||||
if (is_null($style = $this->getStyle())) {
|
||||
$style = $this->getStyle();
|
||||
if (!$style instanceof \PhpOffice\PhpWord\Style\Section) {
|
||||
return;
|
||||
}
|
||||
$xmlWriter = $this->getXmlWriter();
|
||||
|
|
|
|||
|
|
@ -29,7 +29,8 @@ class Shading extends AbstractStyle
|
|||
*/
|
||||
public function write()
|
||||
{
|
||||
if (is_null($style = $this->getStyle())) {
|
||||
$style = $this->getStyle();
|
||||
if (!$style instanceof \PhpOffice\PhpWord\Style\Shading) {
|
||||
return;
|
||||
}
|
||||
$xmlWriter = $this->getXmlWriter();
|
||||
|
|
|
|||
|
|
@ -29,7 +29,8 @@ class Spacing extends AbstractStyle
|
|||
*/
|
||||
public function write()
|
||||
{
|
||||
if (is_null($style = $this->getStyle())) {
|
||||
$style = $this->getStyle();
|
||||
if (!$style instanceof \PhpOffice\PhpWord\Style\Spacing) {
|
||||
return;
|
||||
}
|
||||
$xmlWriter = $this->getXmlWriter();
|
||||
|
|
|
|||
|
|
@ -29,7 +29,8 @@ class Tab extends AbstractStyle
|
|||
*/
|
||||
public function write()
|
||||
{
|
||||
if (is_null($style = $this->getStyle())) {
|
||||
$style = $this->getStyle();
|
||||
if (!$style instanceof \PhpOffice\PhpWord\Style\Tab) {
|
||||
return;
|
||||
}
|
||||
$xmlWriter = $this->getXmlWriter();
|
||||
|
|
|
|||
|
|
@ -36,7 +36,8 @@ class Table extends AbstractStyle
|
|||
*/
|
||||
public function write()
|
||||
{
|
||||
if (is_null($style = $this->getStyle())) {
|
||||
$style = $this->getStyle();
|
||||
if (!$style instanceof \PhpOffice\PhpWord\Style\Table) {
|
||||
return;
|
||||
}
|
||||
$xmlWriter = $this->getXmlWriter();
|
||||
|
|
|
|||
|
|
@ -31,10 +31,12 @@ class TextBox extends Image
|
|||
*/
|
||||
public function write()
|
||||
{
|
||||
if (!is_null($this->getStyle())) {
|
||||
$this->writeStyle();
|
||||
$this->writeBorder();
|
||||
$style = $this->getStyle();
|
||||
if (!$style instanceof \PhpOffice\PhpWord\Style\TextBox) {
|
||||
return;
|
||||
}
|
||||
$this->writeStyle();
|
||||
$this->writeBorder();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -0,0 +1,39 @@
|
|||
<?php
|
||||
/**
|
||||
* This file is part of PHPWord - A pure PHP library for reading and writing
|
||||
* word processing documents.
|
||||
*
|
||||
* PHPWord is free software distributed under the terms of the GNU Lesser
|
||||
* General Public License version 3 as published by the Free Software Foundation.
|
||||
*
|
||||
* For the full copyright and license information, please read the LICENSE
|
||||
* file that was distributed with this source code. For the full list of
|
||||
* contributors, visit https://github.com/PHPOffice/PHPWord/contributors.
|
||||
*
|
||||
* @link https://github.com/PHPOffice/PHPWord
|
||||
* @copyright 2010-2014 PHPWord contributors
|
||||
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
|
||||
*/
|
||||
namespace PhpOffice\PhpWord\Tests\Writer\HTML;
|
||||
|
||||
use PhpOffice\PhpWord\Shared\XMLWriter;
|
||||
|
||||
/**
|
||||
* Test class for PhpOffice\PhpWord\Writer\HTML\Style subnamespace
|
||||
*/
|
||||
class StyleTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* Test empty styles
|
||||
*/
|
||||
public function testEmptyStyles()
|
||||
{
|
||||
$styles = array('Font', 'Paragraph', 'Image');
|
||||
foreach ($styles as $style) {
|
||||
$objectClass = 'PhpOffice\\PhpWord\\Writer\\HTML\\Style\\' . $style;
|
||||
$object = new $objectClass();
|
||||
|
||||
$this->assertEquals('', $object->write());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,41 @@
|
|||
<?php
|
||||
/**
|
||||
* This file is part of PHPWord - A pure PHP library for reading and writing
|
||||
* word processing documents.
|
||||
*
|
||||
* PHPWord is free software distributed under the terms of the GNU Lesser
|
||||
* General Public License version 3 as published by the Free Software Foundation.
|
||||
*
|
||||
* For the full copyright and license information, please read the LICENSE
|
||||
* file that was distributed with this source code. For the full list of
|
||||
* contributors, visit https://github.com/PHPOffice/PHPWord/contributors.
|
||||
*
|
||||
* @link https://github.com/PHPOffice/PHPWord
|
||||
* @copyright 2010-2014 PHPWord contributors
|
||||
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
|
||||
*/
|
||||
namespace PhpOffice\PhpWord\Tests\Writer\ODText;
|
||||
|
||||
use PhpOffice\PhpWord\Shared\XMLWriter;
|
||||
|
||||
/**
|
||||
* Test class for PhpOffice\PhpWord\Writer\ODText\Style subnamespace
|
||||
*/
|
||||
class StyleTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* Test empty styles
|
||||
*/
|
||||
public function testEmptyStyles()
|
||||
{
|
||||
$styles = array('Font', 'Paragraph');
|
||||
foreach ($styles as $style) {
|
||||
$objectClass = 'PhpOffice\\PhpWord\\Writer\\ODText\\Style\\' . $style;
|
||||
$xmlWriter = new XMLWriter();
|
||||
$object = new $objectClass($xmlWriter);
|
||||
$object->write();
|
||||
|
||||
$this->assertEquals('', $xmlWriter->getData());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,39 @@
|
|||
<?php
|
||||
/**
|
||||
* This file is part of PHPWord - A pure PHP library for reading and writing
|
||||
* word processing documents.
|
||||
*
|
||||
* PHPWord is free software distributed under the terms of the GNU Lesser
|
||||
* General Public License version 3 as published by the Free Software Foundation.
|
||||
*
|
||||
* For the full copyright and license information, please read the LICENSE
|
||||
* file that was distributed with this source code. For the full list of
|
||||
* contributors, visit https://github.com/PHPOffice/PHPWord/contributors.
|
||||
*
|
||||
* @link https://github.com/PHPOffice/PHPWord
|
||||
* @copyright 2010-2014 PHPWord contributors
|
||||
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
|
||||
*/
|
||||
namespace PhpOffice\PhpWord\Tests\Writer\RTF;
|
||||
|
||||
use PhpOffice\PhpWord\Shared\XMLWriter;
|
||||
|
||||
/**
|
||||
* Test class for PhpOffice\PhpWord\Writer\RTF\Style subnamespace
|
||||
*/
|
||||
class StyleTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* Test empty styles
|
||||
*/
|
||||
public function testEmptyStyles()
|
||||
{
|
||||
$styles = array('Font', 'Paragraph');
|
||||
foreach ($styles as $style) {
|
||||
$objectClass = 'PhpOffice\\PhpWord\\Writer\\RTF\\Style\\' . $style;
|
||||
$object = new $objectClass();
|
||||
|
||||
$this->assertEquals('', $object->write());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,44 @@
|
|||
<?php
|
||||
/**
|
||||
* This file is part of PHPWord - A pure PHP library for reading and writing
|
||||
* word processing documents.
|
||||
*
|
||||
* PHPWord is free software distributed under the terms of the GNU Lesser
|
||||
* General Public License version 3 as published by the Free Software Foundation.
|
||||
*
|
||||
* For the full copyright and license information, please read the LICENSE
|
||||
* file that was distributed with this source code. For the full list of
|
||||
* contributors, visit https://github.com/PHPOffice/PHPWord/contributors.
|
||||
*
|
||||
* @link https://github.com/PHPOffice/PHPWord
|
||||
* @copyright 2010-2014 PHPWord contributors
|
||||
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
|
||||
*/
|
||||
namespace PhpOffice\PhpWord\Tests\Writer\Word2007;
|
||||
|
||||
use PhpOffice\PhpWord\Shared\XMLWriter;
|
||||
|
||||
/**
|
||||
* Test class for PhpOffice\PhpWord\Writer\Word2007\Style subnamespace
|
||||
*/
|
||||
class StyleTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* Test empty styles
|
||||
*/
|
||||
public function testEmptyStyles()
|
||||
{
|
||||
$styles = array(
|
||||
'Cell', 'Font', 'Image', 'Indentation', 'LineNumbering',
|
||||
'Paragraph', 'Section', 'Shading', 'Spacing', 'Tab', 'Table', 'TextBox'
|
||||
);
|
||||
foreach ($styles as $style) {
|
||||
$objectClass = 'PhpOffice\\PhpWord\\Writer\\Word2007\\Style\\' . $style;
|
||||
$xmlWriter = new XMLWriter();
|
||||
$object = new $objectClass($xmlWriter);
|
||||
$object->write();
|
||||
|
||||
$this->assertEquals('', $xmlWriter->getData());
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue