Add Abstract- prefix and -Interface suffix for corresponding classes

This commit is contained in:
Ivan Lanin 2014-04-08 00:23:49 +07:00
parent b594e32f04
commit f1108c48e6
57 changed files with 284 additions and 310 deletions

View File

@ -39,8 +39,8 @@ This is the changelog between releases of PHPWord. Releases are listed in revers
- `createHeader` replaced by `addHeader`
- `createFooter` replaced by `addFooter`
- `createSection` replaced by `addSection`
- `Element\Footnote::getReferenceId` replaced by `Container\Container::getRelationId`
- `Element\Footnote::setReferenceId` replaced by `Container\Container::setRelationId`
- `Element\Footnote::getReferenceId` replaced by `Element\AbstractElement::getRelationId`
- `Element\Footnote::setReferenceId` replaced by `Element\AbstractElement::setRelationId`
- `Footnote::addFootnoteLinkElement` replaced by `Media::addElement`
- `Footnote::getFootnoteLinkElements` replaced by `Media::getElements`
- All current methods on `Media`
@ -48,14 +48,14 @@ This is the changelog between releases of PHPWord. Releases are listed in revers
### Miscellaneous
- Documentation: Simplify page level docblock - @ivanlanin GH-179
- Writer: Refactor writer classes and make a new Writer abstract class - @ivanlanin GH-160
- Reader: Rename AbstractReader > Reader - @ivanlanin
- General: Refactor folders: Element, Container, and Exception - @ivanlanin GH-187
- Writer: Refactor writer classes and make a new AbstractWriter abstract class - @ivanlanin GH-160
- General: Refactor folders: Element and Exception - @ivanlanin GH-187
- General: Remove legacy HashTable and ZipStreamWrapper and all related properties/methods - @ivanlanin GH-187
- Container: Create new Container abstract class - @ivanlanin GH-187
- Element: Create new Element abstract class - @ivanlanin GH-187
- Element: Create new AbstractElement abstract class - @ivanlanin GH-187
- Media: Refactor media class to use one method for all docPart (section, header, footer, footnote) - @ivanlanin GH-187
- General: Remove underscore prefix from all private properties name
- General: Remove underscore prefix from all private properties name - @ivanlanin GH-187
- General: Move Section Settings to Style\Section - @ivanlanin GH-187
- 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
## 0.9.1 - 27 Mar 2014

View File

