diff --git a/.php-cs-fixer.dist.php b/.php-cs-fixer.dist.php new file mode 100644 index 00000000..14d58dac --- /dev/null +++ b/.php-cs-fixer.dist.php @@ -0,0 +1,228 @@ +notName('pclzip.lib.php') + ->notName('OLERead.php') + ->in('samples') + ->in('src') + ->in('tests'); + +$config = new PhpCsFixer\Config(); +$config + ->setRiskyAllowed(true) + ->setFinder($finder) + ->setCacheFile(sys_get_temp_dir() . '/php-cs-fixer' . preg_replace('~\W~', '-', __DIR__)) + ->setRules([ + 'align_multiline_comment' => true, + 'array_indentation' => true, + 'array_syntax' => ['syntax' => 'short'], + 'backtick_to_shell_exec' => true, + 'binary_operator_spaces' => true, + 'blank_line_after_namespace' => true, + 'blank_line_after_opening_tag' => true, + 'blank_line_before_statement' => true, + 'braces' => true, + 'cast_spaces' => true, + 'class_attributes_separation' => ['elements' => ['method' => 'one', 'property' => 'one']], // const are often grouped with other related const + 'class_definition' => false, + 'class_keyword_remove' => false, // ::class keyword gives us better support in IDE + 'combine_consecutive_issets' => true, + 'combine_consecutive_unsets' => true, + 'combine_nested_dirname' => true, + 'comment_to_phpdoc' => false, // interferes with annotations + 'compact_nullable_typehint' => true, + 'concat_space' => ['spacing' => 'one'], + 'constant_case' => true, + 'date_time_immutable' => false, // Break our unit tests + 'declare_equal_normalize' => true, + 'declare_strict_types' => false, // Too early to adopt strict types + 'dir_constant' => true, + 'doctrine_annotation_array_assignment' => true, + 'doctrine_annotation_braces' => true, + 'doctrine_annotation_indentation' => true, + 'doctrine_annotation_spaces' => true, + 'elseif' => true, + 'encoding' => true, + 'ereg_to_preg' => true, + 'escape_implicit_backslashes' => true, + 'explicit_indirect_variable' => false, // I feel it makes the code actually harder to read + 'explicit_string_variable' => false, // I feel it makes the code actually harder to read + 'final_class' => false, // We need non-final classes + 'final_internal_class' => true, + 'final_public_method_for_abstract_class' => false, // We need non-final methods + 'fopen_flag_order' => true, + 'fopen_flags' => true, + 'full_opening_tag' => true, + 'fully_qualified_strict_types' => true, + 'function_declaration' => true, + 'function_to_constant' => true, + 'function_typehint_space' => true, + 'general_phpdoc_annotation_remove' => ['annotations' => ['access', 'category', 'copyright', 'throws']], + 'global_namespace_import' => true, + 'header_comment' => false, // We don't use common header in all our files + 'heredoc_indentation' => false, // Requires PHP >= 7.3 + 'heredoc_to_nowdoc' => false, // Not sure about this one + 'implode_call' => true, + 'include' => true, + 'increment_style' => true, + 'indentation_type' => true, + 'is_null' => true, + 'line_ending' => true, + 'linebreak_after_opening_tag' => true, + 'list_syntax' => ['syntax' => 'short'], + 'logical_operators' => true, + 'lowercase_cast' => true, + 'lowercase_keywords' => true, + 'lowercase_static_reference' => true, + 'magic_constant_casing' => true, + 'magic_method_casing' => true, + 'mb_str_functions' => false, // No, too dangerous to change that + 'method_argument_space' => true, + 'method_chaining_indentation' => true, + 'modernize_types_casting' => true, + 'multiline_comment_opening_closing' => true, + 'multiline_whitespace_before_semicolons' => true, + 'native_constant_invocation' => false, // Micro optimization that look messy + 'native_function_casing' => true, + 'native_function_invocation' => false, // I suppose this would be best, but I am still unconvinced about the visual aspect of it + 'native_function_type_declaration_casing' => true, + 'new_with_braces' => true, + 'no_alias_functions' => true, + 'no_alternative_syntax' => true, + 'no_binary_string' => true, + 'no_blank_lines_after_class_opening' => true, + 'no_blank_lines_after_phpdoc' => true, + 'no_blank_lines_before_namespace' => false, // we want 1 blank line before namespace + 'no_break_comment' => true, + 'no_closing_tag' => true, + 'no_empty_comment' => true, + 'no_empty_phpdoc' => true, + 'no_empty_statement' => true, + 'no_extra_blank_lines' => true, + 'no_homoglyph_names' => true, + 'no_leading_import_slash' => true, + 'no_leading_namespace_whitespace' => true, + 'no_mixed_echo_print' => true, + 'no_multiline_whitespace_around_double_arrow' => true, + 'no_null_property_initialization' => true, + 'no_php4_constructor' => true, + 'no_short_bool_cast' => true, + 'echo_tag_syntax' => ['format' => 'long'], + 'no_singleline_whitespace_before_semicolons' => true, + 'no_spaces_after_function_name' => true, + 'no_spaces_around_offset' => true, + 'no_spaces_inside_parenthesis' => true, + 'no_superfluous_elseif' => false, // Might be risky on a huge code base + 'no_superfluous_phpdoc_tags' => ['allow_mixed' => true], + 'no_trailing_comma_in_list_call' => true, + 'no_trailing_comma_in_singleline_array' => true, + 'no_trailing_whitespace' => true, + 'no_trailing_whitespace_in_comment' => true, + 'no_unneeded_control_parentheses' => true, + 'no_unneeded_curly_braces' => true, + 'no_unneeded_final_method' => true, + 'no_unreachable_default_argument_value' => true, + 'no_unset_cast' => true, + 'no_unset_on_property' => true, + 'no_unused_imports' => true, + 'no_useless_else' => true, + 'no_useless_return' => true, + 'no_whitespace_before_comma_in_array' => true, + 'no_whitespace_in_blank_line' => true, + 'non_printable_character' => true, + 'normalize_index_brace' => true, + 'not_operator_with_space' => false, // No we prefer to keep '!' without spaces + 'not_operator_with_successor_space' => false, // idem + 'nullable_type_declaration_for_default_null_value' => true, + 'object_operator_without_whitespace' => true, + 'ordered_class_elements' => false, // We prefer to keep some freedom + 'ordered_imports' => true, + 'ordered_interfaces' => true, + 'php_unit_construct' => true, + 'php_unit_dedicate_assert' => true, + 'php_unit_dedicate_assert_internal_type' => true, + 'php_unit_expectation' => true, + 'php_unit_fqcn_annotation' => true, + 'php_unit_internal_class' => false, // Because tests are excluded from package + 'php_unit_method_casing' => true, + 'php_unit_mock' => true, + 'php_unit_mock_short_will_return' => true, + 'php_unit_namespaced' => true, + 'php_unit_no_expectation_annotation' => true, + 'phpdoc_order_by_value' => ['annotations' => ['covers']], + 'php_unit_set_up_tear_down_visibility' => true, + 'php_unit_size_class' => false, // That seems extra work to maintain for little benefits + 'php_unit_strict' => false, // We sometime actually need assertEquals + 'php_unit_test_annotation' => true, + 'php_unit_test_case_static_method_calls' => ['call_type' => 'self'], + 'php_unit_test_class_requires_covers' => false, // We don't care as much as we should about coverage + 'phpdoc_add_missing_param_annotation' => false, // Don't add things that bring no value + 'phpdoc_align' => false, // Waste of time + 'phpdoc_annotation_without_dot' => true, + 'phpdoc_indent' => true, + //'phpdoc_inline_tag' => true, + 'phpdoc_line_span' => false, // Unfortunately our old comments turn even uglier with this + 'phpdoc_no_access' => true, + 'phpdoc_no_alias_tag' => true, + 'phpdoc_no_empty_return' => true, + 'phpdoc_no_package' => true, + 'phpdoc_no_useless_inheritdoc' => true, + 'phpdoc_order' => true, + 'phpdoc_return_self_reference' => true, + 'phpdoc_scalar' => true, + 'phpdoc_separation' => true, + 'phpdoc_single_line_var_spacing' => true, + 'phpdoc_summary' => true, + 'phpdoc_to_comment' => false, // interferes with annotations + 'phpdoc_to_param_type' => false, // Because experimental, but interesting for one shot use + 'phpdoc_to_return_type' => false, // idem + 'phpdoc_trim' => true, + 'phpdoc_trim_consecutive_blank_line_separation' => true, + 'phpdoc_types' => true, + 'phpdoc_types_order' => true, + 'phpdoc_var_annotation_correct_order' => true, + 'phpdoc_var_without_name' => true, + 'pow_to_exponentiation' => true, + 'protected_to_private' => true, + //'psr0' => true, + //'psr4' => true, + 'random_api_migration' => true, + 'return_assignment' => false, // Sometimes useful for clarity or debug + 'return_type_declaration' => true, + 'self_accessor' => true, + 'self_static_accessor' => true, + 'semicolon_after_instruction' => false, // Buggy in `samples/index.php` + 'set_type_to_cast' => true, + 'short_scalar_cast' => true, + 'simple_to_complex_string_variable' => false, // Would differ from TypeScript without obvious advantages + 'simplified_null_return' => false, // Even if technically correct we prefer to be explicit + 'single_blank_line_at_eof' => true, + 'single_blank_line_before_namespace' => true, + 'single_class_element_per_statement' => true, + 'single_import_per_statement' => true, + 'single_line_after_imports' => true, + 'single_line_comment_style' => true, + 'single_line_throw' => false, // I don't see any reason for having a special case for Exception + 'single_quote' => true, + 'single_trait_insert_per_statement' => true, + 'space_after_semicolon' => true, + 'standardize_increment' => true, + 'standardize_not_equals' => true, + 'static_lambda' => false, // Risky if we can't guarantee nobody use `bindTo()` + 'strict_comparison' => false, // No, too dangerous to change that + 'strict_param' => false, // No, too dangerous to change that + 'string_line_ending' => true, + 'switch_case_semicolon_to_colon' => true, + 'switch_case_space' => true, + 'ternary_operator_spaces' => true, + 'ternary_to_null_coalescing' => true, + 'trailing_comma_in_multiline' => true, + 'trim_array_spaces' => true, + 'unary_operator_spaces' => true, + 'visibility_required' => ['elements' => ['property', 'method']], // not const + 'void_return' => true, + 'whitespace_after_comma_in_array' => true, + 'yoda_style' => false, + ]); + +return $config; diff --git a/.php_cs.dist b/.php_cs.dist deleted file mode 100644 index 895ed80f..00000000 --- a/.php_cs.dist +++ /dev/null @@ -1,146 +0,0 @@ -notName('pclzip.lib.php') - ->notName('OLERead.php') - ->in('samples') - ->in('src') - ->in('tests'); - -return PhpCsFixer\Config::create() - ->setRiskyAllowed(true) - ->setFinder($finder) - ->setRules(array( - 'array_syntax' => array('syntax' => 'long'), - 'binary_operator_spaces' => array('align_double_arrow' => true), - 'blank_line_after_namespace' => true, - 'blank_line_after_opening_tag' => false, - 'blank_line_before_return' => true, - 'braces' => true, - 'cast_spaces' => true, - 'class_definition' => true, - 'class_keyword_remove' => false, // ::class keyword gives us beter support in IDE - 'combine_consecutive_unsets' => true, - 'concat_space' => array('spacing' => 'one'), - 'declare_equal_normalize' => true, - 'declare_strict_types' => false, // Too early to adopt strict types - 'dir_constant' => true, - 'elseif' => true, - 'encoding' => true, - 'ereg_to_preg' => true, - 'full_opening_tag' => true, - 'function_declaration' => true, - 'function_typehint_space' => true, - 'general_phpdoc_annotation_remove' => false, // No use for that - 'hash_to_slash_comment' => true, - 'header_comment' => false, // We don't use common header in all our files - 'heredoc_to_nowdoc' => false, // Not sure about this one - 'is_null' => false, // Risky - 'include' => true, - 'indentation_type' => true, - 'line_ending' => true, - 'linebreak_after_opening_tag' => true, - 'lowercase_cast' => true, - 'lowercase_constants' => true, - 'lowercase_keywords' => true, - 'mb_str_functions' => false, // No, too dangerous to change that - 'method_argument_space' => true, - 'method_separation' => true, - 'modernize_types_casting' => true, - 'native_function_casing' => true, - 'native_function_invocation'=> false, // This is risky and seems to be micro-optimization that make code uglier so not worth it, at least for now - 'new_with_braces' => true, - 'no_alias_functions' => true, - 'no_blank_lines_after_class_opening' => true, - 'no_blank_lines_after_phpdoc' => true, - 'no_blank_lines_before_namespace' => false, // we want 1 blank line before namespace - 'no_closing_tag' => true, - 'no_empty_comment' => true, - 'no_empty_phpdoc' => true, - 'no_empty_statement' => true, - 'no_extra_consecutive_blank_lines' => array('break', 'continue', 'extra', 'return', 'throw', 'use', 'useTrait', 'curly_brace_block', 'parenthesis_brace_block', 'square_brace_block'), - 'no_leading_import_slash' => true, - 'no_leading_namespace_whitespace' => true, - 'no_mixed_echo_print' => true, - 'no_multiline_whitespace_around_double_arrow' => true, - 'no_multiline_whitespace_before_semicolons' => true, - 'no_php4_constructor' => true, - 'no_short_bool_cast' => true, - 'no_short_echo_tag' => true, - 'no_singleline_whitespace_before_semicolons' => true, - 'no_spaces_after_function_name' => true, - 'no_spaces_around_offset' => true, - 'no_spaces_inside_parenthesis' => true, - 'no_trailing_comma_in_list_call' => true, - 'no_trailing_comma_in_singleline_array' => true, - 'no_trailing_whitespace' => true, - 'no_trailing_whitespace_in_comment' => true, - 'no_unneeded_control_parentheses' => true, - 'no_unreachable_default_argument_value' => true, - 'no_unused_imports' => true, - 'no_useless_else' => true, - 'no_useless_return' => true, - 'no_whitespace_before_comma_in_array' => true, - 'no_whitespace_in_blank_line' => true, - 'normalize_index_brace' => true, - 'not_operator_with_space' => false, // No we prefer to keep '!' without spaces - 'not_operator_with_successor_space' => false, // idem - 'object_operator_without_whitespace' => true, - 'ordered_class_elements' => false, // We prefer to keep some freedom - 'ordered_imports' => true, - 'php_unit_construct' => true, - 'php_unit_dedicate_assert' => true, - 'php_unit_fqcn_annotation' => true, - 'php_unit_strict' => false, // We sometime actually need assertEquals - 'phpdoc_add_missing_param_annotation' => true, - 'phpdoc_align' => false, // Waste of time - 'phpdoc_annotation_without_dot' => true, - 'phpdoc_indent' => true, - 'phpdoc_inline_tag' => true, - 'phpdoc_no_access' => true, - 'phpdoc_no_alias_tag' => true, - 'phpdoc_no_empty_return' => true, - 'phpdoc_no_package' => true, - 'phpdoc_no_useless_inheritdoc' => true, - 'phpdoc_order' => true, - 'phpdoc_return_self_reference' => true, - 'phpdoc_scalar' => true, - 'phpdoc_separation' => false, - 'phpdoc_single_line_var_spacing' => true, - 'phpdoc_summary' => false, - 'phpdoc_to_comment' => true, - 'phpdoc_trim' => true, - 'phpdoc_types' => true, - 'phpdoc_var_without_name' => true, - 'pow_to_exponentiation' => false, - 'pre_increment' => false, - 'protected_to_private' => true, - 'psr0' => true, - 'psr4' => true, - 'random_api_migration' => false, // This breaks our unit tests - 'return_type_declaration' => true, - 'self_accessor' => true, - 'semicolon_after_instruction' => false, // Buggy in `samples/index.php` - 'short_scalar_cast' => true, - 'silenced_deprecation_error' => true, - 'simplified_null_return' => false, // While technically correct we prefer to be explicit when returning null - 'single_blank_line_at_eof' => true, - 'single_blank_line_before_namespace' => true, - 'single_class_element_per_statement' => true, - 'single_import_per_statement' => true, - 'single_line_after_imports' => true, - 'single_quote' => true, - 'space_after_semicolon' => true, - 'standardize_not_equals' => true, - 'strict_comparison' => false, // No, too dangerous to change that - 'strict_param' => false, // No, too dangerous to change that - 'switch_case_semicolon_to_colon' => true, - 'switch_case_space' => true, - 'ternary_operator_spaces' => true, - 'ternary_to_null_coalescing' => false, // Cannot use that with PHP 5.6 - 'trailing_comma_in_multiline_array' => true, - 'trim_array_spaces' => false, - 'unary_operator_spaces' => true, - 'visibility_required' => true, - 'whitespace_after_comma_in_array' => true, - )); diff --git a/samples/Sample_01_SimpleText.php b/samples/Sample_01_SimpleText.php index 8af44d20..e89f7323 100644 --- a/samples/Sample_01_SimpleText.php +++ b/samples/Sample_01_SimpleText.php @@ -1,4 +1,5 @@ getSettings()->setThemeFontLang($languageEnGb); $fontStyleName = 'rStyle'; -$phpWord->addFontStyle($fontStyleName, array('bold' => true, 'italic' => true, 'size' => 16, 'allCaps' => true, 'doubleStrikethrough' => true)); +$phpWord->addFontStyle($fontStyleName, ['bold' => true, 'italic' => true, 'size' => 16, 'allCaps' => true, 'doubleStrikethrough' => true]); $paragraphStyleName = 'pStyle'; -$phpWord->addParagraphStyle($paragraphStyleName, array('alignment' => \PhpOffice\PhpWord\SimpleType\Jc::CENTER, 'spaceAfter' => 100)); +$phpWord->addParagraphStyle($paragraphStyleName, ['alignment' => \PhpOffice\PhpWord\SimpleType\Jc::CENTER, 'spaceAfter' => 100]); -$phpWord->addTitleStyle(1, array('bold' => true), array('spaceAfter' => 240)); +$phpWord->addTitleStyle(1, ['bold' => true], ['spaceAfter' => 240]); // New portrait section $section = $phpWord->addSection(); @@ -28,7 +29,7 @@ $section->addText('Hello World!'); // $pStyle = new Font(); // $pStyle->setLang() -$section->addText('Ce texte-ci est en français.', array('lang' => \PhpOffice\PhpWord\Style\Language::FR_BE)); +$section->addText('Ce texte-ci est en français.', ['lang' => \PhpOffice\PhpWord\Style\Language::FR_BE]); // Two text break $section->addTextBreak(2); @@ -47,33 +48,33 @@ $fontStyle['size'] = 20; $textrun = $section->addTextRun(); $textrun->addText('I am inline styled ', $fontStyle); $textrun->addText('with '); -$textrun->addText('color', array('color' => '996699')); +$textrun->addText('color', ['color' => '996699']); $textrun->addText(', '); -$textrun->addText('bold', array('bold' => true)); +$textrun->addText('bold', ['bold' => true]); $textrun->addText(', '); -$textrun->addText('italic', array('italic' => true)); +$textrun->addText('italic', ['italic' => true]); $textrun->addText(', '); -$textrun->addText('underline', array('underline' => 'dash')); +$textrun->addText('underline', ['underline' => 'dash']); $textrun->addText(', '); -$textrun->addText('strikethrough', array('strikethrough' => true)); +$textrun->addText('strikethrough', ['strikethrough' => true]); $textrun->addText(', '); -$textrun->addText('doubleStrikethrough', array('doubleStrikethrough' => true)); +$textrun->addText('doubleStrikethrough', ['doubleStrikethrough' => true]); $textrun->addText(', '); -$textrun->addText('superScript', array('superScript' => true)); +$textrun->addText('superScript', ['superScript' => true]); $textrun->addText(', '); -$textrun->addText('subScript', array('subScript' => true)); +$textrun->addText('subScript', ['subScript' => true]); $textrun->addText(', '); -$textrun->addText('smallCaps', array('smallCaps' => true)); +$textrun->addText('smallCaps', ['smallCaps' => true]); $textrun->addText(', '); -$textrun->addText('allCaps', array('allCaps' => true)); +$textrun->addText('allCaps', ['allCaps' => true]); $textrun->addText(', '); -$textrun->addText('fgColor', array('fgColor' => 'yellow')); +$textrun->addText('fgColor', ['fgColor' => 'yellow']); $textrun->addText(', '); -$textrun->addText('scale', array('scale' => 200)); +$textrun->addText('scale', ['scale' => 200]); $textrun->addText(', '); -$textrun->addText('spacing', array('spacing' => 120)); +$textrun->addText('spacing', ['spacing' => 120]); $textrun->addText(', '); -$textrun->addText('kerning', array('kerning' => 10)); +$textrun->addText('kerning', ['kerning' => 10]); $textrun->addText('. '); // Link @@ -81,7 +82,7 @@ $section->addLink('https://github.com/PHPOffice/PHPWord', 'PHPWord on GitHub'); $section->addTextBreak(); // Image -$section->addImage('resources/_earth.jpg', array('width'=>18, 'height'=>18)); +$section->addImage('resources/_earth.jpg', ['width' => 18, 'height' => 18]); // Save file echo write($phpWord, basename(__FILE__, '.php'), $writers); diff --git a/samples/Sample_02_TabStops.php b/samples/Sample_02_TabStops.php index 4f588ee7..74a0ed1f 100644 --- a/samples/Sample_02_TabStops.php +++ b/samples/Sample_02_TabStops.php @@ -1,4 +1,5 @@ addParagraphStyle( $multipleTabsStyleName, - array( - 'tabs' => array( + [ + 'tabs' => [ new \PhpOffice\PhpWord\Style\Tab('left', 1550), new \PhpOffice\PhpWord\Style\Tab('center', 3200), new \PhpOffice\PhpWord\Style\Tab('right', 5300), - ), - ) + ], + ] ); $rightTabStyleName = 'rightTab'; -$phpWord->addParagraphStyle($rightTabStyleName, array('tabs' => array(new \PhpOffice\PhpWord\Style\Tab('right', 9090)))); +$phpWord->addParagraphStyle($rightTabStyleName, ['tabs' => [new \PhpOffice\PhpWord\Style\Tab('right', 9090)]]); $leftTabStyleName = 'centerTab'; -$phpWord->addParagraphStyle($leftTabStyleName, array('tabs' => array(new \PhpOffice\PhpWord\Style\Tab('center', 4680)))); +$phpWord->addParagraphStyle($leftTabStyleName, ['tabs' => [new \PhpOffice\PhpWord\Style\Tab('center', 4680)]]); // New portrait section $section = $phpWord->addSection(); diff --git a/samples/Sample_03_Sections.php b/samples/Sample_03_Sections.php index 5bb9ecc2..b02a277c 100644 --- a/samples/Sample_03_Sections.php +++ b/samples/Sample_03_Sections.php @@ -1,4 +1,5 @@ addSection(array('borderColor' => '00FF00', 'borderSize' => 12)); +$section = $phpWord->addSection(['borderColor' => '00FF00', 'borderSize' => 12]); $section->addText('I am placed on a default section.'); // New landscape section -$section = $phpWord->addSection(array('orientation' => 'landscape')); +$section = $phpWord->addSection(['orientation' => 'landscape']); $section->addText('I am placed on a landscape section. Every page starting from this section will be landscape style.'); $section->addPageBreak(); $section->addPageBreak(); // New portrait section $section = $phpWord->addSection( - array('paperSize' => 'Folio', 'marginLeft' => 600, 'marginRight' => 600, 'marginTop' => 600, 'marginBottom' => 600) + ['paperSize' => 'Folio', 'marginLeft' => 600, 'marginRight' => 600, 'marginTop' => 600, 'marginBottom' => 600] ); $section->addText('This section uses other margins with folio papersize.'); // The text of this section is vertically centered $section = $phpWord->addSection( - array('vAlign' => VerticalJc::CENTER) + ['vAlign' => VerticalJc::CENTER] ); $section->addText('This section is vertically centered.'); // New portrait section with Header & Footer $section = $phpWord->addSection( - array( - 'marginLeft' => 200, - 'marginRight' => 200, - 'marginTop' => 200, + [ + 'marginLeft' => 200, + 'marginRight' => 200, + 'marginTop' => 200, 'marginBottom' => 200, 'headerHeight' => 50, 'footerHeight' => 50, - ) + ] ); $section->addText('This section and we play with header/footer height.'); $section->addHeader()->addText('Header'); diff --git a/samples/Sample_04_Textrun.php b/samples/Sample_04_Textrun.php index ecd0c88a..33af08a5 100644 --- a/samples/Sample_04_Textrun.php +++ b/samples/Sample_04_Textrun.php @@ -1,4 +1,5 @@ addParagraphStyle($paragraphStyleName, array('spacing' => 100)); +$phpWord->addParagraphStyle($paragraphStyleName, ['spacing' => 100]); $boldFontStyleName = 'BoldText'; -$phpWord->addFontStyle($boldFontStyleName, array('bold' => true)); +$phpWord->addFontStyle($boldFontStyleName, ['bold' => true]); $coloredFontStyleName = 'ColoredText'; -$phpWord->addFontStyle($coloredFontStyleName, array('color' => 'FF8080', 'bgColor' => 'FFFFCC')); +$phpWord->addFontStyle($coloredFontStyleName, ['color' => 'FF8080', 'bgColor' => 'FFFFCC']); $linkFontStyleName = 'NLink'; -$phpWord->addLinkStyle($linkFontStyleName, array('color' => '0000FF', 'underline' => \PhpOffice\PhpWord\Style\Font::UNDERLINE_SINGLE)); +$phpWord->addLinkStyle($linkFontStyleName, ['color' => '0000FF', 'underline' => \PhpOffice\PhpWord\Style\Font::UNDERLINE_SINGLE]); // New portrait section $section = $phpWord->addSection(); @@ -26,21 +27,21 @@ $textrun = $section->addTextRun($paragraphStyleName); $textrun->addText('Each textrun can contain native text, link elements or an image.'); $textrun->addText(' No break is placed after adding an element.', $boldFontStyleName); $textrun->addText(' Both '); -$textrun->addText('superscript', array('superScript' => true)); +$textrun->addText('superscript', ['superScript' => true]); $textrun->addText(' and '); -$textrun->addText('subscript', array('subScript' => true)); +$textrun->addText('subscript', ['subScript' => true]); $textrun->addText(' are also available.'); $textrun->addText(' All elements are placed inside a paragraph with the optionally given paragraph style.', $coloredFontStyleName); $textrun->addText(' Sample Link: '); $textrun->addLink('https://github.com/PHPOffice/PHPWord', 'PHPWord on GitHub', $linkFontStyleName); $textrun->addText(' Sample Image: '); -$textrun->addImage('resources/_earth.jpg', array('width' => 18, 'height' => 18)); +$textrun->addImage('resources/_earth.jpg', ['width' => 18, 'height' => 18]); $textrun->addText(' Sample Object: '); $textrun->addObject('resources/_sheet.xls'); $textrun->addText(' Here is some more text. '); $textrun = $section->addTextRun(); -$textrun->addText('This text is not visible.', array('hidden' => true)); +$textrun->addText('This text is not visible.', ['hidden' => true]); // Save file echo write($phpWord, basename(__FILE__, '.php'), $writers); diff --git a/samples/Sample_05_Multicolumn.php b/samples/Sample_05_Multicolumn.php index f7cefa58..093dd604 100644 --- a/samples/Sample_05_Multicolumn.php +++ b/samples/Sample_05_Multicolumn.php @@ -1,4 +1,5 @@ addText("Normal paragraph. {$filler}"); // Two columns $section = $phpWord->addSection( - array( - 'colsNum' => 2, + [ + 'colsNum' => 2, 'colsSpace' => 1440, 'breakType' => 'continuous', - ) + ] ); $section->addText("Two columns, one inch (1440 twips) spacing. {$filler}"); // Normal -$section = $phpWord->addSection(array('breakType' => 'continuous')); +$section = $phpWord->addSection(['breakType' => 'continuous']); $section->addText("Normal paragraph again. {$filler}"); // Three columns $section = $phpWord->addSection( - array( - 'colsNum' => 3, + [ + 'colsNum' => 3, 'colsSpace' => 720, 'breakType' => 'continuous', - ) + ] ); $section->addText("Three columns, half inch (720 twips) spacing. {$filler}"); // Normal -$section = $phpWord->addSection(array('breakType' => 'continuous')); +$section = $phpWord->addSection(['breakType' => 'continuous']); $section->addText("Normal paragraph again. {$filler}"); // Save file diff --git a/samples/Sample_06_Footnote.php b/samples/Sample_06_Footnote.php index 19d6a524..f3c369b3 100644 --- a/samples/Sample_06_Footnote.php +++ b/samples/Sample_06_Footnote.php @@ -1,4 +1,5 @@ addParagraphStyle($paragraphStyleName, array('spacing' => 100)); +$phpWord->addParagraphStyle($paragraphStyleName, ['spacing' => 100]); $boldFontStyleName = 'BoldText'; -$phpWord->addFontStyle($boldFontStyleName, array('bold' => true)); +$phpWord->addFontStyle($boldFontStyleName, ['bold' => true]); $coloredFontStyleName = 'ColoredText'; -$phpWord->addFontStyle($coloredFontStyleName, array('color' => 'FF8080', 'bgColor' => 'FFFFCC')); +$phpWord->addFontStyle($coloredFontStyleName, ['color' => 'FF8080', 'bgColor' => 'FFFFCC']); $linkFontStyleName = 'NLink'; -$phpWord->addLinkStyle($linkFontStyleName, array('color' => '0000FF', 'underline' => \PhpOffice\PhpWord\Style\Font::UNDERLINE_SINGLE)); +$phpWord->addLinkStyle($linkFontStyleName, ['color' => '0000FF', 'underline' => \PhpOffice\PhpWord\Style\Font::UNDERLINE_SINGLE]); // New portrait section $section = $phpWord->addSection(); @@ -38,7 +39,7 @@ $footnote->addText('But you can insert a manual text break like above, '); $footnote->addText('links like '); $footnote->addLink('https://github.com/PHPOffice/PHPWord', 'PHPWord on GitHub', $linkFontStyleName); $footnote->addText(', image like '); -$footnote->addImage('resources/_earth.jpg', array('width' => 18, 'height' => 18)); +$footnote->addImage('resources/_earth.jpg', ['width' => 18, 'height' => 18]); $footnote->addText(', or object like '); $footnote->addObject('resources/_sheet.xls'); $footnote->addText('But you can only put footnote in section, not in header or footer.'); diff --git a/samples/Sample_07_TemplateCloneRow.php b/samples/Sample_07_TemplateCloneRow.php index 42c53269..a921569f 100644 --- a/samples/Sample_07_TemplateCloneRow.php +++ b/samples/Sample_07_TemplateCloneRow.php @@ -1,4 +1,5 @@ setValue('rowNumber#9', '9'); $templateProcessor->setValue('rowNumber#10', '10'); // Table with a spanned cell -$values = array( - array( - 'userId' => 1, +$values = [ + [ + 'userId' => 1, 'userFirstName' => 'James', - 'userName' => 'Taylor', - 'userPhone' => '+1 428 889 773', - ), - array( - 'userId' => 2, + 'userName' => 'Taylor', + 'userPhone' => '+1 428 889 773', + ], + [ + 'userId' => 2, 'userFirstName' => 'Robert', - 'userName' => 'Bell', - 'userPhone' => '+1 428 889 774', - ), - array( - 'userId' => 3, + 'userName' => 'Bell', + 'userPhone' => '+1 428 889 774', + ], + [ + 'userId' => 3, 'userFirstName' => 'Michael', - 'userName' => 'Ray', - 'userPhone' => '+1 428 889 775', - ), -); + 'userName' => 'Ray', + 'userPhone' => '+1 428 889 775', + ], +]; $templateProcessor->cloneRowAndSetValues('userId', $values); @@ -80,7 +81,7 @@ $templateProcessor->cloneRowAndSetValues('userId', $values); echo date('H:i:s'), ' Saving the result document...', EOL; $templateProcessor->saveAs('results/Sample_07_TemplateCloneRow.docx'); -echo getEndingNotes(array('Word2007' => 'docx'), 'results/Sample_07_TemplateCloneRow.docx'); +echo getEndingNotes(['Word2007' => 'docx'], 'results/Sample_07_TemplateCloneRow.docx'); if (!CLI) { include_once 'Sample_Footer.php'; } diff --git a/samples/Sample_08_ParagraphPagination.php b/samples/Sample_08_ParagraphPagination.php index 3c21b138..f343366a 100644 --- a/samples/Sample_08_ParagraphPagination.php +++ b/samples/Sample_08_ParagraphPagination.php @@ -1,15 +1,16 @@ setDefaultParagraphStyle( - array( - 'alignment' => \PhpOffice\PhpWord\SimpleType\Jc::BOTH, + [ + 'alignment' => \PhpOffice\PhpWord\SimpleType\Jc::BOTH, 'spaceAfter' => \PhpOffice\PhpWord\Shared\Converter::pointToTwip(12), - 'spacing' => 120, - ) + 'spacing' => 120, + ] ); // New section @@ -19,8 +20,8 @@ $section->addText( 'Below are the samples on how to control your paragraph ' . 'pagination. See "Line and Page Break" tab on paragraph properties ' . 'window to see the attribute set by these controls.', - array('bold' => true), - array('space' => array('before' => 360, 'after' => 480)) + ['bold' => true], + ['space' => ['before' => 360, 'after' => 480]] ); $section->addText( @@ -30,7 +31,7 @@ $section->addText( . 'itself at the bottom of a page. Set this option to "false" if you want ' . 'to disable this automatic control.', null, - array('widowControl' => false, 'indentation' => array('left' => 240, 'right' => 120)) + ['widowControl' => false, 'indentation' => ['left' => 240, 'right' => 120]] ); $section->addText( @@ -39,7 +40,7 @@ $section->addText( . 'breaks between paragraphs. Set this option to "true" if you do not want ' . 'your paragraph to be separated with the next paragraph.', null, - array('keepNext' => true, 'indentation' => array('firstLine' => 240)) + ['keepNext' => true, 'indentation' => ['firstLine' => 240]] ); $section->addText( @@ -48,7 +49,7 @@ $section->addText( . 'break within a paragraph. Set this option to "true" if you do not want ' . 'all lines of your paragraph to be in the same page.', null, - array('keepLines' => true, 'indentation' => array('left' => 240, 'hanging' => 240)) + ['keepLines' => true, 'indentation' => ['left' => 240, 'hanging' => 240]] ); $section->addText('Keep scrolling. More below.'); @@ -59,7 +60,7 @@ $section->addText( . 'your paragraph into the next page. This option is most useful for ' . 'heading styles.', null, - array('pageBreakBefore' => true) + ['pageBreakBefore' => true] ); // Save file diff --git a/samples/Sample_09_Tables.php b/samples/Sample_09_Tables.php index 31155438..f1b67c9e 100644 --- a/samples/Sample_09_Tables.php +++ b/samples/Sample_09_Tables.php @@ -1,4 +1,5 @@ addSection(); -$header = array('size' => 16, 'bold' => true); +$header = ['size' => 16, 'bold' => true]; // 1. Basic table @@ -17,9 +18,9 @@ $cols = 5; $section->addText('Basic table', $header); $table = $section->addTable(); -for ($r = 1; $r <= $rows; $r++) { +for ($r = 1; $r <= $rows; ++$r) { $table->addRow(); - for ($c = 1; $c <= $cols; $c++) { + for ($c = 1; $c <= $cols; ++$c) { $table->addCell(1750)->addText("Row {$r}, Cell {$c}"); } } @@ -30,11 +31,11 @@ $section->addTextBreak(1); $section->addText('Fancy table', $header); $fancyTableStyleName = 'Fancy Table'; -$fancyTableStyle = array('borderSize' => 6, 'borderColor' => '006699', 'cellMargin' => 80, 'alignment' => \PhpOffice\PhpWord\SimpleType\JcTable::CENTER, 'cellSpacing' => 50); -$fancyTableFirstRowStyle = array('borderBottomSize' => 18, 'borderBottomColor' => '0000FF', 'bgColor' => '66BBFF'); -$fancyTableCellStyle = array('valign' => 'center'); -$fancyTableCellBtlrStyle = array('valign' => 'center', 'textDirection' => \PhpOffice\PhpWord\Style\Cell::TEXT_DIR_BTLR); -$fancyTableFontStyle = array('bold' => true); +$fancyTableStyle = ['borderSize' => 6, 'borderColor' => '006699', 'cellMargin' => 80, 'alignment' => \PhpOffice\PhpWord\SimpleType\JcTable::CENTER, 'cellSpacing' => 50]; +$fancyTableFirstRowStyle = ['borderBottomSize' => 18, 'borderBottomColor' => '0000FF', 'bgColor' => '66BBFF']; +$fancyTableCellStyle = ['valign' => 'center']; +$fancyTableCellBtlrStyle = ['valign' => 'center', 'textDirection' => \PhpOffice\PhpWord\Style\Cell::TEXT_DIR_BTLR]; +$fancyTableFontStyle = ['bold' => true]; $phpWord->addTableStyle($fancyTableStyleName, $fancyTableStyle, $fancyTableFirstRowStyle); $table = $section->addTable($fancyTableStyleName); $table->addRow(900); @@ -43,7 +44,7 @@ $table->addCell(2000, $fancyTableCellStyle)->addText('Row 2', $fancyTableFontSty $table->addCell(2000, $fancyTableCellStyle)->addText('Row 3', $fancyTableFontStyle); $table->addCell(2000, $fancyTableCellStyle)->addText('Row 4', $fancyTableFontStyle); $table->addCell(500, $fancyTableCellBtlrStyle)->addText('Row 5', $fancyTableFontStyle); -for ($i = 1; $i <= 8; $i++) { +for ($i = 1; $i <= 8; ++$i) { $table->addRow(); $table->addCell(2000)->addText("Cell {$i}"); $table->addCell(2000)->addText("Cell {$i}"); @@ -65,12 +66,12 @@ for ($i = 1; $i <= 8; $i++) { $section->addPageBreak(); $section->addText('Table with colspan and rowspan', $header); -$fancyTableStyle = array('borderSize' => 6, 'borderColor' => '999999'); -$cellRowSpan = array('vMerge' => 'restart', 'valign' => 'center', 'bgColor' => 'FFFF00'); -$cellRowContinue = array('vMerge' => 'continue'); -$cellColSpan = array('gridSpan' => 2, 'valign' => 'center'); -$cellHCentered = array('alignment' => \PhpOffice\PhpWord\SimpleType\Jc::CENTER); -$cellVCentered = array('valign' => 'center'); +$fancyTableStyle = ['borderSize' => 6, 'borderColor' => '999999']; +$cellRowSpan = ['vMerge' => 'restart', 'valign' => 'center', 'bgColor' => 'FFFF00']; +$cellRowContinue = ['vMerge' => 'continue']; +$cellColSpan = ['gridSpan' => 2, 'valign' => 'center']; +$cellHCentered = ['alignment' => \PhpOffice\PhpWord\SimpleType\Jc::CENTER]; +$cellVCentered = ['valign' => 'center']; $spanTableStyleName = 'Colspan Rowspan'; $phpWord->addTableStyle($spanTableStyleName, $fancyTableStyle); @@ -111,22 +112,22 @@ $table->addCell(null, $cellRowContinue); $section->addPageBreak(); $section->addText('Table with colspan and rowspan', $header); -$styleTable = array('borderSize' => 6, 'borderColor' => '999999'); +$styleTable = ['borderSize' => 6, 'borderColor' => '999999']; $phpWord->addTableStyle('Colspan Rowspan', $styleTable); $table = $section->addTable('Colspan Rowspan'); $row = $table->addRow(); -$row->addCell(1000, array('vMerge' => 'restart'))->addText('A'); -$row->addCell(1000, array('gridSpan' => 2, 'vMerge' => 'restart'))->addText('B'); +$row->addCell(1000, ['vMerge' => 'restart'])->addText('A'); +$row->addCell(1000, ['gridSpan' => 2, 'vMerge' => 'restart'])->addText('B'); $row->addCell(1000)->addText('1'); $row = $table->addRow(); -$row->addCell(1000, array('vMerge' => 'continue')); -$row->addCell(1000, array('vMerge' => 'continue', 'gridSpan' => 2)); +$row->addCell(1000, ['vMerge' => 'continue']); +$row->addCell(1000, ['vMerge' => 'continue', 'gridSpan' => 2]); $row->addCell(1000)->addText('2'); $row = $table->addRow(); -$row->addCell(1000, array('vMerge' => 'continue')); +$row->addCell(1000, ['vMerge' => 'continue']); $row->addCell(1000)->addText('C'); $row->addCell(1000)->addText('D'); $row->addCell(1000)->addText('3'); @@ -136,10 +137,10 @@ $row->addCell(1000)->addText('3'); $section->addTextBreak(2); $section->addText('Nested table in a centered and 50% width table.', $header); -$table = $section->addTable(array('width' => 50 * 50, 'unit' => 'pct', 'alignment' => \PhpOffice\PhpWord\SimpleType\JcTable::CENTER)); +$table = $section->addTable(['width' => 50 * 50, 'unit' => 'pct', 'alignment' => \PhpOffice\PhpWord\SimpleType\JcTable::CENTER]); $cell = $table->addRow()->addCell(); $cell->addText('This cell contains nested table.'); -$innerCell = $cell->addTable(array('alignment' => \PhpOffice\PhpWord\SimpleType\JcTable::CENTER))->addRow()->addCell(); +$innerCell = $cell->addTable(['alignment' => \PhpOffice\PhpWord\SimpleType\JcTable::CENTER])->addRow()->addCell(); $innerCell->addText('Inside nested table'); // 6. Table with floating position @@ -147,7 +148,7 @@ $innerCell->addText('Inside nested table'); $section->addTextBreak(2); $section->addText('Table with floating positioning.', $header); -$table = $section->addTable(array('borderSize' => 6, 'borderColor' => '999999', 'position' => array('vertAnchor' => TablePosition::VANCHOR_TEXT, 'bottomFromText' => Converter::cmToTwip(1)))); +$table = $section->addTable(['borderSize' => 6, 'borderColor' => '999999', 'position' => ['vertAnchor' => TablePosition::VANCHOR_TEXT, 'bottomFromText' => Converter::cmToTwip(1)]]); $cell = $table->addRow()->addCell(); $cell->addText('This is a single cell.'); diff --git a/samples/Sample_10_EastAsianFontStyle.php b/samples/Sample_10_EastAsianFontStyle.php index 87345ae0..c8a6ec3a 100644 --- a/samples/Sample_10_EastAsianFontStyle.php +++ b/samples/Sample_10_EastAsianFontStyle.php @@ -1,13 +1,14 @@ addSection(); -$header = array('size' => 16, 'bold' => true); +$header = ['size' => 16, 'bold' => true]; //1.Use EastAisa FontStyle -$section->addText('中文楷体样式测试', array('name' => '楷体', 'size' => 16, 'color' => '1B2232', 'lang' => array('latin' => 'en-US', 'eastAsia' => 'zh-CN'))); +$section->addText('中文楷体样式测试', ['name' => '楷体', 'size' => 16, 'color' => '1B2232', 'lang' => ['latin' => 'en-US', 'eastAsia' => 'zh-CN']]); // Save file echo write($phpWord, basename(__FILE__, '.php'), $writers); diff --git a/samples/Sample_11_ReadWord2007.php b/samples/Sample_11_ReadWord2007.php index c0b54c7a..313cc007 100644 --- a/samples/Sample_11_ReadWord2007.php +++ b/samples/Sample_11_ReadWord2007.php @@ -1,4 +1,5 @@ addCell(4500); $textrun = $cell->addTextRun(); $textrun->addText('This is the header with '); $textrun->addLink('https://github.com/PHPOffice/PHPWord', 'PHPWord on GitHub'); -$table->addCell(4500)->addImage('resources/PhpWord.png', array('width' => 80, 'height' => 80, 'alignment' => \PhpOffice\PhpWord\SimpleType\Jc::END)); +$table->addCell(4500)->addImage('resources/PhpWord.png', ['width' => 80, 'height' => 80, 'alignment' => \PhpOffice\PhpWord\SimpleType\Jc::END]); // Add header for all other pages $subsequent = $section->addHeader(); $subsequent->addText('Subsequent pages in Section 1 will Have this!'); -$subsequent->addImage('resources/_mars.jpg', array('width' => 80, 'height' => 80)); +$subsequent->addImage('resources/_mars.jpg', ['width' => 80, 'height' => 80]); // Add footer $footer = $section->addFooter(); -$footer->addPreserveText('Page {PAGE} of {NUMPAGES}.', null, array('alignment' => \PhpOffice\PhpWord\SimpleType\Jc::CENTER)); +$footer->addPreserveText('Page {PAGE} of {NUMPAGES}.', null, ['alignment' => \PhpOffice\PhpWord\SimpleType\Jc::CENTER]); $footer->addLink('https://github.com/PHPOffice/PHPWord', 'PHPWord on GitHub'); // Write some text diff --git a/samples/Sample_13_Images.php b/samples/Sample_13_Images.php index f7be3be9..30b9cae9 100644 --- a/samples/Sample_13_Images.php +++ b/samples/Sample_13_Images.php @@ -1,4 +1,5 @@ addImage('resources/_mars.jpg'); printSeparator($section); $section->addText('Local image with styles:'); -$section->addImage('resources/_earth.jpg', array('width' => 210, 'height' => 210, 'alignment' => \PhpOffice\PhpWord\SimpleType\Jc::CENTER)); +$section->addImage('resources/_earth.jpg', ['width' => 210, 'height' => 210, 'alignment' => \PhpOffice\PhpWord\SimpleType\Jc::CENTER]); // Remote image printSeparator($section); @@ -33,21 +34,21 @@ $section->addImage($fileContent); //Wrapping style printSeparator($section); $text = str_repeat('Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. ', 2); -$wrappingStyles = array('inline', 'behind', 'infront', 'square', 'tight'); +$wrappingStyles = ['inline', 'behind', 'infront', 'square', 'tight']; foreach ($wrappingStyles as $wrappingStyle) { $section->addText("Wrapping style {$wrappingStyle}"); $section->addImage( 'resources/_earth.jpg', - array( - 'positioning' => 'relative', - 'marginTop' => -1, - 'marginLeft' => 1, - 'width' => 80, - 'height' => 80, - 'wrappingStyle' => $wrappingStyle, - 'wrapDistanceRight' => Converter::cmToPoint(1), + [ + 'positioning' => 'relative', + 'marginTop' => -1, + 'marginLeft' => 1, + 'width' => 80, + 'height' => 80, + 'wrappingStyle' => $wrappingStyle, + 'wrapDistanceRight' => Converter::cmToPoint(1), 'wrapDistanceBottom' => Converter::cmToPoint(1), - ) + ] ); $section->addText($text); printSeparator($section); @@ -57,16 +58,16 @@ foreach ($wrappingStyles as $wrappingStyle) { $section->addText('Absolute positioning: see top right corner of page'); $section->addImage( 'resources/_mars.jpg', - array( - 'width' => \PhpOffice\PhpWord\Shared\Converter::cmToPixel(3), - 'height' => \PhpOffice\PhpWord\Shared\Converter::cmToPixel(3), - 'positioning' => \PhpOffice\PhpWord\Style\Image::POSITION_ABSOLUTE, - 'posHorizontal' => \PhpOffice\PhpWord\Style\Image::POSITION_HORIZONTAL_RIGHT, + [ + 'width' => \PhpOffice\PhpWord\Shared\Converter::cmToPixel(3), + 'height' => \PhpOffice\PhpWord\Shared\Converter::cmToPixel(3), + 'positioning' => \PhpOffice\PhpWord\Style\Image::POSITION_ABSOLUTE, + 'posHorizontal' => \PhpOffice\PhpWord\Style\Image::POSITION_HORIZONTAL_RIGHT, 'posHorizontalRel' => \PhpOffice\PhpWord\Style\Image::POSITION_RELATIVE_TO_PAGE, - 'posVerticalRel' => \PhpOffice\PhpWord\Style\Image::POSITION_RELATIVE_TO_PAGE, - 'marginLeft' => \PhpOffice\PhpWord\Shared\Converter::cmToPixel(15.5), - 'marginTop' => \PhpOffice\PhpWord\Shared\Converter::cmToPixel(1.55), - ) + 'posVerticalRel' => \PhpOffice\PhpWord\Style\Image::POSITION_RELATIVE_TO_PAGE, + 'marginLeft' => \PhpOffice\PhpWord\Shared\Converter::cmToPixel(15.5), + 'marginTop' => \PhpOffice\PhpWord\Shared\Converter::cmToPixel(1.55), + ] ); //Relative positioning @@ -75,21 +76,21 @@ $section->addText('Relative positioning: Horizontal position center relative to $section->addText('Vertical position top relative to line'); $section->addImage( 'resources/_mars.jpg', - array( - 'width' => \PhpOffice\PhpWord\Shared\Converter::cmToPixel(3), - 'height' => \PhpOffice\PhpWord\Shared\Converter::cmToPixel(3), - 'positioning' => \PhpOffice\PhpWord\Style\Image::POSITION_RELATIVE, - 'posHorizontal' => \PhpOffice\PhpWord\Style\Image::POSITION_HORIZONTAL_CENTER, + [ + 'width' => \PhpOffice\PhpWord\Shared\Converter::cmToPixel(3), + 'height' => \PhpOffice\PhpWord\Shared\Converter::cmToPixel(3), + 'positioning' => \PhpOffice\PhpWord\Style\Image::POSITION_RELATIVE, + 'posHorizontal' => \PhpOffice\PhpWord\Style\Image::POSITION_HORIZONTAL_CENTER, 'posHorizontalRel' => \PhpOffice\PhpWord\Style\Image::POSITION_RELATIVE_TO_COLUMN, - 'posVertical' => \PhpOffice\PhpWord\Style\Image::POSITION_VERTICAL_TOP, - 'posVerticalRel' => \PhpOffice\PhpWord\Style\Image::POSITION_RELATIVE_TO_LINE, - ) + 'posVertical' => \PhpOffice\PhpWord\Style\Image::POSITION_VERTICAL_TOP, + 'posVerticalRel' => \PhpOffice\PhpWord\Style\Image::POSITION_RELATIVE_TO_LINE, + ] ); -function printSeparator(Section $section) +function printSeparator(Section $section): void { $section->addTextBreak(); - $lineStyle = array('weight' => 0.2, 'width' => 150, 'height' => 0, 'align' => 'center'); + $lineStyle = ['weight' => 0.2, 'width' => 150, 'height' => 0, 'align' => 'center']; $section->addLine($lineStyle); $section->addTextBreak(2); } diff --git a/samples/Sample_14_ListItem.php b/samples/Sample_14_ListItem.php index f40e9f6f..3b509f35 100644 --- a/samples/Sample_14_ListItem.php +++ b/samples/Sample_14_ListItem.php @@ -1,4 +1,5 @@ addFontStyle($fontStyleName, array('color' => 'FF0000')); +$phpWord->addFontStyle($fontStyleName, ['color' => 'FF0000']); $paragraphStyleName = 'P-Style'; -$phpWord->addParagraphStyle($paragraphStyleName, array('spaceAfter' => 95)); +$phpWord->addParagraphStyle($paragraphStyleName, ['spaceAfter' => 95]); $multilevelNumberingStyleName = 'multilevel'; $phpWord->addNumberingStyle( $multilevelNumberingStyleName, - array( - 'type' => 'multilevel', - 'levels' => array( - array('format' => 'decimal', 'text' => '%1.', 'left' => 360, 'hanging' => 360, 'tabPos' => 360), - array('format' => 'upperLetter', 'text' => '%2.', 'left' => 720, 'hanging' => 360, 'tabPos' => 720), - ), - ) + [ + 'type' => 'multilevel', + 'levels' => [ + ['format' => 'decimal', 'text' => '%1.', 'left' => 360, 'hanging' => 360, 'tabPos' => 360], + ['format' => 'upperLetter', 'text' => '%2.', 'left' => 720, 'hanging' => 360, 'tabPos' => 720], + ], + ] ); -$predefinedMultilevelStyle = array('listType' => \PhpOffice\PhpWord\Style\ListItem::TYPE_NUMBER_NESTED); +$predefinedMultilevelStyle = ['listType' => \PhpOffice\PhpWord\Style\ListItem::TYPE_NUMBER_NESTED]; // New section $section = $phpWord->addSection(); @@ -63,32 +64,32 @@ $section->addTextBreak(2); $section->addText('List with inline formatting.'); $listItemRun = $section->addListItemRun(); $listItemRun->addText('List item 1'); -$listItemRun->addText(' in bold', array('bold' => true)); +$listItemRun->addText(' in bold', ['bold' => true]); $listItemRun = $section->addListItemRun(1, $predefinedMultilevelStyle, $paragraphStyleName); $listItemRun->addText('List item 2'); -$listItemRun->addText(' in italic', array('italic' => true)); +$listItemRun->addText(' in italic', ['italic' => true]); $footnote = $listItemRun->addFootnote(); $footnote->addText('this is a footnote on a list item'); $listItemRun = $section->addListItemRun(); $listItemRun->addText('List item 3'); -$listItemRun->addText(' underlined', array('underline' => 'dash')); +$listItemRun->addText(' underlined', ['underline' => 'dash']); $section->addTextBreak(2); // Numbered heading $headingNumberingStyleName = 'headingNumbering'; $phpWord->addNumberingStyle( $headingNumberingStyleName, - array('type' => 'multilevel', - 'levels' => array( - array('pStyle' => 'Heading1', 'format' => 'decimal', 'text' => '%1'), - array('pStyle' => 'Heading2', 'format' => 'decimal', 'text' => '%1.%2'), - array('pStyle' => 'Heading3', 'format' => 'decimal', 'text' => '%1.%2.%3'), - ), - ) + ['type' => 'multilevel', + 'levels' => [ + ['pStyle' => 'Heading1', 'format' => 'decimal', 'text' => '%1'], + ['pStyle' => 'Heading2', 'format' => 'decimal', 'text' => '%1.%2'], + ['pStyle' => 'Heading3', 'format' => 'decimal', 'text' => '%1.%2.%3'], + ], + ] ); -$phpWord->addTitleStyle(1, array('size' => 16), array('numStyle' => $headingNumberingStyleName, 'numLevel' => 0)); -$phpWord->addTitleStyle(2, array('size' => 14), array('numStyle' => $headingNumberingStyleName, 'numLevel' => 1)); -$phpWord->addTitleStyle(3, array('size' => 12), array('numStyle' => $headingNumberingStyleName, 'numLevel' => 2)); +$phpWord->addTitleStyle(1, ['size' => 16], ['numStyle' => $headingNumberingStyleName, 'numLevel' => 0]); +$phpWord->addTitleStyle(2, ['size' => 14], ['numStyle' => $headingNumberingStyleName, 'numLevel' => 1]); +$phpWord->addTitleStyle(3, ['size' => 12], ['numStyle' => $headingNumberingStyleName, 'numLevel' => 2]); $section->addTitle('Heading 1', 1); $section->addTitle('Heading 2', 2); diff --git a/samples/Sample_15_Link.php b/samples/Sample_15_Link.php index 86c7973b..faef3059 100644 --- a/samples/Sample_15_Link.php +++ b/samples/Sample_15_Link.php @@ -1,4 +1,5 @@ addLinkStyle($linkFontStyleName, array('bold' => true, 'color' => '808000')); +$phpWord->addLinkStyle($linkFontStyleName, ['bold' => true, 'color' => '808000']); // New section $section = $phpWord->addSection(); @@ -16,7 +17,7 @@ $section = $phpWord->addSection(); $section->addLink( 'https://github.com/PHPOffice/PHPWord', 'PHPWord on GitHub', - array('color' => '0000FF', 'underline' => \PhpOffice\PhpWord\Style\Font::UNDERLINE_SINGLE) + ['color' => '0000FF', 'underline' => \PhpOffice\PhpWord\Style\Font::UNDERLINE_SINGLE] ); $section->addTextBreak(2); $section->addLink('http://www.bing.com', null, $linkFontStyleName); diff --git a/samples/Sample_16_Object.php b/samples/Sample_16_Object.php index c4db7f61..b68fb167 100644 --- a/samples/Sample_16_Object.php +++ b/samples/Sample_16_Object.php @@ -1,4 +1,5 @@ getSettings()->setUpdateFields(true); $section = $phpWord->addSection(); // Define styles -$fontStyle12 = array('spaceAfter' => 60, 'size' => 12); -$fontStyle10 = array('size' => 10); -$phpWord->addTitleStyle(null, array('size' => 22, 'bold' => true)); -$phpWord->addTitleStyle(1, array('size' => 20, 'color' => '333333', 'bold' => true)); -$phpWord->addTitleStyle(2, array('size' => 16, 'color' => '666666')); -$phpWord->addTitleStyle(3, array('size' => 14, 'italic' => true)); -$phpWord->addTitleStyle(4, array('size' => 12)); +$fontStyle12 = ['spaceAfter' => 60, 'size' => 12]; +$fontStyle10 = ['size' => 10]; +$phpWord->addTitleStyle(null, ['size' => 22, 'bold' => true]); +$phpWord->addTitleStyle(1, ['size' => 20, 'color' => '333333', 'bold' => true]); +$phpWord->addTitleStyle(2, ['size' => 16, 'color' => '666666']); +$phpWord->addTitleStyle(3, ['size' => 14, 'italic' => true]); +$phpWord->addTitleStyle(4, ['size' => 12]); // Add text elements $section->addTitle('Table of contents 1', 0); diff --git a/samples/Sample_18_Watermark.php b/samples/Sample_18_Watermark.php index dbab2b7f..aebb3690 100644 --- a/samples/Sample_18_Watermark.php +++ b/samples/Sample_18_Watermark.php @@ -1,4 +1,5 @@ addSection(); $header = $section->addHeader(); -$header->addWatermark('resources/_earth.jpg', array('marginTop' => 200, 'marginLeft' => 55)); +$header->addWatermark('resources/_earth.jpg', ['marginTop' => 200, 'marginLeft' => 55]); $section->addText('The header reference to the current section includes a watermark image.'); // Save file diff --git a/samples/Sample_19_TextBreak.php b/samples/Sample_19_TextBreak.php index 17e2b1cb..45c79bee 100644 --- a/samples/Sample_19_TextBreak.php +++ b/samples/Sample_19_TextBreak.php @@ -1,4 +1,5 @@ 24); +$fontStyle24 = ['size' => 24]; -$paragraphStyle24 = array('spacing' => 240, 'size' => 24); +$paragraphStyle24 = ['spacing' => 240, 'size' => 24]; $fontStyleName = 'fontStyle'; -$phpWord->addFontStyle($fontStyleName, array('size' => 9)); +$phpWord->addFontStyle($fontStyleName, ['size' => 9]); $paragraphStyleName = 'paragraphStyle'; -$phpWord->addParagraphStyle($paragraphStyleName, array('spacing' => 480)); +$phpWord->addParagraphStyle($paragraphStyleName, ['spacing' => 480]); // New section $section = $phpWord->addSection(); diff --git a/samples/Sample_20_BGColor.php b/samples/Sample_20_BGColor.php index 628ae890..915a8241 100644 --- a/samples/Sample_20_BGColor.php +++ b/samples/Sample_20_BGColor.php @@ -1,4 +1,5 @@ addSection(); $section->addText( 'This is some text highlighted using fgColor (limited to 15 colors)', - array('fgColor' => \PhpOffice\PhpWord\Style\Font::FGCOLOR_YELLOW) + ['fgColor' => \PhpOffice\PhpWord\Style\Font::FGCOLOR_YELLOW] ); -$section->addText('This one uses bgColor and is using hex value (0xfbbb10)', array('bgColor' => 'fbbb10')); -$section->addText('Compatible with font colors', array('color' => '0000ff', 'bgColor' => 'fbbb10')); +$section->addText('This one uses bgColor and is using hex value (0xfbbb10)', ['bgColor' => 'fbbb10']); +$section->addText('Compatible with font colors', ['color' => '0000ff', 'bgColor' => 'fbbb10']); // Save file echo write($phpWord, basename(__FILE__, '.php'), $writers); diff --git a/samples/Sample_21_TableRowRules.php b/samples/Sample_21_TableRowRules.php index ca33de3b..42fc2d92 100644 --- a/samples/Sample_21_TableRowRules.php +++ b/samples/Sample_21_TableRowRules.php @@ -1,4 +1,5 @@ addText( . 'the textbreak is still there:' ); -$table1 = $section->addTable(array('cellMargin' => 0, 'cellMarginRight' => 0, 'cellMarginBottom' => 0, 'cellMarginLeft' => 0)); +$table1 = $section->addTable(['cellMargin' => 0, 'cellMarginRight' => 0, 'cellMarginBottom' => 0, 'cellMarginLeft' => 0]); $table1->addRow(3750); -$cell1 = $table1->addCell(null, array('valign' => 'top', 'borderSize' => 30, 'borderColor' => 'ff0000')); -$cell1->addImage('./resources/_earth.jpg', array('width' => 250, 'height' => 250, 'alignment' => \PhpOffice\PhpWord\SimpleType\Jc::CENTER)); +$cell1 = $table1->addCell(null, ['valign' => 'top', 'borderSize' => 30, 'borderColor' => 'ff0000']); +$cell1->addImage('./resources/_earth.jpg', ['width' => 250, 'height' => 250, 'alignment' => \PhpOffice\PhpWord\SimpleType\Jc::CENTER]); $section->addTextBreak(); $section->addText("But if we set the rowStyle 'exactHeight' to true, the real row height is used, removing the textbreak:"); $table2 = $section->addTable( - array( - 'cellMargin' => 0, - 'cellMarginRight' => 0, + [ + 'cellMargin' => 0, + 'cellMarginRight' => 0, 'cellMarginBottom' => 0, - 'cellMarginLeft' => 0, - ) + 'cellMarginLeft' => 0, + ] ); -$table2->addRow(3750, array('exactHeight' => true)); -$cell2 = $table2->addCell(null, array('valign' => 'top', 'borderSize' => 30, 'borderColor' => '00ff00')); -$cell2->addImage('./resources/_earth.jpg', array('width' => 250, 'height' => 250, 'alignment' => \PhpOffice\PhpWord\SimpleType\Jc::CENTER)); +$table2->addRow(3750, ['exactHeight' => true]); +$cell2 = $table2->addCell(null, ['valign' => 'top', 'borderSize' => 30, 'borderColor' => '00ff00']); +$cell2->addImage('./resources/_earth.jpg', ['width' => 250, 'height' => 250, 'alignment' => \PhpOffice\PhpWord\SimpleType\Jc::CENTER]); $section->addTextBreak(); $section->addText('In this example, image is 250px height. Rows are calculated in twips, and 1px = 15twips.'); diff --git a/samples/Sample_22_CheckBox.php b/samples/Sample_22_CheckBox.php index 5a2ac3e2..33d4e39c 100644 --- a/samples/Sample_22_CheckBox.php +++ b/samples/Sample_22_CheckBox.php @@ -1,4 +1,5 @@ deleteBlock('DELETEME'); echo date('H:i:s'), ' Saving the result document...', EOL; $templateProcessor->saveAs('results/Sample_23_TemplateBlock.docx'); -echo getEndingNotes(array('Word2007' => 'docx'), 'Sample_23_TemplateBlock'); +echo getEndingNotes(['Word2007' => 'docx'], 'Sample_23_TemplateBlock'); if (!CLI) { include_once 'Sample_Footer.php'; } diff --git a/samples/Sample_24_ReadODText.php b/samples/Sample_24_ReadODText.php index 42df23ae..73c11020 100644 --- a/samples/Sample_24_ReadODText.php +++ b/samples/Sample_24_ReadODText.php @@ -1,4 +1,5 @@ addSection(); // In section $textbox = $section->addTextBox( - array( - 'alignment' => \PhpOffice\PhpWord\SimpleType\Jc::CENTER, - 'width' => 400, - 'height' => 150, - 'borderSize' => 1, + [ + 'alignment' => \PhpOffice\PhpWord\SimpleType\Jc::CENTER, + 'width' => 400, + 'height' => 150, + 'borderSize' => 1, 'borderColor' => '#FF0000', - ) + ] ); $textbox->addText('Text box content in section.'); $textbox->addText('Another line.'); @@ -26,19 +27,19 @@ $cell->addText('Table inside textbox'); // Inside table $section->addTextBreak(2); $cell = $section->addTable()->addRow()->addCell(300); -$textbox = $cell->addTextBox(array('borderSize' => 1, 'borderColor' => '#0000FF', 'innerMargin' => 100)); +$textbox = $cell->addTextBox(['borderSize' => 1, 'borderColor' => '#0000FF', 'innerMargin' => 100]); $textbox->addText('Textbox inside table'); // Inside header with textrun $header = $section->addHeader(); -$textbox = $header->addTextBox(array('width' => 600, 'borderSize' => 1, 'borderColor' => '#00FF00')); +$textbox = $header->addTextBox(['width' => 600, 'borderSize' => 1, 'borderColor' => '#00FF00']); $textrun = $textbox->addTextRun(); $textrun->addText('TextBox in header. TextBox can contain a TextRun '); -$textrun->addText('with bold text', array('bold' => true)); +$textrun->addText('with bold text', ['bold' => true]); $textrun->addText(', '); $textrun->addLink('https://github.com/PHPOffice/PHPWord', 'PHPWord on GitHub'); $textrun->addText(', and image '); -$textrun->addImage('resources/_earth.jpg', array('width' => 18, 'height' => 18)); +$textrun->addImage('resources/_earth.jpg', ['width' => 18, 'height' => 18]); $textrun->addText('.'); // Save file diff --git a/samples/Sample_26_Html.php b/samples/Sample_26_Html.php index 6bd926fe..84468faa 100644 --- a/samples/Sample_26_Html.php +++ b/samples/Sample_26_Html.php @@ -1,10 +1,11 @@ addParagraphStyle('Heading2', array('alignment' => 'center')); +$phpWord->addParagraphStyle('Heading2', ['alignment' => 'center']); $section = $phpWord->addSection(); $html = '

Adding element via HTML

'; diff --git a/samples/Sample_27_Field.php b/samples/Sample_27_Field.php index 4e7a5b22..d2509461 100644 --- a/samples/Sample_27_Field.php +++ b/samples/Sample_27_Field.php @@ -1,4 +1,5 @@ 14)); +PhpOffice\PhpWord\Style::addTitleStyle(1, ['size' => 14]); // New section $section = $phpWord->addSection(); @@ -15,53 +16,53 @@ $section->addTitle('This page demos fields'); // Add Field elements // See Element/Field.php for all options $section->addText('Date field:'); -$section->addField('DATE', array('dateformat' => 'dddd d MMMM yyyy H:mm:ss'), array('PreserveFormat')); +$section->addField('DATE', ['dateformat' => 'dddd d MMMM yyyy H:mm:ss'], ['PreserveFormat']); $section->addText('Style Ref field:'); -$section->addField('STYLEREF', array('StyleIdentifier' => 'Heading 1')); +$section->addField('STYLEREF', ['StyleIdentifier' => 'Heading 1']); $section->addText('Page field:'); -$section->addField('PAGE', array('format' => 'Arabic')); +$section->addField('PAGE', ['format' => 'Arabic']); $section->addText('Number of pages field:'); -$section->addField('NUMPAGES', array('numformat' => '0,00', 'format' => 'Arabic'), array('PreserveFormat')); +$section->addField('NUMPAGES', ['numformat' => '0,00', 'format' => 'Arabic'], ['PreserveFormat']); $section->addTextBreak(); $textrun = $section->addTextRun(); $textrun->addText('An index field is '); -$textrun->addField('XE', array(), array('Italic'), 'My first index'); +$textrun->addField('XE', [], ['Italic'], 'My first index'); $textrun->addText('here:'); $indexEntryText = new TextRun(); $indexEntryText->addText('My '); -$indexEntryText->addText('bold index', array('bold' => true)); +$indexEntryText->addText('bold index', ['bold' => true]); $indexEntryText->addText(' entry'); $textrun = $section->addTextRun(); $textrun->addText('A complex index field is '); -$textrun->addField('XE', array(), array('Bold'), $indexEntryText); +$textrun->addField('XE', [], ['Bold'], $indexEntryText); $textrun->addText('here:'); $section->addText('The actual index:'); -$section->addField('INDEX', array(), array('\\e " "'), 'right click to update the index'); +$section->addField('INDEX', [], ['\\e " "'], 'right click to update the index'); -$textrun = $section->addTextRun(array('alignment' => \PhpOffice\PhpWord\SimpleType\Jc::CENTER)); +$textrun = $section->addTextRun(['alignment' => \PhpOffice\PhpWord\SimpleType\Jc::CENTER]); $textrun->addText('This is the date of lunar calendar '); -$textrun->addField('DATE', array('dateformat' => 'd-M-yyyy H:mm:ss'), array('PreserveFormat', 'LunarCalendar')); +$textrun->addField('DATE', ['dateformat' => 'd-M-yyyy H:mm:ss'], ['PreserveFormat', 'LunarCalendar']); $textrun->addText(' written in a textrun.'); $section->addTextBreak(); $macroText = new TextRun(); -$macroText->addText('Double click', array('bold' => true)); +$macroText->addText('Double click', ['bold' => true]); $macroText->addText(' to '); -$macroText->addText('zoom to 100%', array('italic' => true)); +$macroText->addText('zoom to 100%', ['italic' => true]); $section->addText('A macro button with styled text:'); -$section->addField('MACROBUTTON', array('macroname' => 'Zoom100'), array(), $macroText); +$section->addField('MACROBUTTON', ['macroname' => 'Zoom100'], [], $macroText); $section->addTextBreak(); $section->addText('A macro button with simple text:'); -$section->addField('MACROBUTTON', array('macroname' => 'Zoom100'), array(), 'double click to zoom'); +$section->addField('MACROBUTTON', ['macroname' => 'Zoom100'], [], 'double click to zoom'); // Save file echo write($phpWord, basename(__FILE__, '.php'), $writers); diff --git a/samples/Sample_28_ReadRTF.php b/samples/Sample_28_ReadRTF.php index 76ac3d48..43b859ac 100644 --- a/samples/Sample_28_ReadRTF.php +++ b/samples/Sample_28_ReadRTF.php @@ -1,4 +1,5 @@ addSection(); // See Element/Line.php for all options $section->addText('Horizontal Line (Inline style):'); $section->addLine( - array( - 'width' => \PhpOffice\PhpWord\Shared\Converter::cmToPixel(4), - 'height' => \PhpOffice\PhpWord\Shared\Converter::cmToPixel(0), + [ + 'width' => \PhpOffice\PhpWord\Shared\Converter::cmToPixel(4), + 'height' => \PhpOffice\PhpWord\Shared\Converter::cmToPixel(0), 'positioning' => 'absolute', - ) + ] ); $section->addText('Vertical Line (Inline style):'); $section->addLine( - array( - 'width' => \PhpOffice\PhpWord\Shared\Converter::cmToPixel(0), - 'height' => \PhpOffice\PhpWord\Shared\Converter::cmToPixel(1), + [ + 'width' => \PhpOffice\PhpWord\Shared\Converter::cmToPixel(0), + 'height' => \PhpOffice\PhpWord\Shared\Converter::cmToPixel(1), 'positioning' => 'absolute', - ) + ] ); // Two text break $section->addTextBreak(1); $section->addText('Positioned Line (red):'); $section->addLine( - array( - 'width' => \PhpOffice\PhpWord\Shared\Converter::cmToPixel(4), - 'height' => \PhpOffice\PhpWord\Shared\Converter::cmToPixel(1), - 'positioning' => 'absolute', + [ + 'width' => \PhpOffice\PhpWord\Shared\Converter::cmToPixel(4), + 'height' => \PhpOffice\PhpWord\Shared\Converter::cmToPixel(1), + 'positioning' => 'absolute', 'posHorizontalRel' => 'page', - 'posVerticalRel' => 'page', - 'marginLeft' => \PhpOffice\PhpWord\Shared\Converter::cmToPixel(10), - 'marginTop' => \PhpOffice\PhpWord\Shared\Converter::cmToPixel(8), - 'wrappingStyle' => \PhpOffice\PhpWord\Style\Image::WRAPPING_STYLE_SQUARE, - 'color' => 'red', - ) + 'posVerticalRel' => 'page', + 'marginLeft' => \PhpOffice\PhpWord\Shared\Converter::cmToPixel(10), + 'marginTop' => \PhpOffice\PhpWord\Shared\Converter::cmToPixel(8), + 'wrappingStyle' => \PhpOffice\PhpWord\Style\Image::WRAPPING_STYLE_SQUARE, + 'color' => 'red', + ] ); $section->addText('Horizontal Formatted Line'); $section->addLine( - array( - 'width' => \PhpOffice\PhpWord\Shared\Converter::cmToPixel(15), - 'height' => \PhpOffice\PhpWord\Shared\Converter::cmToPixel(0), + [ + 'width' => \PhpOffice\PhpWord\Shared\Converter::cmToPixel(15), + 'height' => \PhpOffice\PhpWord\Shared\Converter::cmToPixel(0), 'positioning' => 'absolute', - 'beginArrow' => \PhpOffice\PhpWord\Style\Line::ARROW_STYLE_BLOCK, - 'endArrow' => \PhpOffice\PhpWord\Style\Line::ARROW_STYLE_OVAL, - 'dash' => \PhpOffice\PhpWord\Style\Line::DASH_STYLE_LONG_DASH_DOT_DOT, - 'weight' => 10, - ) + 'beginArrow' => \PhpOffice\PhpWord\Style\Line::ARROW_STYLE_BLOCK, + 'endArrow' => \PhpOffice\PhpWord\Style\Line::ARROW_STYLE_OVAL, + 'dash' => \PhpOffice\PhpWord\Style\Line::DASH_STYLE_LONG_DASH_DOT_DOT, + 'weight' => 10, + ] ); // Save file diff --git a/samples/Sample_30_ReadHTML.php b/samples/Sample_30_ReadHTML.php index 029f8c8c..8698fe63 100644 --- a/samples/Sample_30_ReadHTML.php +++ b/samples/Sample_30_ReadHTML.php @@ -1,4 +1,5 @@ addSection(); // Define styles -$phpWord->addTitleStyle(1, array('size' => 14, 'bold' => true)); +$phpWord->addTitleStyle(1, ['size' => 14, 'bold' => true]); // Arc $section->addTitle('Arc', 1); $section->addShape( 'arc', - array( - 'points' => '-90 20', - 'frame' => array('width' => 120, 'height' => 120), - 'outline' => array('color' => '#333333', 'weight' => 2, 'startArrow' => 'oval', 'endArrow' => 'open'), - ) + [ + 'points' => '-90 20', + 'frame' => ['width' => 120, 'height' => 120], + 'outline' => ['color' => '#333333', 'weight' => 2, 'startArrow' => 'oval', 'endArrow' => 'open'], + ] ); // Curve $section->addTitle('Curve', 1); $section->addShape( 'curve', - array( - 'points' => '1,100 200,1 1,50 200,50', + [ + 'points' => '1,100 200,1 1,50 200,50', 'connector' => 'elbow', - 'outline' => array( - 'color' => '#66cc00', - 'weight' => 2, - 'dash' => 'dash', + 'outline' => [ + 'color' => '#66cc00', + 'weight' => 2, + 'dash' => 'dash', 'startArrow' => 'diamond', - 'endArrow' => 'block', - ), - ) + 'endArrow' => 'block', + ], + ] ); // Line $section->addTitle('Line', 1); $section->addShape( 'line', - array( - 'points' => '1,1 150,30', - 'outline' => array( - 'color' => '#cc00ff', - 'line' => 'thickThin', - 'weight' => 3, + [ + 'points' => '1,1 150,30', + 'outline' => [ + 'color' => '#cc00ff', + 'line' => 'thickThin', + 'weight' => 3, 'startArrow' => 'oval', - 'endArrow' => 'classic', - ), - ) + 'endArrow' => 'classic', + ], + ] ); // Polyline $section->addTitle('Polyline', 1); $section->addShape( 'polyline', - array( - 'points' => '1,30 20,10 55,20 75,10 100,40 115,50, 120,15 200,50', - 'outline' => array('color' => '#cc6666', 'weight' => 2, 'startArrow' => 'none', 'endArrow' => 'classic'), - ) + [ + 'points' => '1,30 20,10 55,20 75,10 100,40 115,50, 120,15 200,50', + 'outline' => ['color' => '#cc6666', 'weight' => 2, 'startArrow' => 'none', 'endArrow' => 'classic'], + ] ); // Rectangle $section->addTitle('Rectangle', 1); $section->addShape( 'rect', - array( + [ 'roundness' => 0.2, - 'frame' => array('width' => 100, 'height' => 100, 'left' => 1, 'top' => 1), - 'fill' => array('color' => '#FFCC33'), - 'outline' => array('color' => '#990000', 'weight' => 1), - 'shadow' => array(), - ) + 'frame' => ['width' => 100, 'height' => 100, 'left' => 1, 'top' => 1], + 'fill' => ['color' => '#FFCC33'], + 'outline' => ['color' => '#990000', 'weight' => 1], + 'shadow' => [], + ] ); // Oval $section->addTitle('Oval', 1); $section->addShape( 'oval', - array( - 'frame' => array('width' => 100, 'height' => 70, 'left' => 1, 'top' => 1), - 'fill' => array('color' => '#33CC99'), - 'outline' => array('color' => '#333333', 'weight' => 2), - 'extrusion' => array(), - ) + [ + 'frame' => ['width' => 100, 'height' => 70, 'left' => 1, 'top' => 1], + 'fill' => ['color' => '#33CC99'], + 'outline' => ['color' => '#333333', 'weight' => 2], + 'extrusion' => [], + ] ); // Save file diff --git a/samples/Sample_32_Chart.php b/samples/Sample_32_Chart.php index bfb9ffe8..7e99984e 100644 --- a/samples/Sample_32_Chart.php +++ b/samples/Sample_32_Chart.php @@ -1,4 +1,5 @@ addTitleStyle(1, array('size' => 14, 'bold' => true), array('keepNext' => true, 'spaceBefore' => 240)); -$phpWord->addTitleStyle(2, array('size' => 14, 'bold' => true), array('keepNext' => true, 'spaceBefore' => 240)); +$phpWord->addTitleStyle(1, ['size' => 14, 'bold' => true], ['keepNext' => true, 'spaceBefore' => 240]); +$phpWord->addTitleStyle(2, ['size' => 14, 'bold' => true], ['keepNext' => true, 'spaceBefore' => 240]); // 2D charts $section = $phpWord->addSection(); $section->addTitle('2D charts', 1); -$section = $phpWord->addSection(array('colsNum' => 2, 'breakType' => 'continuous')); +$section = $phpWord->addSection(['colsNum' => 2, 'breakType' => 'continuous']); -$chartTypes = array('pie', 'doughnut', 'bar', 'column', 'line', 'area', 'scatter', 'radar', 'stacked_bar', 'percent_stacked_bar', 'stacked_column', 'percent_stacked_column'); -$twoSeries = array('bar', 'column', 'line', 'area', 'scatter', 'radar', 'stacked_bar', 'percent_stacked_bar', 'stacked_column', 'percent_stacked_column'); -$threeSeries = array('bar', 'line'); -$categories = array('A', 'B', 'C', 'D', 'E'); -$series1 = array(1, 3, 2, 5, 4); -$series2 = array(3, 1, 7, 2, 6); -$series3 = array(8, 3, 2, 5, 4); +$chartTypes = ['pie', 'doughnut', 'bar', 'column', 'line', 'area', 'scatter', 'radar', 'stacked_bar', 'percent_stacked_bar', 'stacked_column', 'percent_stacked_column']; +$twoSeries = ['bar', 'column', 'line', 'area', 'scatter', 'radar', 'stacked_bar', 'percent_stacked_bar', 'stacked_column', 'percent_stacked_column']; +$threeSeries = ['bar', 'line']; +$categories = ['A', 'B', 'C', 'D', 'E']; +$series1 = [1, 3, 2, 5, 4]; +$series2 = [3, 1, 7, 2, 6]; +$series3 = [8, 3, 2, 5, 4]; $showGridLines = false; $showAxisLabels = false; $showLegend = true; @@ -48,20 +49,20 @@ foreach ($chartTypes as $chartType) { } // 3D charts -$section = $phpWord->addSection(array('breakType' => 'continuous')); +$section = $phpWord->addSection(['breakType' => 'continuous']); $section->addTitle('3D charts', 1); -$section = $phpWord->addSection(array('colsNum' => 2, 'breakType' => 'continuous')); +$section = $phpWord->addSection(['colsNum' => 2, 'breakType' => 'continuous']); -$chartTypes = array('pie', 'bar', 'column', 'line', 'area'); -$multiSeries = array('bar', 'column', 'line', 'area'); -$style = array( - 'width' => Converter::cmToEmu(5), - 'height' => Converter::cmToEmu(4), - '3d' => true, +$chartTypes = ['pie', 'bar', 'column', 'line', 'area']; +$multiSeries = ['bar', 'column', 'line', 'area']; +$style = [ + 'width' => Converter::cmToEmu(5), + 'height' => Converter::cmToEmu(4), + '3d' => true, 'showAxisLabels' => $showAxisLabels, - 'showGridX' => $showGridLines, - 'showGridY' => $showGridLines, -); + 'showGridX' => $showGridLines, + 'showGridY' => $showGridLines, +]; foreach ($chartTypes as $chartType) { $section->addTitle(ucfirst($chartType), 2); $chart = $section->addChart($chartType, $categories, $series1, $style); diff --git a/samples/Sample_33_FormField.php b/samples/Sample_33_FormField.php index a855d42a..61abc415 100644 --- a/samples/Sample_33_FormField.php +++ b/samples/Sample_33_FormField.php @@ -1,4 +1,5 @@ addFormField('textinput')->setName('MyTextBox'); $textrun->addText(', checkbox '); $textrun->addFormField('checkbox')->setDefault(true); $textrun->addText(', or dropdown '); -$textrun->addFormField('dropdown')->setEntries(array('Choice 1', 'Choice 2', 'Choice 3')); +$textrun->addFormField('dropdown')->setEntries(['Choice 1', 'Choice 2', 'Choice 3']); $textrun->addText('. You have to set document protection to "forms" to enable dropdown.'); $section->addText('They can also be added as a stand alone paragraph.'); diff --git a/samples/Sample_34_SDT.php b/samples/Sample_34_SDT.php index f9077a1a..c1722b5b 100644 --- a/samples/Sample_34_SDT.php +++ b/samples/Sample_34_SDT.php @@ -1,4 +1,5 @@ addSection(); $textrun = $section->addTextRun(); $textrun->addText('Combobox: '); -$textrun->addSDT('comboBox')->setListItems(array('1' => 'Choice 1', '2' => 'Choice 2')); +$textrun->addSDT('comboBox')->setListItems(['1' => 'Choice 1', '2' => 'Choice 2']); $textrun = $section->addTextRun(); $textrun->addText('Date: '); @@ -24,7 +25,7 @@ $textrun->addSDT('date')->setValue('30.03.2017'); $textrun = $section->addTextRun(); $textrun->addText('Drop down list: '); -$textrun->addSDT('dropDownList')->setListItems(array('1' => 'Choice 1', '2' => 'Choice 2'))->setValue('Choice 1'); +$textrun->addSDT('dropDownList')->setListItems(['1' => 'Choice 1', '2' => 'Choice 2'])->setValue('Choice 1'); // Save file echo write($phpWord, basename(__FILE__, '.php'), $writers); diff --git a/samples/Sample_35_InternalLink.php b/samples/Sample_35_InternalLink.php index 5ab7d9b4..e59c3530 100644 --- a/samples/Sample_35_InternalLink.php +++ b/samples/Sample_35_InternalLink.php @@ -1,4 +1,5 @@ addSection(); $textrun = $section->addTextRun(); $textrun->addText('This is a Left to Right paragraph.'); -$textrun = $section->addTextRun(array('alignment' => \PhpOffice\PhpWord\SimpleType\Jc::END)); -$textrun->addText('سلام این یک پاراگراف راست به چپ است', array('rtl' => true)); +$textrun = $section->addTextRun(['alignment' => \PhpOffice\PhpWord\SimpleType\Jc::END]); +$textrun->addText('سلام این یک پاراگراف راست به چپ است', ['rtl' => true]); $section->addText('Table visually presented as RTL'); -$style = array('rtl' => true, 'size' => 12); -$tableStyle = array('borderSize' => 6, 'borderColor' => '000000', 'width' => 5000, 'unit' => \PhpOffice\PhpWord\SimpleType\TblWidth::PERCENT, 'bidiVisual' => true); +$style = ['rtl' => true, 'size' => 12]; +$tableStyle = ['borderSize' => 6, 'borderColor' => '000000', 'width' => 5000, 'unit' => \PhpOffice\PhpWord\SimpleType\TblWidth::PERCENT, 'bidiVisual' => true]; $table = $section->addTable($tableStyle); -$cellHCentered = array('alignment' => \PhpOffice\PhpWord\SimpleType\Jc::CENTER); -$cellHEnd = array('alignment' => \PhpOffice\PhpWord\SimpleType\Jc::END); -$cellVCentered = array('valign' => \PhpOffice\PhpWord\Style\Cell::VALIGN_CENTER); +$cellHCentered = ['alignment' => \PhpOffice\PhpWord\SimpleType\Jc::CENTER]; +$cellHEnd = ['alignment' => \PhpOffice\PhpWord\SimpleType\Jc::END]; +$cellVCentered = ['valign' => \PhpOffice\PhpWord\Style\Cell::VALIGN_CENTER]; //Vidually bidirectinal table $table->addRow(); diff --git a/samples/Sample_37_Comments.php b/samples/Sample_37_Comments.php index 268739bc..79647478 100644 --- a/samples/Sample_37_Comments.php +++ b/samples/Sample_37_Comments.php @@ -1,4 +1,5 @@ addText('Test', array('bold' => true)); +$comment->addText('Test', ['bold' => true]); $phpWord->addComment($comment); $section = $phpWord->addSection(); @@ -27,9 +28,9 @@ $phpWord->addComment($commentWithStartAndEnd); $textrunWithEnd = $section->addTextRun(); $textrunWithEnd->addText('This '); -$textToStartOn = $textrunWithEnd->addText('is', array('bold' => true)); +$textToStartOn = $textrunWithEnd->addText('is', ['bold' => true]); $textToStartOn->setCommentRangeStart($commentWithStartAndEnd); -$textrunWithEnd->addText(' another', array('italic' => true)); +$textrunWithEnd->addText(' another', ['italic' => true]); $textToEndOn = $textrunWithEnd->addText(' test'); $textToEndOn->setCommentRangeEnd($commentWithStartAndEnd); @@ -39,7 +40,7 @@ $section->addTextBreak(2); $commentOnImage = new \PhpOffice\PhpWord\Element\Comment('Mr Smart', new \DateTime()); $imageComment = $commentOnImage->addTextRun(); $imageComment->addText('Hey, Mars does look '); -$imageComment->addText('red', array('color' => 'FF0000')); +$imageComment->addText('red', ['color' => 'FF0000']); $phpWord->addComment($commentOnImage); $image = $section->addImage('resources/_mars.jpg'); $image->setCommentRangeStart($commentOnImage); @@ -50,7 +51,7 @@ $section->addTextBreak(2); $anotherText = $section->addText('another text'); $comment1 = new \PhpOffice\PhpWord\Element\Comment('Authors name', new \DateTime(), 'my_initials'); -$comment1->addText('Test', array('bold' => true)); +$comment1->addText('Test', ['bold' => true]); $comment1->setStartElement($anotherText); $comment1->setEndElement($anotherText); $phpWord->addComment($comment1); diff --git a/samples/Sample_38_Protection.php b/samples/Sample_38_Protection.php index ee2b460b..9f615380 100644 --- a/samples/Sample_38_Protection.php +++ b/samples/Sample_38_Protection.php @@ -1,4 +1,5 @@ addTextRun(); $text = $textRun->addText('Hello World! Time to '); -$text = $textRun->addText('wake ', array('bold' => true)); +$text = $textRun->addText('wake ', ['bold' => true]); $text->setChangeInfo(TrackChange::INSERTED, 'Fred', time() - 1800); $text = $textRun->addText('up'); diff --git a/samples/Sample_40_TemplateSetComplexValue.php b/samples/Sample_40_TemplateSetComplexValue.php index 094823f7..38ecb3f7 100644 --- a/samples/Sample_40_TemplateSetComplexValue.php +++ b/samples/Sample_40_TemplateSetComplexValue.php @@ -1,4 +1,5 @@ addText('This title has been set ', array('bold' => true, 'italic' => true, 'color' => 'blue')); -$title->addText('dynamically', array('bold' => true, 'italic' => true, 'color' => 'red', 'underline' => 'single')); +$title->addText('This title has been set ', ['bold' => true, 'italic' => true, 'color' => 'blue']); +$title->addText('dynamically', ['bold' => true, 'italic' => true, 'color' => 'red', 'underline' => 'single']); $templateProcessor->setComplexBlock('title', $title); $inline = new TextRun(); -$inline->addText('by a red italic text', array('italic' => true, 'color' => 'red')); +$inline->addText('by a red italic text', ['italic' => true, 'color' => 'red']); $templateProcessor->setComplexValue('inline', $inline); -$table = new Table(array('borderSize' => 12, 'borderColor' => 'green', 'width' => 6000, 'unit' => TblWidth::TWIP)); +$table = new Table(['borderSize' => 12, 'borderColor' => 'green', 'width' => 6000, 'unit' => TblWidth::TWIP]); $table->addRow(); $table->addCell(150)->addText('Cell A1'); $table->addCell(150)->addText('Cell A2'); @@ -30,7 +31,7 @@ $table->addCell(150)->addText('Cell B2'); $table->addCell(150)->addText('Cell B3'); $templateProcessor->setComplexBlock('table', $table); -$field = new Field('DATE', array('dateformat' => 'dddd d MMMM yyyy H:mm:ss'), array('PreserveFormat')); +$field = new Field('DATE', ['dateformat' => 'dddd d MMMM yyyy H:mm:ss'], ['PreserveFormat']); $templateProcessor->setComplexValue('field', $field); // $link = new Link('https://github.com/PHPOffice/PHPWord'); @@ -39,7 +40,7 @@ $templateProcessor->setComplexValue('field', $field); echo date('H:i:s'), ' Saving the result document...', EOL; $templateProcessor->saveAs('results/Sample_40_TemplateSetComplexValue.docx'); -echo getEndingNotes(array('Word2007' => 'docx'), 'results/Sample_40_TemplateSetComplexValue.docx'); +echo getEndingNotes(['Word2007' => 'docx'], 'results/Sample_40_TemplateSetComplexValue.docx'); if (!CLI) { include_once 'Sample_Footer.php'; } diff --git a/samples/Sample_41_TemplateSetChart.php b/samples/Sample_41_TemplateSetChart.php index 2b017d7f..88eb2ccb 100644 --- a/samples/Sample_41_TemplateSetChart.php +++ b/samples/Sample_41_TemplateSetChart.php @@ -1,4 +1,5 @@ setHeight(Converter::inchToEmu(3)); $templateProcessor->setChart("chart{$i}", $chart); - $i++; + ++$i; } echo date('H:i:s'), ' Saving the result document...', EOL; $templateProcessor->saveAs('results/Sample_41_TemplateSetChart.docx'); -echo getEndingNotes(array('Word2007' => 'docx'), 'results/Sample_41_TemplateSetChart.docx'); +echo getEndingNotes(['Word2007' => 'docx'], 'results/Sample_41_TemplateSetChart.docx'); if (!CLI) { include_once 'Sample_Footer.php'; } diff --git a/samples/Sample_Header.php b/samples/Sample_Header.php index f0fc6266..53674b79 100644 --- a/samples/Sample_Header.php +++ b/samples/Sample_Header.php @@ -19,7 +19,7 @@ if (file_exists($dompdfPath)) { } // Set writers -$writers = array('Word2007' => 'docx', 'ODText' => 'odt', 'RTF' => 'rtf', 'HTML' => 'html', 'PDF' => 'pdf'); +$writers = ['Word2007' => 'docx', 'ODText' => 'odt', 'RTF' => 'rtf', 'HTML' => 'html', 'PDF' => 'pdf']; // Set PDF renderer if (null === Settings::getPdfRendererPath()) { @@ -43,7 +43,7 @@ $pageHeading = IS_INDEX ? '' : "

{$pageHeading}

"; // Populate samples $files = ''; if ($handle = opendir('.')) { - $sampleFiles = array(); + $sampleFiles = []; while (false !== ($sampleFile = readdir($handle))) { $sampleFiles[] = $sampleFile; } @@ -59,7 +59,7 @@ if ($handle = opendir('.')) { } /** - * Write documents + * Write documents. * * @param \PhpOffice\PhpWord\PhpWord $phpWord * @param string $filename @@ -89,10 +89,11 @@ function write($phpWord, $filename, $writers) } /** - * Get ending notes + * Get ending notes. * * @param array $writers * @param mixed $filename + * * @return string */ function getEndingNotes($writers, $filename) @@ -114,7 +115,7 @@ function getEndingNotes($writers, $filename) $result .= '

 

'; $result .= '

Results: '; foreach ($types as $type) { - if (!is_null($type)) { + if (null !== $type) { $resultFile = 'results/' . SCRIPT_FILENAME . '.' . $type; if (file_exists($resultFile)) { $result .= "{$type} "; diff --git a/samples/index.php b/samples/index.php index d539cd62..c47deebe 100644 --- a/samples/index.php +++ b/samples/index.php @@ -3,15 +3,15 @@ include_once 'Sample_Header.php'; use PhpOffice\PhpWord\Settings; -$requirements = array( - 'php' => array('PHP 7.4', version_compare(PHP_VERSION, '7.4', '>=')), - 'xml' => array('PHP extension XML', extension_loaded('xml')), - 'temp' => array('Temp folder "' . Settings::getTempDir() . '" is writable', is_writable(Settings::getTempDir())), - 'zip' => array('PHP extension ZipArchive (optional)', extension_loaded('zip')), - 'gd' => array('PHP extension GD (optional)', extension_loaded('gd')), - 'xmlw' => array('PHP extension XMLWriter (optional)', extension_loaded('xmlwriter')), - 'xsl' => array('PHP extension XSL (optional)', extension_loaded('xsl')), -); +$requirements = [ + 'php' => ['PHP 7.4', version_compare(PHP_VERSION, '7.4', '>=')], + 'xml' => ['PHP extension XML', extension_loaded('xml')], + 'temp' => ['Temp folder "' . Settings::getTempDir() . '" is writable', is_writable(Settings::getTempDir())], + 'zip' => ['PHP extension ZipArchive (optional)', extension_loaded('zip')], + 'gd' => ['PHP extension GD (optional)', extension_loaded('gd')], + 'xmlw' => ['PHP extension XMLWriter (optional)', extension_loaded('xmlwriter')], + 'xsl' => ['PHP extension XSL (optional)', extension_loaded('xsl')], +]; if (!CLI) { ?>

@@ -28,7 +28,7 @@ if (!CLI) { echo '

Requirement check:

'; echo '