Skip to content

Commit f3f11cb

Browse files
authored
Merge pull request #1092 from troosan/implement_request_#1041
add new NumberFormat values and refactor FootnoteProperties to use same values
2 parents 663a552 + 8a5433e commit f3f11cb

File tree

10 files changed

+271
-53
lines changed

10 files changed

+271
-53
lines changed

samples/Sample_06_Footnote.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<?php
2-
use PhpOffice\PhpWord\SimpleType\FootnoteProperties;
2+
use PhpOffice\PhpWord\ComplexType\FootnoteProperties;
3+
use PhpOffice\PhpWord\SimpleType\NumberFormat;
34

45
include_once 'Sample_Header.php';
56

@@ -50,7 +51,7 @@
5051
$footnote->addText('The reference for this is wrapped in its own line');
5152

5253
$footnoteProperties = new FootnoteProperties();
53-
$footnoteProperties->setNumFmt(FootnoteProperties::NUMBER_FORMAT_UPPER_ROMAN);
54+
$footnoteProperties->setNumFmt(NumberFormat::DECIMAL_ENCLOSED_CIRCLE);
5455
$section->setFootnoteProperties($footnoteProperties);
5556

5657
// Save file

src/PhpWord/SimpleType/FootnoteProperties.php renamed to src/PhpWord/ComplexType/FootnoteProperties.php

Lines changed: 57 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@
1414
* @copyright 2010-2016 PHPWord contributors
1515
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
1616
*/
17-
namespace PhpOffice\PhpWord\SimpleType;
17+
namespace PhpOffice\PhpWord\ComplexType;
18+
19+
use PhpOffice\PhpWord\SimpleType\NumberFormat;
1820

1921
/**
2022
* Footnote properties
@@ -28,17 +30,6 @@ final class FootnoteProperties
2830
const RESTART_NUMBER_EACH_SECTION = 'eachSect';
2931
const RESTART_NUMBER_EACH_PAGE = 'eachPage';
3032

31-
const NUMBER_FORMAT_DECIMAL = 'decimal';
32-
const NUMBER_FORMAT_UPPER_ROMAN = 'upperRoman';
33-
const NUMBER_FORMAT_LOWER_ROMAN = 'lowerRoman';
34-
const NUMBER_FORMAT_UPPER_LETTER = 'upperLetter';
35-
const NUMBER_FORMAT_LOWER_LETTER = 'lowerLetter';
36-
const NUMBER_FORMAT_ORDINAL = 'ordinal';
37-
const NUMBER_FORMAT_CARDINAL_TEXT = 'cardinalText';
38-
const NUMBER_FORMAT_ORDINAL_TEXT = 'ordinalText';
39-
const NUMBER_FORMAT_NONE = 'none';
40-
const NUMBER_FORMAT_BULLET = 'bullet';
41-
4233
const POSITION_PAGE_BOTTOM = 'pageBottom';
4334
const POSITION_BENEATH_TEXT = 'beneathText';
4435
const POSITION_SECTION_END = 'sectEnd';
@@ -52,7 +43,7 @@ final class FootnoteProperties
5243
private $pos;
5344

5445
/**
55-
* Footnote Numbering Format
46+
* Footnote Numbering Format w:numFmt, one of PhpOffice\PhpWord\SimpleType\NumberFormat
5647
*
5748
* @var string
5849
*/
@@ -61,7 +52,7 @@ final class FootnoteProperties
6152
/**
6253
* Footnote and Endnote Numbering Starting Value
6354
*
64-
* @var decimal
55+
* @var double
6556
*/
6657
private $numStart;
6758

@@ -72,11 +63,23 @@ final class FootnoteProperties
7263
*/
7364
private $numRestart;
7465

66+
/**
67+
* Get the Footnote Positioning Location
68+
*
69+
* @return string
70+
*/
7571
public function getPos()
7672
{
7773
return $this->pos;
7874
}
7975

76+
/**
77+
* Set the Footnote Positioning Location (pageBottom, beneathText, sectEnd, docEnd)
78+
*
79+
* @param string $pos
80+
* @throws \InvalidArgumentException
81+
* @return self
82+
*/
8083
public function setPos($pos)
8184
{
8285
$position = array(
@@ -91,50 +94,71 @@ public function setPos($pos)
9194
} else {
9295
throw new \InvalidArgumentException("Invalid value, on of " . implode(', ', $position) . " possible");
9396
}
97+
return $this;
9498
}
9599