@ -7,7 +7,7 @@
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
*/
namespace PhpOffice\PhpWord\Container;
namespace PhpOffice\PhpWord\Element;
use PhpOffice\PhpWord\Exception\InvalidImageException;
use PhpOffice\PhpWord\Exception\InvalidObjectException;
@ -35,7 +35,7 @@ use PhpOffice\PhpWord\Element\CheckBox;
*
* @since 0.9.2
*/
abstract class Container extends Element
abstract class AbstractElement
{
/**
* Container type section|header|footer|cell|textrun|footnote
@ -51,6 +51,28 @@ abstract class Container extends Element
*/
protected $sectionId;
/**
* Document part type: section|header|footer
*
* Used by textrun and cell container to determine where the element is
* located because it will affect the availability of other element,
* e.g. footnote will not be available when $docPart is header or footer.
*
* @var string
*/
private $docPart = 'section';
/**
* Document part Id
*
* For header and footer, this will be = ($sectionId - 1) * 3 + $index
* because the max number of header/footer in every page is 3, i.e.
* AUTO, FIRST, and EVEN (AUTO = ODD)
*
* @var integer
*/
private $docPartId = 1;
/**
* Elements collection
*
@ -340,6 +362,38 @@ abstract class Container extends Element
return $this->sectionId;
}
/**
* Set doc part
*
* @param string $docPart
* @param integer $docPartId
*/
public function setDocPart($docPart, $docPartId = 1)
{
$this->docPart = $docPart;
$this->docPartId = $docPartId;
}
/**
* Get doc part
*
* @return string
*/
public function getDocPart()
{
return $this->docPart;
}
/**
* Get doc part Id
*
* @return integer
*/
public function getDocPartId()
{
return $this->docPartId;
}
/**
* Get all elements
*
@ -372,6 +426,106 @@ abstract class Container extends Element
$this->relationId = $rId;
}
/**
* Check if element is located in section doc part (as opposed to header/footer)
*
* @return boolean
*/
public function isInSection()
{
return ($this->docPart == 'section');
}
/**
* Set style value
*
* @param mixed $styleObject Style object
* @param mixed $styleValue Style value
* @param boolean $returnObject Always return object
*/
protected function setStyle($styleObject, $styleValue = null, $returnObject = false)
{
if (!is_null($styleValue) && is_array($styleValue)) {
foreach ($styleValue as $key => $value) {
if (substr($key, 0, 1) == '_') {
$key = substr($key, 1);
}
$styleObject->setStyleValue($key, $value);
}
$style = $styleObject;
} else {
$style = $returnObject ? $styleObject : $styleValue;
}
return $style;
}
/**
* Check if a method is allowed for the current container
*
* @param string $method
* @return boolean
*/
private function checkValidity($method)
{
// Valid containers for each element
$allContainers = array('section', 'header', 'footer', 'cell', 'textrun', 'footnote');
$validContainers = array(
'text' => $allContainers,
'link' => $allContainers,
'textbreak' => $allContainers,
'image' => $allContainers,
'object' => $allContainers,
'textrun' => array('section', 'header', 'footer', 'cell'),
'listitem' => array('section', 'header', 'footer', 'cell'),
'checkbox' => array('section', 'header', 'footer', 'cell'),
'table' => array('section', 'header', 'footer'),
'footnote' => array('section', 'textrun', 'cell'),
'preservetext' => array('header', 'footer', 'cell'),
'relationid' => array('header', 'footer', 'footnote'),
'title' => array('section'),
);
// Special condition, e.g. preservetext can only exists in cell when
// the cell is located in header or footer
$validContainerInContainers = array(
'preservetext' => array(array('cell'), array('header', 'footer')),
'footnote' => array(array('cell', 'textrun'), array('section')),
);
// Check if a method is valid for current container
if (array_key_exists($method, $validContainers)) {
if (!in_array($this->container, $validContainers[$method])) {
throw new \BadMethodCallException();
}
}
// Check if a method is valid for current container, located in other container
if (array_key_exists($method, $validContainerInContainers)) {
$rules = $validContainerInContainers[$method];
$containers = $rules[0];
$allowedDocParts = $rules[1];
foreach ($containers as $container) {
if ($this->container == $container && !in_array($this->getDocPart(), $allowedDocParts)) {
throw new \BadMethodCallException();
}
}
}
return true;
}
/**
* Return element location in document: section, headerx, or footerx
*/
private function checkElementDocPart()
{
$isCellTextrun = in_array($this->container, array('cell', 'textrun'));
$docPart = $isCellTextrun ? $this->getDocPart() : $this->container;
$docPartId = $isCellTextrun ? $this->getDocPartId() : $this->sectionId;
$inHeaderFooter = ($docPart == 'header' || $docPart == 'footer');
return $inHeaderFooter ? $docPart . $docPartId : $docPart;
}
/**
* Add memory image element
*
@ -408,71 +562,4 @@ abstract class Container extends Element
{
return $this->addFootnote($paragraphStyle);
}
/**
* Check if a method is allowed for the current container
*
* @param string $method
* @return boolean
*/
private function checkValidity($method)
{
// Empty array means the element can be accepted by all containers
$validContainers = array(
'text' => array(),
'link' => array(),
'textbreak' => array(),
'image' => array(),
'object' => array(),
'textrun' => array('section', 'header', 'footer', 'cell'),
'listitem' => array('section', 'header', 'footer', 'cell'),
'checkbox' => array('section', 'header', 'footer', 'cell'),
'table' => array('section', 'header', 'footer'),
'footnote' => array('section', 'textrun', 'cell'),
'preservetext' => array('header', 'footer', 'cell'),
'relationid' => array('header', 'footer', 'footnote'),
'title' => array('section'),
);
// Special condition, e.g. preservetext can only exists in cell when
// the cell is located in header or footer
$validContainerInContainers = array(
'preservetext' => array(array('cell'), array('header', 'footer')),
'footnote' => array(array('cell', 'textrun'), array('section')),
);
// Check if a method is valid for current container
if (array_key_exists($method, $validContainers)) {
if (!empty($validContainers[$method])) {
if (!in_array($this->container, $validContainers[$method])) {
throw new \BadMethodCallException();
}
}
}
// Check if a method is valid for current container, located in other container
if (array_key_exists($method, $validContainerInContainers)) {
$rules = $validContainerInContainers[$method];
$containers = $rules[0];
$allowedDocParts = $rules[1];
foreach ($containers as $container) {
if ($this->container == $container && !in_array($this->getDocPart(), $allowedDocParts)) {
throw new \BadMethodCallException();
}
}
}
return true;
}
/**
* Return element location in document: section, headerx, or footerx
*/
private function checkElementDocPart()
{
$isCellTextrun = in_array($this->container, array('cell', 'textrun'));
$docPart = $isCellTextrun ? $this->getDocPart() : $this->container;
$docPartId = $isCellTextrun ? $this->getDocPartId() : $this->sectionId;
$inHeaderFooter = ($docPart == 'header' || $docPart == 'footer');
return $inHeaderFooter ? $docPart . $docPartId : $docPart;
}
}

View File

