Refactor: Increase DocumentProperties cohesion
This commit is contained in:
parent
98613423f8
commit
4e5bbb98b1
|
|
@ -137,12 +137,13 @@ class DocumentProperties
|
||||||
/**
|
/**
|
||||||
* Set Creator
|
* Set Creator
|
||||||
*
|
*
|
||||||
* @param string $pValue
|
* @param string $value
|
||||||
* @return self
|
* @return self
|
||||||
*/
|
*/
|
||||||
public function setCreator($pValue = '')
|
public function setCreator($value = '')
|
||||||
{
|
{
|
||||||
$this->creator = $pValue;
|
$this->creator = $this->setValue($value, '');
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -159,12 +160,13 @@ class DocumentProperties
|
||||||
/**
|
/**
|
||||||
* Set Last Modified By
|
* Set Last Modified By
|
||||||
*
|
*
|
||||||
* @param string $pValue
|
* @param string $value
|
||||||
* @return self
|
* @return self
|
||||||
*/
|
*/
|
||||||
public function setLastModifiedBy($pValue = '')
|
public function setLastModifiedBy($value = '')
|
||||||
{
|
{
|
||||||
$this->lastModifiedBy = $pValue;
|
$this->lastModifiedBy = $this->setValue($value, '');
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -181,15 +183,13 @@ class DocumentProperties
|
||||||
/**
|
/**
|
||||||
* Set Created
|
* Set Created
|
||||||
*
|
*
|
||||||
* @param int $pValue
|
* @param int $value
|
||||||
* @return self
|
* @return self
|
||||||
*/
|
*/
|
||||||
public function setCreated($pValue = null)
|
public function setCreated($value = null)
|
||||||
{
|
{
|
||||||
if (is_null($pValue)) {
|
$this->created = $this->setValue($value, time());
|
||||||
$pValue = time();
|
|
||||||
}
|
|
||||||
$this->created = $pValue;
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -206,15 +206,13 @@ class DocumentProperties
|
||||||
/**
|
/**
|
||||||
* Set Modified
|
* Set Modified
|
||||||
*
|
*
|
||||||
* @param int $pValue
|
* @param int $value
|
||||||
* @return self
|
* @return self
|
||||||
*/
|
*/
|
||||||
public function setModified($pValue = null)
|
public function setModified($value = null)
|
||||||
{
|
{
|
||||||
if (is_null($pValue)) {
|
$this->modified = $this->setValue($value, time());
|
||||||
$pValue = time();
|
|
||||||
}
|
|
||||||
$this->modified = $pValue;
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -231,12 +229,13 @@ class DocumentProperties
|
||||||
/**
|
/**
|
||||||
* Set Title
|
* Set Title
|
||||||
*
|
*
|
||||||
* @param string $pValue
|
* @param string $value
|
||||||
* @return self
|
* @return self
|
||||||
*/
|
*/
|
||||||
public function setTitle($pValue = '')
|
public function setTitle($value = '')
|
||||||
{
|
{
|
||||||
$this->title = $pValue;
|
$this->title = $this->setValue($value, '');
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -253,12 +252,13 @@ class DocumentProperties
|
||||||
/**
|
/**
|
||||||
* Set Description
|
* Set Description
|
||||||
*
|
*
|
||||||
* @param string $pValue
|
* @param string $value
|
||||||
* @return self
|
* @return self
|
||||||
*/
|
*/
|
||||||
public function setDescription($pValue = '')
|
public function setDescription($value = '')
|
||||||
{
|
{
|
||||||
$this->description = $pValue;
|
$this->description = $this->setValue($value, '');
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -275,12 +275,13 @@ class DocumentProperties
|
||||||
/**
|
/**
|
||||||
* Set Subject
|
* Set Subject
|
||||||
*
|
*
|
||||||
* @param string $pValue
|
* @param string $value
|
||||||
* @return self
|
* @return self
|
||||||
*/
|
*/
|
||||||
public function setSubject($pValue = '')
|
public function setSubject($value = '')
|
||||||
{
|
{
|
||||||
$this->subject = $pValue;
|
$this->subject = $this->setValue($value, '');
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -297,12 +298,13 @@ class DocumentProperties
|
||||||
/**
|
/**
|
||||||
* Set Keywords
|
* Set Keywords
|
||||||
*
|
*
|
||||||
* @param string $pValue
|
* @param string $value
|
||||||
* @return self
|
* @return self
|
||||||
*/
|
*/
|
||||||
public function setKeywords($pValue = '')
|
public function setKeywords($value = '')
|
||||||
{
|
{
|
||||||
$this->keywords = $pValue;
|
$this->keywords = $this->setValue($value, '');
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -319,12 +321,13 @@ class DocumentProperties
|
||||||
/**
|
/**
|
||||||
* Set Category
|
* Set Category
|
||||||
*
|
*
|
||||||
* @param string $pValue
|
* @param string $value
|
||||||
* @return self
|
* @return self
|
||||||
*/
|
*/
|
||||||
public function setCategory($pValue = '')
|
public function setCategory($value = '')
|
||||||
{
|
{
|
||||||
$this->category = $pValue;
|
$this->category = $this->setValue($value, '');
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -341,12 +344,13 @@ class DocumentProperties
|
||||||
/**
|
/**
|
||||||
* Set Company
|
* Set Company
|
||||||
*
|
*
|
||||||
* @param string $pValue
|
* @param string $value
|
||||||
* @return self
|
* @return self
|
||||||
*/
|
*/
|
||||||
public function setCompany($pValue = '')
|
public function setCompany($value = '')
|
||||||
{
|
{
|
||||||
$this->company = $pValue;
|
$this->company = $this->setValue($value, '');
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -363,12 +367,13 @@ class DocumentProperties
|
||||||
/**
|
/**
|
||||||
* Set Manager
|
* Set Manager
|
||||||
*
|
*
|
||||||
* @param string $pValue
|
* @param string $value
|
||||||
* @return self
|
* @return self
|
||||||
*/
|
*/
|
||||||
public function setManager($pValue = '')
|
public function setManager($value = '')
|
||||||
{
|
{
|
||||||
$this->manager = $pValue;
|
$this->manager = $this->setValue($value, '');
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -401,7 +406,7 @@ class DocumentProperties
|
||||||
*/
|
*/
|
||||||
public function getCustomPropertyValue($propertyName)
|
public function getCustomPropertyValue($propertyName)
|
||||||
{
|
{
|
||||||
if (isset($this->customProperties[$propertyName])) {
|
if ($this->isCustomPropertySet($propertyName)) {
|
||||||
return $this->customProperties[$propertyName]['value'];
|
return $this->customProperties[$propertyName]['value'];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -415,7 +420,7 @@ class DocumentProperties
|
||||||
*/
|
*/
|
||||||
public function getCustomPropertyType($propertyName)
|
public function getCustomPropertyType($propertyName)
|
||||||
{
|
{
|
||||||
if (isset($this->customProperties[$propertyName])) {
|
if ($this->isCustomPropertySet($propertyName)) {
|
||||||
return $this->customProperties[$propertyName]['type'];
|
return $this->customProperties[$propertyName]['type'];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -473,33 +478,49 @@ class DocumentProperties
|
||||||
*/
|
*/
|
||||||
public static function convertProperty($propertyValue, $propertyType)
|
public static function convertProperty($propertyValue, $propertyType)
|
||||||
{
|
{
|
||||||
$typeGroups = array(
|
switch ($propertyType) {
|
||||||
'empty' => array('empty'),
|
case 'empty': // Empty
|
||||||
'null' => array('null'),
|
return '';
|
||||||
'int' => array('i1', 'i2', 'i4', 'i8', 'int'),
|
case 'null': // Null
|
||||||
'abs' => array('ui1', 'ui2', 'ui4', 'ui8', 'uint'),
|
return null;
|
||||||
'float' => array('r4', 'r8', 'decimal'),
|
case 'i1': // 1-Byte Signed Integer
|
||||||
'date' => array('date', 'filetime'),
|
case 'i2': // 2-Byte Signed Integer
|
||||||
'bool' => array('bool'),
|
case 'i4': // 4-Byte Signed Integer
|
||||||
);
|
case 'i8': // 8-Byte Signed Integer
|
||||||
foreach ($typeGroups as $groupId => $groupMembers) {
|
case 'int': // Integer
|
||||||
if (in_array($propertyType, $groupMembers)) {
|
return (int) $propertyValue;
|
||||||
if ($groupId == 'null') {
|
case 'ui1': // 1-Byte Unsigned Integer
|
||||||
return null;
|
case 'ui2': // 2-Byte Unsigned Integer
|
||||||
} elseif ($groupId == 'int') {
|
case 'ui4': // 4-Byte Unsigned Integer
|
||||||
return (int) $propertyValue;
|
case 'ui8': // 8-Byte Unsigned Integer
|
||||||
} elseif ($groupId == 'abs') {
|
case 'uint': // Unsigned Integer
|
||||||
return abs((int) $propertyValue);
|
return abs((int) $propertyValue);
|
||||||
} elseif ($groupId == 'float') {
|
case 'r4': // 4-Byte Real Number
|
||||||
return (float) $propertyValue;
|
case 'r8': // 8-Byte Real Number
|
||||||
} elseif ($groupId == 'date') {
|
case 'decimal': // Decimal
|
||||||
return strtotime($propertyValue);
|
return (float) $propertyValue;
|
||||||
} elseif ($groupId == 'bool') {
|
case 'date': // Date and Time
|
||||||
return ($propertyValue == 'true') ? true : false;
|
case 'filetime': // File Time
|
||||||
} else {
|
return strtotime($propertyValue);
|
||||||
return '';
|
case 'bool': // Boolean
|
||||||
}
|
return ($propertyValue == 'true') ? true : false;
|
||||||
}
|
case 'lpstr': // LPSTR
|
||||||
|
case 'lpwstr': // LPWSTR
|
||||||
|
case 'bstr': // Basic String
|
||||||
|
case 'cy': // Currency
|
||||||
|
case 'error': // Error Status Code
|
||||||
|
case 'vector': // Vector
|
||||||
|
case 'array': // Array
|
||||||
|
case 'blob': // Binary Blob
|
||||||
|
case 'oblob': // Binary Blob Object
|
||||||
|
case 'stream': // Binary Stream
|
||||||
|
case 'ostream': // Binary Stream Object
|
||||||
|
case 'storage': // Binary Storage
|
||||||
|
case 'ostorage': // Binary Storage Object
|
||||||
|
case 'vstream': // Binary Versioned Stream
|
||||||
|
case 'clsid': // Class ID
|
||||||
|
case 'cf': // Clipboard Data
|
||||||
|
return $propertyValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
return $propertyValue;
|
return $propertyValue;
|
||||||
|
|
@ -528,4 +549,20 @@ class DocumentProperties
|
||||||
|
|
||||||
return self::PROPERTY_TYPE_UNKNOWN;
|
return self::PROPERTY_TYPE_UNKNOWN;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set default for null and empty value
|
||||||
|
*
|
||||||
|
* @param mixed $value
|
||||||
|
* @param mixed $default
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
private function setValue($value, $default)
|
||||||
|
{
|
||||||
|
if (is_null($value) || $value == '') {
|
||||||
|
$value = $default;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $value;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -118,7 +118,7 @@ abstract class AbstractStyle
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set boolean value
|
* Set default for null and empty value
|
||||||
*
|
*
|
||||||
* @param mixed $value
|
* @param mixed $value
|
||||||
* @param mixed $default
|
* @param mixed $default
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue