diff --git a/CHANGELOG.md b/CHANGELOG.md index 650ca5dfc6..6c554bb78f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,10 +16,13 @@ Place announcement text here. ### Changed - Improved error message for the case when `autoload.php` is not found. - @RomanSyroeshko #371 - Renamed the `align` option of `NumberingLevel`, `Frame`, `Table`, and `Paragraph` styles into `alignment`. - @RomanSyroeshko +- Bootstrap script for the manual installation scenario (now include `bootstrap.php` instead of `src/PhpWord/Autoloader.php`). - @RomanSyroeshko ### Deprecated - `getAlign` and `setAlign` methods of `NumberingLevel`, `Frame`, `Table`, and `Paragraph` styles. Use the correspondent `getAlignment` and `setAlignment` methods instead. +- `left`, `right`, and `justify` alignment options for paragraphs (now are mapped to `Jc::START`, `Jc::END`, and `Jc::BOTH`). +- `left`, `right`, and `justify` alignment options for tables (now are mapped to `Jc::START`, `Jc::END`, and `Jc::CENTER`). ### Removed - `PhpOffice\PhpWord\Style\Alignment`. Style properties, which previously stored instances of this class, now deal with strings. diff --git a/bootstrap.php b/bootstrap.php new file mode 100644 index 0000000000..8f427a946d --- /dev/null +++ b/bootstrap.php @@ -0,0 +1,28 @@ +=5.3.3", - "ext-xml": "*" + "ext-xml": "*", + "zendframework/zend-validator": "2.5.*" }, "require-dev": { "phpunit/phpunit": "3.7.*", @@ -44,14 +45,15 @@ "phploc/phploc": "2.*", "dompdf/dompdf":"0.6.*", "tecnick.com/tcpdf": "6.*", - "mpdf/mpdf": "5.*" + "mpdf/mpdf": "5.*", + "zendframework/zend-validator": "2.5.*" }, "suggest": { - "ext-zip": "Used to write DOCX and ODT", - "ext-gd2": "Used to add images", - "ext-xmlwriter": "Used to write DOCX and ODT", - "ext-xsl": "Used to apply XSL style sheet to main document part of OOXML template", - "dompdf/dompdf": "Used to write PDF" + "ext-zip": "Allows writing DOCX and ODT", + "ext-gd2": "Allows adding images", + "ext-xmlwriter": "Allows writing DOCX and ODT", + "ext-xsl": "Allows applying XSL style sheet to main document part of OOXML template", + "dompdf/dompdf": "Allows writing PDF" }, "autoload": { "psr-4": { diff --git a/docs/installing.rst b/docs/installing.rst index d05464bf07..2ba8509a15 100644 --- a/docs/installing.rst +++ b/docs/installing.rst @@ -22,14 +22,12 @@ Installation ------------ There are two ways to install PHPWord, i.e. via -`Composer `__ or manually by downloading the -library. +`Composer `__ or manually by downloading the library. Using Composer ~~~~~~~~~~~~~~ -To install via Composer, add the following lines to your -``composer.json``: +To install via Composer, add the following lines to your ``composer.json``: .. code-block:: json @@ -51,8 +49,8 @@ Notice: all contributions must be done against the developer branch. } -Manual install -~~~~~~~~~~~~~~ +Manual installation +~~~~~~~~~~~~~~~~~~~ To install manually, you change to the web-server directory of your file system. Then you have 2 possibilities. @@ -63,12 +61,11 @@ To install manually, you change to the web-server directory of your file system. git clone https://github.com/PHPOffice/PHPWord.git -To use the library, include ``src/PhpWord/Autoloader.php`` in your PHP script and -invoke ``Autoloader::register``. +To use the library, include ``bootstrap.php`` in your PHP script and invoke ``Autoloader::register``. .. code-block:: php - require_once '/path/to/src/PhpWord/Autoloader.php'; + require_once "${path_to_the_cloned_repo}/bootstrap.php"; \PhpOffice\PhpWord\Autoloader::register(); diff --git a/samples/Sample_Footer.php b/samples/Sample_Footer.php index 95ac693fc3..2d89bfd253 100644 --- a/samples/Sample_Footer.php +++ b/samples/Sample_Footer.php @@ -1,7 +1,4 @@ '); diff --git a/src/PhpWord/Autoloader.php b/src/PhpWord/Autoloader.php index 68da845de3..1865292b76 100644 --- a/src/PhpWord/Autoloader.php +++ b/src/PhpWord/Autoloader.php @@ -17,9 +17,6 @@ namespace PhpOffice\PhpWord; -/** - * Autoloader - */ class Autoloader { /** @const string */ diff --git a/src/PhpWord/SimpleType/Jc.php b/src/PhpWord/SimpleType/Jc.php index 3d7366e403..ff94db169d 100644 --- a/src/PhpWord/SimpleType/Jc.php +++ b/src/PhpWord/SimpleType/Jc.php @@ -17,6 +17,8 @@ namespace PhpOffice\PhpWord\SimpleType; +use Zend\Validator\InArray; + /** * Horizontal Alignment Type. * @@ -35,23 +37,45 @@ final class Jc const LOW_KASHIDA = 'lowKashida'; const THAI_DISTRIBUTE = 'thaiDistribute'; + /** + * @deprecated 0.13.0 Use `START` instead. + */ + const LEFT = 'left'; + /** + * @deprecated 0.13.0 Use `END` instead. + */ + const RIGHT = 'right'; + /** + * @deprecated 0.13.0 Use `BOTH` instead. + */ + const JUSTIFY = 'justify'; + /** * @since 0.13.0 * - * @return string[] + * @return \Zend\Validator\InArray */ - final public static function getAllowedValues() - { - return array( - self::START, - self::CENTER, - self::END, - self::MEDIUM_KASHIDA, - self::DISTRIBUTE, - self::NUM_TAB, - self::HIGH_KASHIDA, - self::LOW_KASHIDA, - self::THAI_DISTRIBUTE, + final public static function getValidator() { + // todo: consider caching validator instances. + return new InArray( + array ( + 'haystack' => array( + self::START, + self::CENTER, + self::END, + self::BOTH, + self::MEDIUM_KASHIDA, + self::DISTRIBUTE, + self::NUM_TAB, + self::HIGH_KASHIDA, + self::LOW_KASHIDA, + self::THAI_DISTRIBUTE, + self::LEFT, + self::RIGHT, + self::JUSTIFY, + ), + 'strict' => InArray::COMPARE_STRICT, + ) ); } } diff --git a/src/PhpWord/SimpleType/JcTable.php b/src/PhpWord/SimpleType/JcTable.php index e9928a01fd..8a918fe7bb 100644 --- a/src/PhpWord/SimpleType/JcTable.php +++ b/src/PhpWord/SimpleType/JcTable.php @@ -17,6 +17,8 @@ namespace PhpOffice\PhpWord\SimpleType; +use Zend\Validator\InArray; + /** * Table Alignment Type. * @@ -28,13 +30,31 @@ final class JcTable const CENTER = 'center'; const END = 'end'; + /** + * @deprecated 0.13.0 Use `START` instead. + */ + const LEFT = 'left'; + /** + * @deprecated 0.13.0 Use `END` instead. + */ + const RIGHT = 'right'; + /** + * @deprecated 0.13.0 Use `CENTER` instead. + */ + const JUSTIFY = 'justify'; + /** * @since 0.13.0 * - * @return string[] + * @return \Zend\Validator\InArray */ - final public static function getAllowedValues() - { - return array(self::START, self::CENTER, self::END); + final public static function getValidator() { + // todo: consider caching validator instances. + return new InArray( + array ( + 'haystack' => array(self::START, self::CENTER, self::END, self::LEFT, self::RIGHT, self::JUSTIFY), + 'strict' => InArray::COMPARE_STRICT, + ) + ); } } diff --git a/src/PhpWord/Style/Frame.php b/src/PhpWord/Style/Frame.php index 055a4e8944..13388f6bc6 100644 --- a/src/PhpWord/Style/Frame.php +++ b/src/PhpWord/Style/Frame.php @@ -200,8 +200,25 @@ public function getAlignment() */ public function setAlignment($value) { - if (in_array($value, Jc::getAllowedValues(), true)) { - $this->alignment = $value; + if (Jc::getValidator()->isValid($value)) { + $alignment = ''; + + switch ($value) { + case Jc::LEFT: + $alignment = Jc::START; + break; + case Jc::RIGHT: + $alignment = Jc::END; + break; + case Jc::JUSTIFY: + $alignment = Jc::BOTH; + break; + default: + $alignment = $value; + break; + } + + $this->alignment = $alignment; } return $this; diff --git a/src/PhpWord/Style/NumberingLevel.php b/src/PhpWord/Style/NumberingLevel.php index 91f40df247..46686bf6fe 100644 --- a/src/PhpWord/Style/NumberingLevel.php +++ b/src/PhpWord/Style/NumberingLevel.php @@ -298,8 +298,25 @@ public function getAlignment() */ public function setAlignment($value) { - if (in_array($value, Jc::getAllowedValues(), true)) { - $this->alignment = $value; + if (Jc::getValidator()->isValid($value)) { + $alignment = ''; + + switch ($value) { + case Jc::LEFT: + $alignment = Jc::START; + break; + case Jc::RIGHT: + $alignment = Jc::END; + break; + case Jc::JUSTIFY: + $alignment = Jc::BOTH; + break; + default: + $alignment = $value; + break; + } + + $this->alignment = $alignment; } return $this; diff --git a/src/PhpWord/Style/Paragraph.php b/src/PhpWord/Style/Paragraph.php index 78a9c95f97..a98ca258cc 100644 --- a/src/PhpWord/Style/Paragraph.php +++ b/src/PhpWord/Style/Paragraph.php @@ -232,8 +232,25 @@ public function getAlignment() */ public function setAlignment($value) { - if (in_array($value, Jc::getAllowedValues(), true)) { - $this->alignment = $value; + if (Jc::getValidator()->isValid($value)) { + $alignment = ''; + + switch ($value) { + case Jc::LEFT: + $alignment = Jc::START; + break; + case Jc::RIGHT: + $alignment = Jc::END; + break; + case Jc::JUSTIFY: + $alignment = Jc::BOTH; + break; + default: + $alignment = $value; + break; + } + + $this->alignment = $alignment; } return $this; diff --git a/src/PhpWord/Style/Table.php b/src/PhpWord/Style/Table.php index ea4e493284..717a6bc168 100644 --- a/src/PhpWord/Style/Table.php +++ b/src/PhpWord/Style/Table.php @@ -509,8 +509,25 @@ public function getAlignment() */ public function setAlignment($value) { - if (in_array($value, JcTable::getAllowedValues(), true)) { - $this->alignment = $value; + if (JcTable::getValidator()->isValid($value)) { + $alignment = ''; + + switch ($value) { + case JcTable::LEFT: + $alignment = JcTable::START; + break; + case JcTable::RIGHT: + $alignment = JcTable::END; + break; + case JcTable::JUSTIFY: + $alignment = JcTable::CENTER; + break; + default: + $alignment = $value; + break; + } + + $this->alignment = $alignment; } return $this; diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 6a1398a4db..8ea94aede9 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -15,6 +15,8 @@ * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ +require_once __DIR__ . '/../bootstrap.php'; + date_default_timezone_set('UTC'); // defining base dir for tests @@ -22,18 +24,6 @@ define('PHPWORD_TESTS_BASE_DIR', realpath(__DIR__)); } -$vendorDirPath = realpath(__DIR__ . '/../vendor'); -if (file_exists($vendorDirPath . '/autoload.php')) { - require $vendorDirPath . '/autoload.php'; -} else { - throw new Exception( - sprintf( - 'Could not find file \'%s\'. It is generated by Composer. Use \'install\' or \'update\' Composer commands to move forward.', - $vendorDirPath . '/autoload.php' - ) - ); -} - spl_autoload_register(function ($class) { $class = ltrim($class, '\\'); $prefix = 'PhpOffice\\PhpWord\\Tests';