@ -9,13 +9,12 @@
namespace PhpOffice\PhpWord\Element;
use PhpOffice\PhpWord\Container\Container;
use PhpOffice\PhpWord\Style\Cell as CellStyle;
/**
* Table cell element
*/
class Cell extends Container
class Cell extends AbstractElement
{
/**
* Cell width

View File

@ -15,7 +15,7 @@ use PhpOffice\PhpWord\Style\Paragraph;
/**
* Check box element
*/
class CheckBox extends Element
class CheckBox extends AbstractElement
{
/**
* Name content

View File

@ -1,106 +0,0 @@
<?php
/**
* PHPWord
*
* @link https://github.com/PHPOffice/PHPWord
* @copyright 2014 PHPWord
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
*/
namespace PhpOffice\PhpWord\Element;
/**
* Abstract element class
*
* @since 0.9.2
*/
abstract class Element
{
/**
* Document part type: section|header|footer
*
* Used by textrun and cell container to determine where the element is
* located because it will affect the availability of other element,
* e.g. footnote will not be available when $docPart is header or footer.
*
* @var string
*/
private $docPart = 'section';
/**
* Document part Id
*
* For header and footer, this will be = ($sectionId - 1) * 3 + $index
* because the max number of header/footer in every page is 3, i.e.
* AUTO, FIRST, and EVEN (AUTO = ODD)
*
* @var integer
*/
private $docPartId = 1;
/**
* Set style value
*
* @param mixed $styleObject Style object
* @param mixed $styleValue Style value
* @param boolean $returnObject Always return object
*/
protected function setStyle($styleObject, $styleValue = null, $returnObject = false)
{
if (!is_null($styleValue) && is_array($styleValue)) {
foreach ($styleValue as $key => $value) {
if (substr($key, 0, 1) == '_') {
$key = substr($key, 1);
}
$styleObject->setStyleValue($key, $value);
}
$style = $styleObject;
} else {
$style = $returnObject ? $styleObject : $styleValue;
}
return $style;
}
/**
* Set doc part
*
* @param string $docPart
* @param integer $docPartId
*/
public function setDocPart($docPart, $docPartId = 1)
{
$this->docPart = $docPart;
$this->docPartId = $docPartId;
}
/**
* Get doc part
*
* @return string
*/
public function getDocPart()
{
return $this->docPart;
}
/**
* Get doc part Id
*
* @return integer
*/
public function getDocPartId()
{
return $this->docPartId;
}
/**
* Check if element is located in section doc part (as opposed to header/footer)
*
* @return boolean
*/
public function isInSection()
{
return ($this->docPart == 'section');
}
}

View File

@ -7,12 +7,12 @@
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
*/
namespace PhpOffice\PhpWord\Container;
namespace PhpOffice\PhpWord\Element;
/**
* Footer element
*/
class Footer extends Container
class Footer extends AbstractElement
{
const AUTO = 'default'; // default and odd pages
const FIRST = 'first';

View File

@ -9,13 +9,12 @@
namespace PhpOffice\PhpWord\Element;
use PhpOffice\PhpWord\Container\Container;
use PhpOffice\PhpWord\Style\Paragraph;
/**
* Footnote element
*/
class Footnote extends Container
class Footnote extends AbstractElement
{
/**
* Paragraph style

View File

@ -7,14 +7,14 @@
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
*/
namespace PhpOffice\PhpWord\Container;
namespace PhpOffice\PhpWord\Element;
use PhpOffice\PhpWord\Element\Image;
/**
* Header element
*/
class Header extends Container
class Header extends AbstractElement
{
/**
* Header types constants

View File

@ -16,7 +16,7 @@ use PhpOffice\PhpWord\Style\Image as ImageStyle;
/**
* Image element
*/
class Image extends Element
class Image extends AbstractElement
{
/**
* Image source
@ -138,9 +138,6 @@ class Image extends Element
$this->source = $source;
$this->isWatermark = $isWatermark;
$this->style = $this->setStyle(new ImageStyle(), $style, true);
if (isset($style['wrappingStyle'])) {
$this->style->setWrappingStyle($style['wrappingStyle']);
}
if ($this->style->getWidth() == null && $this->style->getHeight() == null) {
$this->style->setWidth($imgData[0]);
$this->style->setHeight($imgData[1]);

View File

@ -15,7 +15,7 @@ use PhpOffice\PhpWord\Style\Paragraph;
/**
* Link element
*/
class Link extends Element
class Link extends AbstractElement
{
/**
* Link source

View File

@ -14,7 +14,7 @@ use PhpOffice\PhpWord\Style\ListItem as ListItemStyle;
/**
* List item element
*/
class ListItem extends Element
class ListItem extends AbstractElement
{
/**
* ListItem Style

View File

@ -14,7 +14,7 @@ use PhpOffice\PhpWord\Style\Image as ImageStyle;
/**
* Object element
*/
class Object extends Element
class Object extends AbstractElement
{
/**
* Ole-Object Src

View File

@ -12,7 +12,7 @@ namespace PhpOffice\PhpWord\Element;
/**
* Page break element
*/
class PageBreak extends Element
class PageBreak extends AbstractElement
{
/**
* Create new page break

View File

@ -15,7 +15,7 @@ use PhpOffice\PhpWord\Style\Paragraph;
/**
* Preserve text/field element
*/
class PreserveText extends Element
class PreserveText extends AbstractElement
{
/**
* Text content

View File

@ -14,7 +14,7 @@ use PhpOffice\PhpWord\Style\Row as RowStyle;
/**
* Table row element
*/
class Row extends Element
class Row extends AbstractElement
{
/**
* Row height

View File

@ -7,24 +7,24 @@
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
*/
namespace PhpOffice\PhpWord\Container;
namespace PhpOffice\PhpWord\Element;
use PhpOffice\PhpWord\Exception\Exception;
use PhpOffice\PhpWord\TOC;
use PhpOffice\PhpWord\Container\Footer;
use PhpOffice\PhpWord\Container\Header;
use PhpOffice\PhpWord\Container\Settings;
use PhpOffice\PhpWord\Element\Footer;
use PhpOffice\PhpWord\Element\Header;
use PhpOffice\PhpWord\Element\PageBreak;
use PhpOffice\PhpWord\Style\Section as SectionSettings;
/**
* Section
*/
class Section extends Container
class Section extends AbstractElement
{
/**
* Section settings
*
* @var Settings
* @var SectionSettings
*/
private $settings;
@ -53,7 +53,7 @@ class Section extends Container
$this->container = 'section';
$this->sectionId = $sectionCount;
$this->setDocPart($this->container, $this->sectionId);
$this->settings = new Settings();
$this->settings = new SectionSettings();
$this->setSettings($settings);
}
@ -77,7 +77,7 @@ class Section extends Container
/**
* Get Section Settings
*
* @return Settings
* @return SectionSettings
*/
public function getSettings()
{
@ -181,7 +181,7 @@ class Section extends Container
private function addHeaderFooter($type = Header::AUTO, $header = true)
{
$collectionArray = $header ? 'headers' : 'footers';
$containerClass = 'PhpOffice\\PhpWord\\Container\\';
$containerClass = 'PhpOffice\\PhpWord\\Element\\';
$containerClass .= ($header ? 'Header' : 'Footer');
$collection = &$this->$collectionArray;

View File

@ -15,7 +15,7 @@ use PhpOffice\PhpWord\Style\Table as TableStyle;
/**
* Table element
*/
class Table extends Element
class Table extends AbstractElement
{
/**
* Table style

View File

@ -15,7 +15,7 @@ use PhpOffice\PhpWord\Style\Paragraph;
/**
* Text element
*/
class Text extends Element
class Text extends AbstractElement
{
/**
* Text content

View File

@ -15,7 +15,7 @@ use PhpOffice\PhpWord\Style\Paragraph;
/**
* Text break element
*/
class TextBreak extends Element
class TextBreak extends AbstractElement
{
/**
* Paragraph style

View File

@ -9,13 +9,12 @@
namespace PhpOffice\PhpWord\Element;
use PhpOffice\PhpWord\Container\Container;
use PhpOffice\PhpWord\Style\Paragraph;
/**
* Textrun/paragraph element
*/
class TextRun extends Container
class TextRun extends AbstractElement
{
/**
* Paragraph style

View File

@ -12,7 +12,7 @@ namespace PhpOffice\PhpWord\Element;
/**
* Title element
*/
class Title extends Element
class Title extends AbstractElement
{
/**
* Title Text content

View File

@ -21,12 +21,12 @@ abstract class IOFactory
*
* @param \PhpOffice\PhpWord\PhpWord $phpWord
* @param string $name
* @return \PhpOffice\PhpWord\Writer\IWriter
* @return \PhpOffice\PhpWord\Writer\WriterInterface
* @throws Exception
*/
public static function createWriter(PhpWord $phpWord, $name = 'Word2007')
{
if ($name !== 'IWriter' && $name !== 'ODText' && $name !== 'RTF' && $name !== 'Word2007') {
if ($name !== 'WriterInterface' && $name !== 'ODText' && $name !== 'RTF' && $name !== 'Word2007') {
throw new Exception("\"{$name}\" is not a valid writer.");
}
@ -38,12 +38,12 @@ abstract class IOFactory
* Create new reader
*
* @param string $name
* @return \PhpOffice\PhpWord\Reader\IReader
* @return \PhpOffice\PhpWord\Reader\ReaderInterface
* @throws Exception
*/
public static function createReader($name = 'Word2007')
{
if ($name !== 'IReader' && $name !== 'Word2007') {
if ($name !== 'ReaderInterface' && $name !== 'Word2007') {
throw new Exception("\"{$name}\" is not a valid reader.");
}

View File

@ -11,7 +11,7 @@ namespace PhpOffice\PhpWord;
use PhpOffice\PhpWord\DocumentProperties;
use PhpOffice\PhpWord\Exception\Exception;
use PhpOffice\PhpWord\Container\Section;
use PhpOffice\PhpWord\Element\Section;
use PhpOffice\PhpWord\Style;
use PhpOffice\PhpWord\Template;
@ -217,7 +217,7 @@ class PhpWord
/**
* Get all sections
*
* @return \PhpOffice\PhpWord\Container\Section[]
* @return \PhpOffice\PhpWord\Element\Section[]
*/
public function getSections()
{

View File

@ -16,7 +16,7 @@ use PhpOffice\PhpWord\Exception\Exception;
*
* @codeCoverageIgnore Abstract class
*/
abstract class Reader implements IReader
abstract class AbstractReader implements ReaderInterface
{
/**
* Read data only?
@ -47,7 +47,7 @@ abstract class Reader implements IReader
* Set read data only
*
* @param bool $pValue
* @return \PhpOffice\PhpWord\Reader\IReader
* @return \PhpOffice\PhpWord\Reader\ReaderInterface
*/
public function setReadDataOnly($pValue = true)
{
@ -77,7 +77,7 @@ abstract class Reader implements IReader
}
/**
* Can the current IReader read the file?
* Can the current ReaderInterface read the file?
*
* @param string $pFilename
* @return bool

View File

@ -12,10 +12,10 @@ namespace PhpOffice\PhpWord\Reader;
/**
* Reader interface
*/
interface IReader
interface ReaderInterface
{
/**
* Can the current IReader read the file?
* Can the current ReaderInterface read the file?
*
* @param string $pFilename
* @return boolean

View File

@ -17,10 +17,10 @@ use PhpOffice\PhpWord\Exception\Exception;
/**
* Reader for Word2007
*/
class Word2007 extends Reader implements IReader
class Word2007 extends AbstractReader implements ReaderInterface
{
/**
* Can the current IReader read the file?
* Can the current ReaderInterface read the file?
*
* @param string $pFilename
* @return bool

View File

@ -7,12 +7,12 @@
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
*/
namespace PhpOffice\PhpWord\Container;
namespace PhpOffice\PhpWord\Style;
/**
* Section settings
*/
class Settings
class Section
{
/**
* Default Page Size Width

View File

@ -17,7 +17,7 @@ use PhpOffice\PhpWord\PhpWord;
*
* @since 0.9.2
*/
abstract class Writer implements IWriter
abstract class AbstractWriter implements WriterInterface
{
/**
* PHPWord object

View File

@ -21,7 +21,7 @@ use PhpOffice\PhpWord\Writer\ODText\Styles;
/**
* ODText writer
*/
class ODText extends Writer implements IWriter
class ODText extends AbstractWriter implements WriterInterface
{
/**
* Create new ODText writer

View File

@ -12,6 +12,6 @@ namespace PhpOffice\PhpWord\Writer\ODText;
/**
* ODText writer part abstract
*/
abstract class WriterPart extends \PhpOffice\PhpWord\Writer\Word2007\WriterPart
abstract class AbstractWriterPart extends \PhpOffice\PhpWord\Writer\Word2007\AbstractWriterPart
{
}

View File

@ -29,7 +29,7 @@ use PhpOffice\PhpWord\TOC;
/**
* ODText content part writer
*/
class Content extends WriterPart
class Content extends AbstractWriterPart
{
/**
* Write content file to XML format

View File

@ -15,7 +15,7 @@ use PhpOffice\PhpWord\PhpWord;
/**
* ODText manifest part writer
*/
class Manifest extends WriterPart
class Manifest extends AbstractWriterPart
{
/**
* Write Manifest file to XML format

View File

@ -14,7 +14,7 @@ use PhpOffice\PhpWord\PhpWord;
/**
* ODText meta part writer
*/
class Meta extends WriterPart
class Meta extends AbstractWriterPart
{
/**
* Write Meta file to XML format

View File

@ -14,7 +14,7 @@ use PhpOffice\PhpWord\PhpWord;
/**
* ODText mimetype part writer
*/
class Mimetype extends WriterPart
class Mimetype extends AbstractWriterPart
{
/**
* Write Mimetype to Text format

View File

@ -18,7 +18,7 @@ use PhpOffice\PhpWord\Style\Table;
/**
* ODText styloes part writer
*/
class Styles extends WriterPart
class Styles extends AbstractWriterPart
{
/**
* Write Styles file to XML format

View File

@ -29,7 +29,7 @@ use PhpOffice\PhpWord\TOC;
/**
* RTF writer
*/
class RTF extends Writer implements IWriter
class RTF extends AbstractWriter implements WriterInterface
{
/**
* Color register

View File

@ -26,7 +26,7 @@ use PhpOffice\PhpWord\Writer\Word2007\Styles;
/**
* Word2007 writer
*/
class Word2007 extends Writer implements IWriter
class Word2007 extends AbstractWriter implements WriterInterface
{
/**
* Content types values
@ -229,7 +229,7 @@ class Word2007 extends Writer implements IWriter
/**
* Add header/footer content
*
* @param \PhpOffice\PhpWord\Container\Section $section
* @param \PhpOffice\PhpWord\Element\Section $section
* @param mixed $objZip
* @param string $elmType
* @param integer $rID

View File

@ -10,27 +10,27 @@
namespace PhpOffice\PhpWord\Writer\Word2007;
use PhpOffice\PhpWord\Exception\Exception;
use PhpOffice\PhpWord\Writer\IWriter;
use PhpOffice\PhpWord\Writer\WriterInterface;
use PhpOffice\PhpWord\Shared\XMLWriter;
/**
* Word2007 writer part abstract class
*/
abstract class WriterPart
abstract class AbstractWriterPart
{
/**
* Parent writer
*
* @var IWriter
* @var WriterInterface
*/
protected $parentWriter;
/**
* Set parent writer
*
* @param IWriter $pWriter
* @param WriterInterface $pWriter
*/
public function setParentWriter(IWriter $pWriter = null)
public function setParentWriter(WriterInterface $pWriter = null)
{
$this->parentWriter = $pWriter;
}
@ -38,7 +38,7 @@ abstract class WriterPart
/**
* Get parent writer
*
* @return IWriter
* @return WriterInterface
* @throws Exception
*/
public function getParentWriter()
@ -46,7 +46,7 @@ abstract class WriterPart
if (!is_null($this->parentWriter)) {
return $this->parentWriter;
} else {
throw new Exception("No parent IWriter assigned.");
throw new Exception("No parent WriterInterface assigned.");
}
}

View File

@ -11,7 +11,7 @@ namespace PhpOffice\PhpWord\Writer\Word2007;
use PhpOffice\PhpWord\Exception\Exception;
use PhpOffice\PhpWord\PhpWord;
use PhpOffice\PhpWord\Container\Container;
use PhpOffice\PhpWord\Element\AbstractElement;
use PhpOffice\PhpWord\Element\Text;
use PhpOffice\PhpWord\Element\TextRun;
use PhpOffice\PhpWord\Element\Link;
@ -37,7 +37,7 @@ use PhpOffice\PhpWord\Style\Image as ImageStyle;
*
* Write common parts of document.xml, headerx.xml, and footerx.xml
*/
class Base extends WriterPart
class Base extends AbstractWriterPart
{
/**
* Write text element
@ -1121,9 +1121,9 @@ class Base extends WriterPart
* Write container elements
*
* @param XMLWriter $xmlWriter
* @param Container $container
* @param AbstractElement $container
*/
protected function writeContainerElements(XMLWriter $xmlWriter, Container $container)
protected function writeContainerElements(XMLWriter $xmlWriter, AbstractElement $container)
{
// Check allowed elements
$elmCommon = array('Text', 'Link', 'TextBreak', 'Image', 'Object');

View File

@ -15,7 +15,7 @@ use PhpOffice\PhpWord\Shared\XMLWriter;
/**
* Word2007 contenttypes part writer
*/
class ContentTypes extends WriterPart
class ContentTypes extends AbstractWriterPart
{
/**
* Write [Content_Types].xml

View File

@ -14,7 +14,7 @@ use PhpOffice\PhpWord\PhpWord;
/**
* Word2007 contenttypes part writer
*/
class DocProps extends WriterPart
class DocProps extends AbstractWriterPart
{
/**
* Write docProps/app.xml

View File

@ -11,7 +11,7 @@ namespace PhpOffice\PhpWord\Writer\Word2007;
use PhpOffice\PhpWord\PhpWord;
use PhpOffice\PhpWord\TOC;
use PhpOffice\PhpWord\Container\Section;
use PhpOffice\PhpWord\Element\Section;
use PhpOffice\PhpWord\Element\PageBreak;
use PhpOffice\PhpWord\Shared\XMLWriter;
use PhpOffice\PhpWord\Style\Font;

View File

@ -9,7 +9,7 @@
namespace PhpOffice\PhpWord\Writer\Word2007;
use PhpOffice\PhpWord\Container\Footer as FooterElement;
use PhpOffice\PhpWord\Element\Footer as FooterElement;
/**
* Word2007 footer part writer

View File

@ -9,7 +9,7 @@
namespace PhpOffice\PhpWord\Writer\Word2007;
use PhpOffice\PhpWord\Container\Header as HeaderElement;
use PhpOffice\PhpWord\Element\Header as HeaderElement;
/**
* Word2007 header part writer

View File

@ -17,7 +17,7 @@ use PhpOffice\PhpWord\Shared\XMLWriter;
*
* @since 0.9.2
*/
class Rels extends WriterPart
class Rels extends AbstractWriterPart
{
/**
* Base relationship URL

View File

@ -12,7 +12,7 @@ namespace PhpOffice\PhpWord\Writer;
/**
* Writer interface
*/
interface IWriter
interface WriterInterface
{
/**
* Save PhpWord to file

View File

@ -7,12 +7,12 @@
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
*/
namespace PhpOffice\PhpWord\Tests\Container;
namespace PhpOffice\PhpWord\Tests\Element;
use PhpOffice\PhpWord\Container\Footer;
use PhpOffice\PhpWord\Element\Footer;
/**
* Test class for PhpOffice\PhpWord\Container\Footer
* Test class for PhpOffice\PhpWord\Element\Footer
*
* @runTestsInSeparateProcesses
*/
@ -26,7 +26,7 @@ class FooterTest extends \PHPUnit_Framework_TestCase
$iVal = rand(1, 1000);
$oFooter = new Footer($iVal);
$this->assertInstanceOf('PhpOffice\\PhpWord\\Container\\Footer', $oFooter);
$this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Footer', $oFooter);
$this->assertEquals($oFooter->getSectionId(), $iVal);
}

View File

@ -7,12 +7,12 @@
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
*/
namespace PhpOffice\PhpWord\Tests\Container;
namespace PhpOffice\PhpWord\Tests\Element;
use PhpOffice\PhpWord\Container\Header;
use PhpOffice\PhpWord\Element\Header;
/**
* Test class for PhpOffice\PhpWord\Container\Header
* Test class for PhpOffice\PhpWord\Element\Header
*
* @runTestsInSeparateProcesses
*/
@ -26,7 +26,7 @@ class HeaderTest extends \PHPUnit_Framework_TestCase
$iVal = rand(1, 1000);
$oHeader = new Header($iVal);
$this->assertInstanceOf('PhpOffice\\PhpWord\\Container\\Header', $oHeader);
$this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Header', $oHeader);
$this->assertEquals($oHeader->getSectionId(), $iVal);
$this->assertEquals($oHeader->getType(), Header::AUTO);
}

View File

@ -24,7 +24,6 @@ class PageBreakTest extends \PHPUnit_Framework_TestCase
*/
public function testConstruct()
{
// Section Settings
$oPageBreak = new PageBreak();
$this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\PageBreak', $oPageBreak);

View File

@ -7,15 +7,15 @@
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
*/
namespace PhpOffice\PhpWord\Tests\Container;
namespace PhpOffice\PhpWord\Tests\Element;
use PhpOffice\PhpWord\Exception\Exception;
use PhpOffice\PhpWord\Container\Section;
use PhpOffice\PhpWord\Container\Header;
use PhpOffice\PhpWord\Element\Section;
use PhpOffice\PhpWord\Element\Header;
use PhpOffice\PhpWord\Style;
/**
* Test class for PhpOffice\PhpWord\Container\Section
* Test class for PhpOffice\PhpWord\Element\Section
*
* @runTestsInSeparateProcesses
*/
@ -139,7 +139,7 @@ class SectionTest extends \PHPUnit_Framework_TestCase
foreach ($elements as $element) {
$method = "create{$element}";
$this->assertInstanceOf("PhpOffice\\PhpWord\\Container\\{$element}", $object->$method());
$this->assertInstanceOf("PhpOffice\\PhpWord\\Element\\{$element}", $object->$method());
}
$this->assertFalse($object->hasDifferentFirstPage());
}

View File

@ -10,7 +10,7 @@
namespace PhpOffice\PhpWord\Tests;
use PhpOffice\PhpWord\Media;
use PhpOffice\PhpWord\Container\Section;
use PhpOffice\PhpWord\Element\Section;
use PhpOffice\PhpWord\Element\Image;
/**

View File

@ -11,7 +11,7 @@ namespace PhpOffice\PhpWord\Tests;
use PhpOffice\PhpWord\PhpWord;
use PhpOffice\PhpWord\DocumentProperties;
use PhpOffice\PhpWord\Container\Section;
use PhpOffice\PhpWord\Element\Section;
use PhpOffice\PhpWord\Style;
/**

View File

@ -7,14 +7,14 @@
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
*/
namespace PhpOffice\PhpWord\Tests\Container;
namespace PhpOffice\PhpWord\Tests\Style;
use PhpOffice\PhpWord\Container\Settings;
use PhpOffice\PhpWord\Style\Section;
/**
* Test class for PhpOffice\PhpWord\Container\Settings
* Test class for PhpOffice\PhpWord\Style\Section
*
* @coversDefaultClass \PhpOffice\PhpWord\Container\Settings
* @coversDefaultClass \PhpOffice\PhpWord\Element\Section
* @runTestsInSeparateProcesses
*/
class SettingsTest extends \PHPUnit_Framework_TestCase
@ -25,7 +25,7 @@ class SettingsTest extends \PHPUnit_Framework_TestCase
public function testSettingValue()
{
// Section Settings
$oSettings = new Settings();
$oSettings = new Section();
$oSettings->setSettingValue('_orientation', 'landscape');
$this->assertEquals('landscape', $oSettings->getOrientation());
@ -63,7 +63,7 @@ class SettingsTest extends \PHPUnit_Framework_TestCase
public function testMargin()
{
// Section Settings
$oSettings = new Settings();
$oSettings = new Section();
$iVal = rand(1, 1000);
$oSettings->setMarginTop($iVal);
@ -88,7 +88,7 @@ class SettingsTest extends \PHPUnit_Framework_TestCase
public function testOrientationLandscape()
{
// Section Settings
$oSettings = new Settings();
$oSettings = new Section();
$oSettings->setLandscape();
$this->assertEquals('landscape', $oSettings->getOrientation());
@ -102,7 +102,7 @@ class SettingsTest extends \PHPUnit_Framework_TestCase
public function testOrientationPortrait()
{
// Section Settings
$oSettings = new Settings();
$oSettings = new Section();
$oSettings->setPortrait();
$this->assertNull($oSettings->getOrientation());
@ -116,7 +116,7 @@ class SettingsTest extends \PHPUnit_Framework_TestCase
public function testBorderSize()
{
// Section Settings
$oSettings = new Settings();
$oSettings = new Section();
$iVal = rand(1, 1000);
$oSettings->setBorderSize($iVal);
@ -149,7 +149,7 @@ class SettingsTest extends \PHPUnit_Framework_TestCase
public function testBorderColor()
{
// Section Settings
$oSettings = new Settings();
$oSettings = new Section();
$oSettings->setBorderColor('FF00AA');
$this->assertEquals(array('FF00AA', 'FF00AA', 'FF00AA', 'FF00AA'), $oSettings->getBorderColor());
@ -177,7 +177,7 @@ class SettingsTest extends \PHPUnit_Framework_TestCase
public function testNumberingStart()
{
// Section Settings
$oSettings = new Settings();
$oSettings = new Section();
$this->assertNull($oSettings->getPageNumberingStart());
@ -194,7 +194,7 @@ class SettingsTest extends \PHPUnit_Framework_TestCase
*/
public function testHeader()
{
$oSettings = new Settings();
$oSettings = new Section();
$this->assertEquals(720, $oSettings->getHeaderHeight());
@ -212,7 +212,7 @@ class SettingsTest extends \PHPUnit_Framework_TestCase
public function testFooter()
{
// Section Settings
$oSettings = new Settings();
$oSettings = new Section();
$this->assertEquals(720, $oSettings->getFooterHeight());
@ -230,7 +230,7 @@ class SettingsTest extends \PHPUnit_Framework_TestCase
public function testColumnsNum()
{
// Section Settings
$oSettings = new Settings();
$oSettings = new Section();
// Default
$this->assertEquals(1, $oSettings->getColsNum());
@ -249,16 +249,16 @@ class SettingsTest extends \PHPUnit_Framework_TestCase
public function testColumnsSpace()
{
// Section Settings
$oSettings = new Settings();
$oSettings = new Section();
// Default
$this->assertEquals(720, $oSettings->getColsSpace());
$iVal = rand(1, 1000);
$this->assertInstanceOf('PhpOffice\\PhpWord\\Container\\Settings', $oSettings->setColsSpace($iVal));
$this->assertInstanceOf('PhpOffice\\PhpWord\\Style\\Section', $oSettings->setColsSpace($iVal));
$this->assertEquals($iVal, $oSettings->getColsSpace());
$this->assertInstanceOf('PhpOffice\\PhpWord\\Container\\Settings', $oSettings->setColsSpace());
$this->assertInstanceOf('PhpOffice\\PhpWord\\Style\\Section', $oSettings->setColsSpace());
$this->assertEquals(720, $oSettings->getColsSpace());
}
@ -268,7 +268,7 @@ class SettingsTest extends \PHPUnit_Framework_TestCase
public function testBreakType()
{
// Section Settings
$oSettings = new Settings();
$oSettings = new Section();
$this->assertNull($oSettings->getBreakType());

View File

@ -12,12 +12,12 @@ use PhpOffice\PhpWord\Writer\ODText;
use PhpWord\Tests\TestHelperDOCX;
/**
* Test class for PhpOffice\PhpWord\Writer\ODText\WriterPart
* Test class for PhpOffice\PhpWord\Writer\ODText\AbstractWriterPart
*
* @coversDefaultClass \PhpOffice\PhpWord\Writer\ODText\WriterPart
* @coversDefaultClass \PhpOffice\PhpWord\Writer\ODText\AbstractWriterPart
* @runTestsInSeparateProcesses
*/
class WriterPartTest extends \PHPUnit_Framework_TestCase
class AbstractWriterPartTest extends \PHPUnit_Framework_TestCase
{
/**
* covers ::setParentWriter
@ -26,7 +26,7 @@ class WriterPartTest extends \PHPUnit_Framework_TestCase
public function testSetGetParentWriter()
{
$object = $this->getMockForAbstractClass(
'PhpOffice\\PhpWord\\Writer\\ODText\\WriterPart'
'PhpOffice\\PhpWord\\Writer\\ODText\\AbstractWriterPart'
);
$object->setParentWriter(new ODText());
$this->assertEquals(
@ -38,12 +38,12 @@ class WriterPartTest extends \PHPUnit_Framework_TestCase
/**
* covers ::getParentWriter
* @expectedException Exception
* @expectedExceptionMessage No parent IWriter assigned.
* @expectedExceptionMessage No parent WriterInterface assigned.
*/
public function testSetGetParentWriterNull()
{
$object = $this->getMockForAbstractClass(
'PhpOffice\\PhpWord\\Writer\\ODText\\WriterPart'
'PhpOffice\\PhpWord\\Writer\\ODText\\AbstractWriterPart'
);
$object->getParentWriter();
}

View File

@ -8,17 +8,17 @@
*/
namespace PhpOffice\PhpWord\Tests\Writer\Word2007;
use PhpOffice\PhpWord\Writer\Word2007\WriterPart;
use PhpOffice\PhpWord\Writer\Word2007\AbstractWriterPart;
use PhpOffice\PhpWord\Writer\Word2007;
use PhpWord\Tests\TestHelperDOCX;
/**
* Test class for PhpOffice\PhpWord\Writer\Word2007\WriterPart
* Test class for PhpOffice\PhpWord\Writer\Word2007\AbstractWriterPart
*
* @coversDefaultClass \PhpOffice\PhpWord\Writer\Word2007\WriterPart
* @coversDefaultClass \PhpOffice\PhpWord\Writer\Word2007\AbstractWriterPart
* @runTestsInSeparateProcesses
*/
class WriterPartTest extends \PHPUnit_Framework_TestCase
class AbstractWriterPartTest extends \PHPUnit_Framework_TestCase
{
/**
* covers ::setParentWriter
@ -27,7 +27,7 @@ class WriterPartTest extends \PHPUnit_Framework_TestCase
public function testSetGetParentWriter()
{
$object = $this->getMockForAbstractClass(
'PhpOffice\\PhpWord\\Writer\\Word2007\\WriterPart'
'PhpOffice\\PhpWord\\Writer\\Word2007\\AbstractWriterPart'
);
$object->setParentWriter(new Word2007());
$this->assertEquals(
@ -39,12 +39,12 @@ class WriterPartTest extends \PHPUnit_Framework_TestCase
/**
* covers ::getParentWriter
* @expectedException Exception
* @expectedExceptionMessage No parent IWriter assigned.
* @expectedExceptionMessage No parent WriterInterface assigned.
*/
public function testSetGetParentWriterNull()
{
$object = $this->getMockForAbstractClass(
'PhpOffice\\PhpWord\\Writer\\Word2007\\WriterPart'
'PhpOffice\\PhpWord\\Writer\\Word2007\\AbstractWriterPart'
);
$object->getParentWriter();
}

View File

@ -28,7 +28,7 @@ class FooterTest extends \PHPUnit_Framework_TestCase
public function testWriteFooter()
{
$imageSrc = __DIR__ . "/../../_files/images/PhpWord.png";
$container = new \PhpOffice\PhpWord\Container\Footer(1);
$container = new \PhpOffice\PhpWord\Element\Footer(1);
$container->addText('');
$container->addPreserveText('');
$container->addTextBreak();

View File

@ -26,7 +26,7 @@ class HeaderTest extends \PHPUnit_Framework_TestCase
{
$imageSrc = __DIR__ . "/../../_files/images/PhpWord.png";
$container = new \PhpOffice\PhpWord\Container\Header(1);
$container = new \PhpOffice\PhpWord\Element\Header(1);
$container->addText('Test');
$container->addPreserveText('');
$container->addTextBreak();