Bugfix #294: add<elementName> of container should be case insensitive

This commit is contained in:
Ivan Lanin 2014-07-01 09:52:24 +07:00
parent 40e41342ce
commit d8aef5c502
2 changed files with 13 additions and 8 deletions

View File

@ -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 - `addHTML` encoding and ampersand fixes for PHP 5.3 - @bskrtich GH-270
- Page breaks on titles and tables - @ivanlanin GH-274 - Page breaks on titles and tables - @ivanlanin GH-274
- Table inside vertical border does not rendered properly - @ivanlanin GH-280 - Table inside vertical border does not rendered properly - @ivanlanin GH-280
- `add<elementName>` of container should be case insensitive, e.g. `addToc` should be accepted, not only `addTOC` - @ivanlanin GH-294
### Deprecated ### Deprecated

View File

@ -77,18 +77,22 @@ abstract class AbstractContainer extends AbstractElement
*/ */
public function __call($function, $args) public function __call($function, $args)
{ {
$elements = array('Text', 'TextRun', 'Link', 'PreserveText', 'TextBreak', $elements = array(
'ListItem', 'ListItemRun', 'Table', 'Image', 'Object', 'Footnote', 'Text', 'TextRun', 'Link', 'PreserveText', 'TextBreak',
'Endnote', 'CheckBox', 'TextBox', 'Field', 'Line', 'Shape', 'ListItem', 'ListItemRun', 'Table', 'Image', 'Object',
'Title', 'TOC', 'PageBreak', 'Chart', 'FormField', 'SDT'); 'Footnote', 'Endnote', 'CheckBox', 'TextBox', 'Field',
'Line', 'Shape', 'Title', 'TOC', 'PageBreak',
'Chart', 'FormField', 'SDT'
);
$functions = array(); $functions = array();
for ($i = 0; $i < count($elements); $i++) { foreach ($elements as $element) {
$functions[$i] = 'add' . $elements[$i]; $functions['add' . strtolower($element)] = $element;
} }
// Run valid `add` command // Run valid `add` command
if (in_array($function, $functions)) { $function = strtolower($function);
$element = str_replace('add', '', $function); if (array_key_exists($function, $functions)) {
$element = $functions[$function];
// Special case for TextBreak // Special case for TextBreak
// @todo Remove the `$count` parameter in 1.0.0 to make this element similiar to other elements? // @todo Remove the `$count` parameter in 1.0.0 to make this element similiar to other elements?