100+
/**
101+
* Get the Footnote Numbering Format
102+
*
103+
* @return string
104+
*/
96105
public function getNumFmt()
97106
{
98107
return $this->numFmt;
99108
}
100109

110+
/**
111+
* Set the Footnote Numbering Format
112+
*
113+
* @param string $numFmt One of NumberFormat
114+
* @return self
115+
*/
101116
public function setNumFmt($numFmt)
102117
{
103-
$numberFormat = array(
104-
self::NUMBER_FORMAT_DECIMAL,
105-
self::NUMBER_FORMAT_UPPER_ROMAN,
106-
self::NUMBER_FORMAT_LOWER_ROMAN,
107-
self::NUMBER_FORMAT_UPPER_LETTER,
108-
self::NUMBER_FORMAT_LOWER_LETTER,
109-
self::NUMBER_FORMAT_ORDINAL,
110-
self::NUMBER_FORMAT_CARDINAL_TEXT,
111-
self::NUMBER_FORMAT_ORDINAL_TEXT,
112-
self::NUMBER_FORMAT_NONE,
113-
self::NUMBER_FORMAT_BULLET
114-
);
115-
116-
if (in_array($numFmt, $numberFormat)) {
117-
$this->numFmt = $numFmt;
118-
} else {
119-
throw new \InvalidArgumentException("Invalid value, on of " . implode(', ', $numberFormat) . " possible");
120-
}
118+
NumberFormat::validate($numFmt);
119+
$this->numFmt = $numFmt;
120+
return $this;
121121
}
122122

123+
/**
124+
* Get the Footnote Numbering Format
125+
*
126+
* @return double
127+
*/
123128
public function getNumStart()
124129
{
125130
return $this->numStart;
126131
}
127132

133+
/**
134+
* Set the Footnote Numbering Format
135+
*
136+
* @param double $numStart
137+
* @return self
138+
*/
128139
public function setNumStart($numStart)
129140
{
130141
$this->numStart = $numStart;
142+
return $this;
131143
}
132144

145+
/**
146+
* Get the Footnote and Endnote Numbering Starting Value
147+
*
148+
* @return string
149+
*/
133150
public function getNumRestart()
134151
{
135152
return $this->numRestart;
136153
}
137154

155+
/**
156+
* Set the Footnote and Endnote Numbering Starting Value (continuous, eachSect, eachPage)
157+
*
158+
* @param string $numRestart
159+
* @throws \InvalidArgumentException
160+
* @return self
161+
*/
138162
public function setNumRestart($numRestart)
139163
{
140164
$restartNumbers = array(
@@ -148,5 +172,6 @@ public function setNumRestart($numRestart)
148172
} else {
149173
throw new \InvalidArgumentException("Invalid value, on of " . implode(', ', $restartNumbers) . " possible");
150174
}
175+
return $this;
151176
}
152177
}

src/PhpWord/Element/Section.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717

1818
namespace PhpOffice\PhpWord\Element;
1919

20+
use PhpOffice\PhpWord\ComplexType\FootnoteProperties;
2021
use PhpOffice\PhpWord\Style\Section as SectionStyle;
21-
use PhpOffice\PhpWord\SimpleType\FootnoteProperties;
2222

