2014-04-08 03:03:14 +07:00
|
|
|
<?php
|
|
|
|
|
/**
|
|
|
|
|
* PHPWord
|
|
|
|
|
*
|
|
|
|
|
* @link https://github.com/PHPOffice/PHPWord
|
2014-05-05 12:38:31 +04:00
|
|
|
* @copyright 2010-2014 PHPWord contributors
|
2014-05-04 21:03:28 +04:00
|
|
|
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
|
2014-04-08 03:03:14 +07:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
namespace PhpOffice\PhpWord\Style;
|
|
|
|
|
|
2014-04-11 21:16:07 +07:00
|
|
|
use PhpOffice\PhpWord\Shared\String;
|
|
|
|
|
|
2014-04-08 03:03:14 +07:00
|
|
|
/**
|
|
|
|
|
* Abstract style class
|
|
|
|
|
*
|
2014-04-11 19:04:53 +07:00
|
|
|
* @since 0.10.0
|
2014-04-08 03:03:14 +07:00
|
|
|
*/
|
|
|
|
|
abstract class AbstractStyle
|
|
|
|
|
{
|
2014-04-26 19:06:44 +07:00
|
|
|
/**
|
|
|
|
|
* Style name
|
|
|
|
|
*
|
|
|
|
|
* @var string
|
|
|
|
|
*/
|
|
|
|
|
protected $styleName;
|
|
|
|
|
|
2014-04-11 16:16:22 +07:00
|
|
|
/**
|
|
|
|
|
* Index number in Style collection for named style
|
|
|
|
|
*
|
|
|
|
|
* This number starts from one and defined in Style::setStyleValues()
|
|
|
|
|
*
|
|
|
|
|
* @var integer|null
|
|
|
|
|
*/
|
|
|
|
|
protected $index;
|
|
|
|
|
|
2014-04-26 19:06:44 +07:00
|
|
|
/**
|
|
|
|
|
* Get style name
|
|
|
|
|
*
|
|
|
|
|
* @return string
|
|
|
|
|
*/
|
|
|
|
|
public function getStyleName()
|
|
|
|
|
{
|
|
|
|
|
return $this->styleName;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Set style name
|
|
|
|
|
*
|
|
|
|
|
* @param string $value
|
|
|
|
|
* @return self
|
|
|
|
|
*/
|
|
|
|
|
public function setStyleName($value)
|
|
|
|
|
{
|
|
|
|
|
$this->styleName = $value;
|
|
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
|
}
|
|
|
|
|
|
2014-04-11 16:16:22 +07:00
|
|
|
/**
|
|
|
|
|
* Get index number
|
|
|
|
|
*
|
|
|
|
|
* @return integer|null
|
|
|
|
|
*/
|
|
|
|
|
public function getIndex()
|
|
|
|
|
{
|
|
|
|
|
return $this->index;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Set index number
|
|
|
|
|
*
|
|
|
|
|
* @param integer|null $value
|
2014-04-26 19:06:44 +07:00
|
|
|
* @return self
|
2014-04-11 16:16:22 +07:00
|
|
|
*/
|
|
|
|
|
public function setIndex($value = null)
|
|
|
|
|
{
|
|
|
|
|
$this->index = $this->setIntVal($value, $this->index);
|
|
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
|
}
|
|
|
|
|
|
2014-04-08 03:03:14 +07:00
|
|
|
/**
|
|
|
|
|
* Set style value template method
|
|
|
|
|
*
|
2014-04-11 21:16:07 +07:00
|
|
|
* Some child classes have their own specific overrides.
|
|
|
|
|
* Backward compability check for versions < 0.10.0 which use underscore
|
|
|
|
|
* prefix for their private properties.
|
|
|
|
|
* Check if the set method is exists. Throws an exception?
|
2014-04-08 03:03:14 +07:00
|
|
|
*
|
|
|
|
|
* @param string $key
|
|
|
|
|
* @param string $value
|
2014-04-11 16:16:22 +07:00
|
|
|
* @return self
|
2014-04-08 03:03:14 +07:00
|
|
|
*/
|
|
|
|
|
public function setStyleValue($key, $value)
|
|
|
|
|
{
|
2014-04-11 21:16:07 +07:00
|
|
|
$method = 'set' . String::removeUnderscorePrefix($key);
|
2014-04-08 03:03:14 +07:00
|
|
|
if (method_exists($this, $method)) {
|
|
|
|
|
$this->$method($value);
|
|
|
|
|
}
|
2014-04-11 16:16:22 +07:00
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Set style by using associative array
|
|
|
|
|
*
|
|
|
|
|
* @param array $styles
|
|
|
|
|
* @return self
|
|
|
|
|
*/
|
|
|
|
|
public function setStyleByArray($styles = array())
|
|
|
|
|
{
|
|
|
|
|
foreach ($styles as $key => $value) {
|
|
|
|
|
$this->setStyleValue($key, $value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
|
}
|
|
|
|
|
|
2014-04-28 23:33:26 +07:00
|
|
|
/**
|
2014-04-30 18:49:48 +07:00
|
|
|
* Set default for null and empty value
|
2014-04-28 23:33:26 +07:00
|
|
|
*
|
|
|
|
|
* @param mixed $value
|
|
|
|
|
* @param mixed $default
|
|
|
|
|
* @return mixed
|
|
|
|
|
*/
|
|
|
|
|
protected function setNonEmptyVal($value, $default)
|
|
|
|
|
{
|
|
|
|
|
if (is_null($value) || $value == '') {
|
|
|
|
|
$value = $default;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $value;
|
|
|
|
|
}
|
|
|
|
|
|
2014-04-11 16:16:22 +07:00
|
|
|
/**
|
|
|
|
|
* Set boolean value
|
|
|
|
|
*
|
|
|
|
|
* @param mixed $value
|
|
|
|
|
* @param boolean|null $default
|
|
|
|
|
* @return boolean|null
|
|
|
|
|
*/
|
|
|
|
|
protected function setBoolVal($value, $default = null)
|
|
|
|
|
{
|
|
|
|
|
if (!is_bool($value)) {
|
|
|
|
|
$value = $default;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $value;
|
|
|
|
|
}
|
|
|
|
|
|
2014-04-28 23:33:26 +07:00
|
|
|
/**
|
|
|
|
|
* Set numeric value
|
|
|
|
|
*
|
|
|
|
|
* @param mixed $value
|
|
|
|
|
* @param integer|float|null $default
|
|
|
|
|
* @return integer|float|null
|
|
|
|
|
*/
|
|
|
|
|
protected function setNumericVal($value, $default = null)
|
|
|
|
|
{
|
|
|
|
|
if (!is_numeric($value)) {
|
|
|
|
|
$value = $default;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $value;
|
|
|
|
|
}
|
|
|
|
|
|
2014-04-11 16:16:22 +07:00
|
|
|
/**
|
|
|
|
|
* Set integer value
|
|
|
|
|
*
|
2014-04-12 12:57:51 +07:00
|
|
|
* @param mixed $value
|
2014-04-11 16:16:22 +07:00
|
|
|
* @param integer|null $default
|
|
|
|
|
* @return integer|null
|
|
|
|
|
*/
|
|
|
|
|
protected function setIntVal($value, $default = null)
|
|
|
|
|
{
|
|
|
|
|
if (!is_int($value)) {
|
|
|
|
|
$value = $default;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $value;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Set float value
|
|
|
|
|
*
|
|
|
|
|
* @param mixed $value
|
|
|
|
|
* @param float|null $default
|
|
|
|
|
* @return float|null
|
|
|
|
|
*/
|
|
|
|
|
protected function setFloatVal($value, $default = null)
|
|
|
|
|
{
|
|
|
|
|
if (!is_float($value)) {
|
|
|
|
|
$value = $default;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $value;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Set enum value
|
|
|
|
|
*
|
|
|
|
|
* @param mixed $value
|
|
|
|
|
* @param array $enum
|
|
|
|
|
* @param mixed $default
|
|
|
|
|
*/
|
|
|
|
|
protected function setEnumVal($value, $enum, $default = null)
|
|
|
|
|
{
|
|
|
|
|
if (!in_array($value, $enum)) {
|
|
|
|
|
$value = $default;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $value;
|
2014-04-08 03:03:14 +07:00
|
|
|
}
|
|
|
|
|
}
|