PHPWord/src/PhpWord/Element/ListItem.php

112 lines
2.5 KiB
PHP
Raw Normal View History

2012-05-06 18:25:40 +02:00
<?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.
2012-05-06 18:25:40 +02:00
*
2014-03-27 23:55:06 +07:00
* @link https://github.com/PHPOffice/PHPWord
* @copyright 2010-2014 PHPWord contributors
2014-05-04 21:03:28 +04:00
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
2012-05-06 18:25:40 +02:00
*/
namespace PhpOffice\PhpWord\Element;
use PhpOffice\PhpWord\Shared\String;
2014-04-03 08:44:41 +07:00
use PhpOffice\PhpWord\Style\ListItem as ListItemStyle;
/**
* List item element
*/
class ListItem extends AbstractElement
{
/**
2014-05-13 23:36:33 +07:00
* Element style
*
* @var \PhpOffice\PhpWord\Style\ListItem
*/
2014-04-03 08:44:41 +07:00
private $style;
/**
2014-05-13 23:36:33 +07:00
* Text object
*
2014-05-13 23:36:33 +07:00
* @var \PhpOffice\PhpWord\Element\Text
*/
2014-04-03 08:44:41 +07:00
private $textObject;
/**
2014-05-13 23:36:33 +07:00
* Depth
*
* @var int
*/
2014-04-03 08:44:41 +07:00
private $depth;
/**
* Create a new ListItem
*
* @param string $text
* @param int $depth
* @param mixed $fontStyle
* @param array|string|null $listStyle
* @param mixed $paragraphStyle
*/
public function __construct($text, $depth = 0, $fontStyle = null, $listStyle = null, $paragraphStyle = null)
{
$this->textObject = new Text(String::toUTF8($text), $fontStyle, $paragraphStyle);
2014-04-03 08:44:41 +07:00
$this->depth = $depth;
// Version >= 0.10.0 will pass numbering style name. Older version will use old method
if (!is_null($listStyle) && is_string($listStyle)) {
$this->style = new ListItemStyle($listStyle);
} else {
$this->style = $this->setStyle(new ListItemStyle(), $listStyle, true);
}
}
/**
2014-05-13 23:36:33 +07:00
* Get style
*
* @return \PhpOffice\PhpWord\Style\ListItem
*/
public function getStyle()
{
2014-04-03 08:44:41 +07:00
return $this->style;
}
/**
2014-05-13 23:36:33 +07:00
* Get Text object
*
* @return \PhpOffice\PhpWord\Element\Text
*/
public function getTextObject()
{
2014-04-03 08:44:41 +07:00
return $this->textObject;
}
/**
2014-05-13 23:36:33 +07:00
* Get depth
*
* @return int
*/
public function getDepth()
{
2014-04-03 08:44:41 +07:00
return $this->depth;
}
2014-05-13 23:36:33 +07:00
/**
* Get text
*
* @return string
* @since 0.11.0
*/
public function getText()
{
return $this->textObject->getText();
}
2012-05-06 18:25:40 +02:00
}