Skip to content

Commit d8aef5c

Browse files
committed
Bugfix #294: add<elementName> of container should be case insensitive
1 parent 40e4134 commit d8aef5c

File tree

2 files changed

+13
-8
lines changed

2 files changed

+13
-8
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ This release added form fields (textinput, checkbox, and dropdown), drawing shap
2929
- `addHTML` encoding and ampersand fixes for PHP 5.3 - @bskrtich GH-270
3030
- Page breaks on titles and tables - @ivanlanin GH-274
3131
- Table inside vertical border does not rendered properly - @ivanlanin GH-280
32+
- `add<elementName>` of container should be case insensitive, e.g. `addToc` should be accepted, not only `addTOC` - @ivanlanin GH-294
3233

3334
### Deprecated
3435

src/PhpWord/Element/AbstractContainer.php

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -77,18 +77,22 @@ abstract class AbstractContainer extends AbstractElement
7777
*/
7878
public function __call($function, $args)
7979
{
80-
$elements = array('Text', 'TextRun', 'Link', 'PreserveText', 'TextBreak',
81-
'ListItem', 'ListItemRun', 'Table', 'Image', 'Object', 'Footnote',
82-
'Endnote', 'CheckBox', 'TextBox', 'Field', 'Line', 'Shape',
83-
'Title', 'TOC', 'PageBreak', 'Chart', 'FormField', 'SDT');
80+
$elements = array(
81+
'Text', 'TextRun', 'Link', 'PreserveText', 'TextBreak',
82+
'ListItem', 'ListItemRun', 'Table', 'Image', 'Object',
83+
'Footnote', 'Endnote', 'CheckBox', 'TextBox', 'Field',
84+
'Line', 'Shape', 'Title', 'TOC', 'PageBreak',
85+
'Chart', 'FormField', 'SDT'
86+
);
8487
$functions = array();
85-
for ($i = 0; $i < count($elements); $i++) {
86-
$functions[$i] = 'add' . $elements[$i];
88+
foreach ($elements as $element) {
89+
$functions['add' . strtolower($element)] = $element;
8790
}
8891

8992
// Run valid `add` command
90-
if (in_array($function, $functions)) {
91-
$element = str_replace('add', '', $function);
93+
$function = strtolower($function);
94+
if (array_key_exists($function, $functions)) {
95+
$element = $functions[$function];
9296

9397
// Special case for TextBreak
9498
// @todo Remove the `$count` parameter in 1.0.0 to make this element similiar to other elements?

0 commit comments

Comments
 (0)