diff --git a/CHANGELOG.md b/CHANGELOG.md index 0ba632cf..eae842bf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -29,6 +29,7 @@ This release added form fields (textinput, checkbox, and dropdown), drawing shap - `addHTML` encoding and ampersand fixes for PHP 5.3 - @bskrtich GH-270 - Page breaks on titles and tables - @ivanlanin GH-274 - Table inside vertical border does not rendered properly - @ivanlanin GH-280 +- `add` of container should be case insensitive, e.g. `addToc` should be accepted, not only `addTOC` - @ivanlanin GH-294 ### Deprecated diff --git a/src/PhpWord/Element/AbstractContainer.php b/src/PhpWord/Element/AbstractContainer.php index b934b2d8..686644eb 100644 --- a/src/PhpWord/Element/AbstractContainer.php +++ b/src/PhpWord/Element/AbstractContainer.php @@ -77,18 +77,22 @@ abstract class AbstractContainer extends AbstractElement */ public function __call($function, $args) { - $elements = array('Text', 'TextRun', 'Link', 'PreserveText', 'TextBreak', - 'ListItem', 'ListItemRun', 'Table', 'Image', 'Object', 'Footnote', - 'Endnote', 'CheckBox', 'TextBox', 'Field', 'Line', 'Shape', - 'Title', 'TOC', 'PageBreak', 'Chart', 'FormField', 'SDT'); + $elements = array( + 'Text', 'TextRun', 'Link', 'PreserveText', 'TextBreak', + 'ListItem', 'ListItemRun', 'Table', 'Image', 'Object', + 'Footnote', 'Endnote', 'CheckBox', 'TextBox', 'Field', + 'Line', 'Shape', 'Title', 'TOC', 'PageBreak', + 'Chart', 'FormField', 'SDT' + ); $functions = array(); - for ($i = 0; $i < count($elements); $i++) { - $functions[$i] = 'add' . $elements[$i]; + foreach ($elements as $element) { + $functions['add' . strtolower($element)] = $element; } // Run valid `add` command - if (in_array($function, $functions)) { - $element = str_replace('add', '', $function); + $function = strtolower($function); + if (array_key_exists($function, $functions)) { + $element = $functions[$function]; // Special case for TextBreak // @todo Remove the `$count` parameter in 1.0.0 to make this element similiar to other elements?