2323
class Section extends AbstractContainer
2424
{

src/PhpWord/Shared/AbstractEnum.php

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
namespace PhpOffice\PhpWord\Shared;
3+
4+
abstract class AbstractEnum
5+
{
6+
7+
private static $constCacheArray = null;
8+
9+
private static function getConstants()
10+
{
11+
if (self::$constCacheArray == null) {
12+
self::$constCacheArray = array();
13+
}
14+
$calledClass = get_called_class();
15+
if (! array_key_exists($calledClass, self::$constCacheArray)) {
16+
$reflect = new \ReflectionClass($calledClass);
17+
self::$constCacheArray[$calledClass] = $reflect->getConstants();
18+
}
19+
return self::$constCacheArray[$calledClass];
20+
}
21+
22+
public static function values()
23+
{
24+
return array_values(self::getConstants());
25+
}
26+
27+
public static function validate($value)
28+
{
29+
$values = array_values(self::getConstants());
30+
if (!in_array($value, $values, true)) {
31+
$calledClass = get_called_class();
32+
throw new \InvalidArgumentException("$value is not a valid value for $calledClass, possible values are " . implode(', ', $values));
33+
}
34+
}
35+
}
Lines changed: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
1+
<?php
2+
/**
3+
* This file is part of PHPWord - A pure PHP library for reading and writing
4+
* word processing documents.
5+
*
6+
* PHPWord is free software distributed under the terms of the GNU Lesser
7+
* General Public License version 3 as published by the Free Software Foundation.
8+
*
9+
* For the full copyright and license information, please read the LICENSE
10+
* file that was distributed with this source code. For the full list of
11+
* contributors, visit https://github.com/PHPOffice/PHPWord/contributors.
12+
*
13+
* @link https://github.com/PHPOffice/PHPWord
14+
* @copyright 2010-2016 PHPWord contributors
15+
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
16+
*/
17+
18+
namespace PhpOffice\PhpWord\SimpleType;
19+
20+
use PhpOffice\PhpWord\Shared\AbstractEnum;
21+
22+
/**
23+
* Numbering Format.
24+
*
25+
* @since 0.14.0
26+
*
27+
* @see http://www.datypic.com/sc/ooxml/t-w_ST_NumberFormat.html.
28+
*
29+
* @codeCoverageIgnore
30+
*/
31+
final class NumberFormat extends AbstractEnum
32+
{
33+
//Decimal Numbers
34+
const DECIMAL = 'decimal';
35+
//Uppercase Roman Numerals
36+
const UPPER_ROMAN = 'upperRoman';
37+
//Lowercase Roman Numerals
38+
const LOWER_ROMAN = 'lowerRoman';
39+
//Uppercase Latin Alphabet
40+
const UPPER_LETTER = 'upperLetter';
41+
//Lowercase Latin Alphabet
42+
const LOWER_LETTER = 'lowerLetter';
43+
//Ordinal
44+
const ORDINAL = 'ordinal';
45+
//Cardinal Text
46+
const CARDINAL_TEXT = 'cardinalText';
47+
//Ordinal Text
48+
const ORDINAL_TEXT = 'ordinalText';
49+
//Hexadecimal Numbering
50+
const HEX = 'hex';
51+
//Chicago Manual of Style
52+
const CHICAGO = 'chicago';
53+
//Ideographs
54+
const IDEOGRAPH_DIGITAL = 'ideographDigital';
55+
//Japanese Counting System
56+
const JAPANESE_COUNTING = 'japaneseCounting';
57+
//AIUEO Order Hiragana
58+
const AIUEO = 'aiueo';
59+
//Iroha Ordered Katakana
60+
const IROHA = 'iroha';
61+
//Double Byte Arabic Numerals
62+
const DECIMAL_FULL_WIDTH = 'decimalFullWidth';
63+
//Single Byte Arabic Numerals
64+
const DECIMAL_HALF_WIDTH = 'decimalHalfWidth';
65+
//Japanese Legal Numbering
66+
const JAPANESE_LEGAL = 'japaneseLegal';
67+
//Japanese Digital Ten Thousand Counting System
68+
const JAPANESE_DIGITAL_TEN_THOUSAND = 'japaneseDigitalTenThousand';
69+
//Decimal Numbers Enclosed in a Circle
70+
const DECIMAL_ENCLOSED_CIRCLE = 'decimalEnclosedCircle';
71+
//Double Byte Arabic Numerals Alternate
72+
const DECIMAL_FULL_WIDTH2 = 'decimalFullWidth2';
73+
//Full-Width AIUEO Order Hiragana
74+
const AIUEO_FULL_WIDTH = 'aiueoFullWidth';
75+
//Full-Width Iroha Ordered Katakana
76+
const IROHA_FULL_WIDTH = 'irohaFullWidth';
77+
//Initial Zero Arabic Numerals
78+
const DECIMAL_ZERO = 'decimalZero';
79+
//Bullet
80+
const BULLET = 'bullet';
81+
//Korean Ganada Numbering
82+
const GANADA = 'ganada';
83+
//Korean Chosung Numbering
84+
const CHOSUNG = 'chosung';
85+
//Decimal Numbers Followed by a Period
86+
const DECIMAL_ENCLOSED_FULL_STOP = 'decimalEnclosedFullstop';
87+
//Decimal Numbers Enclosed in Parenthesis
88+
const DECIMAL_ENCLOSED_PAREN = 'decimalEnclosedParen';
89+
//Decimal Numbers Enclosed in a Circle
90+
const DECIMAL_ENCLOSED_CIRCLE_CHINESE = 'decimalEnclosedCircleChinese';
91+
//Ideographs Enclosed in a Circle
92+
const IDEOGRAPHENCLOSEDCIRCLE = 'ideographEnclosedCircle';
93+
//Traditional Ideograph Format
94+
const IDEOGRAPH_TRADITIONAL = 'ideographTraditional';
95+
//Zodiac Ideograph Format
96+
const IDEOGRAPH_ZODIAC = 'ideographZodiac';
97+
//Traditional Zodiac Ideograph Format
98+
const IDEOGRAPH_ZODIAC_TRADITIONAL = 'ideographZodiacTraditional';
99+
//Taiwanese Counting System
100+
const TAIWANESE_COUNTING = 'taiwaneseCounting';
101+
//Traditional Legal Ideograph Format
102+
const IDEOGRAPH_LEGAL_TRADITIONAL = 'ideographLegalTraditional';
103+
//Taiwanese Counting Thousand System
104+
const TAIWANESE_COUNTING_THOUSAND = 'taiwaneseCountingThousand';
105+
//Taiwanese Digital Counting System
106+
const TAIWANESE_DIGITAL = 'taiwaneseDigital';
107+
//Chinese Counting System
108+
const CHINESE_COUNTING = 'chineseCounting';
109+
//Chinese Legal Simplified Format
110+
const CHINESE_LEGAL_SIMPLIFIED = 'chineseLegalSimplified';
111+
//Chinese Counting Thousand System
112+
const CHINESE_COUNTING_THOUSAND = 'chineseCountingThousand';
113+
//Korean Digital Counting System
114+
const KOREAN_DIGITAL = 'koreanDigital';
115+
//Korean Counting System
116+
const KOREAN_COUNTING = 'koreanCounting';
117+
//Korean Legal Numbering
118+
const KOREAN_LEGAL = 'koreanLegal';
119+
//Korean Digital Counting System Alternate
120+
const KOREAN_DIGITAL2 = 'koreanDigital2';
121+
//Vietnamese Numerals
122+
const VIETNAMESE_COUNTING = 'vietnameseCounting';
123+
//Lowercase Russian Alphabet
124+
const RUSSIAN_LOWER = 'russianLower';
125+
//Uppercase Russian Alphabet
126+
const RUSSIAN_UPPER = 'russianUpper';
127+
//No Numbering
128+
const NONE = 'none';
129+
//Number With Dashes
130+
const NUMBER_IN_DASH = 'numberInDash';
131+
//Hebrew Numerals
132+
const HEBREW1 = 'hebrew1';
133+
//Hebrew Alphabet
134+
const HEBREW2 = 'hebrew2';
135+
//Arabic Alphabet
136+
const ARABIC_ALPHA = 'arabicAlpha';
137+
//Arabic Abjad Numerals
138+
const ARABIC_ABJAD = 'arabicAbjad';
139+
//Hindi Vowels
140+
const HINDI_VOWELS = 'hindiVowels';
141+
//Hindi Consonants
142+
const HINDI_CONSONANTS = 'hindiConsonants';
143+
//Hindi Numbers
144+
const HINDI_NUMBERS = 'hindiNumbers';
145+
//Hindi Counting System
146+
const HINDI_COUNTING = 'hindiCounting';
147+
//Thai Letters
148+
const THAI_LETTERS = 'thaiLetters';
149+
//Thai Numerals
150+
const THAI_NUMBERS = 'thaiNumbers';
151+
//Thai Counting System
152+
const THAI_COUNTING = 'thaiCounting';
153+
}

0 commit comments

Comments
 (0)