PHPWord/src/PhpWord/Element/PreserveText.php

93 lines
1.8 KiB
PHP
Raw Normal View History

2012-05-06 18:25:40 +02:00
<?php
/**
* PHPWord
2012-05-06 18:25:40 +02:00
*
2014-03-27 23:55:06 +07:00
* @link https://github.com/PHPOffice/PHPWord
* @copyright 2014 PHPWord
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
2012-05-06 18:25:40 +02:00
*/
namespace PhpOffice\PhpWord\Element;
use PhpOffice\PhpWord\Style\Font;
use PhpOffice\PhpWord\Style\Paragraph;
/**
* Preserve text/field element
*/
class PreserveText extends AbstractElement
{
/**
* Text content
*
* @var string
*/
2014-04-03 08:44:41 +07:00
private $text;
/**
* Text style
*
* @var string|\PhpOffice\PhpWord\Style\Font
*/
2014-04-03 08:44:41 +07:00
private $fontStyle;
/**
* Paragraph style
*
* @var string|\PhpOffice\PhpWord\Style\Paragraph
*/
2014-04-03 08:44:41 +07:00
private $paragraphStyle;
/**
* Create a new Preserve Text Element
*
2014-03-17 07:26:25 +07:00
* @param string $text
* @param mixed $styleFont
* @param mixed $styleParagraph
2014-03-30 18:51:25 +07:00
* @return $this
*/
public function __construct($text = null, $styleFont = null, $styleParagraph = null)
{
2014-04-03 08:44:41 +07:00
$this->fontStyle = $this->setStyle(new Font('text'), $styleFont);
$this->paragraphStyle = $this->setStyle(new Paragraph(), $styleParagraph);
$matches = preg_split('/({.*?})/', $text, null, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
2014-03-09 15:11:51 -04:00
if (isset($matches[0])) {
2014-04-03 08:44:41 +07:00
$this->text = $matches;
2014-03-09 15:11:51 -04:00
}
return $this;
}
/**
* Get Text style
*
* @return string|\PhpOffice\PhpWord\Style\Font
*/
public function getFontStyle()
{
2014-04-03 08:44:41 +07:00
return $this->fontStyle;
}
/**
* Get Paragraph style
*
* @return string|\PhpOffice\PhpWord\Style\Paragraph
*/
public function getParagraphStyle()
{
2014-04-03 08:44:41 +07:00
return $this->paragraphStyle;
}
/**
* Get Text content
*
* @return string
*/
public function getText()
{
2014-04-03 08:44:41 +07:00
return $this->text;
}
2012-05-06 18:25:40 +02:00
}