Added backward compatibility for deprecated alignment options.
This commit is contained in:
parent
d3908deff8
commit
d74c0bd878
|
|
@ -16,10 +16,13 @@ Place announcement text here.
|
||||||
### Changed
|
### Changed
|
||||||
- Improved error message for the case when `autoload.php` is not found. - @RomanSyroeshko #371
|
- 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
|
- 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
|
### Deprecated
|
||||||
- `getAlign` and `setAlign` methods of `NumberingLevel`, `Frame`, `Table`, and `Paragraph` styles.
|
- `getAlign` and `setAlign` methods of `NumberingLevel`, `Frame`, `Table`, and `Paragraph` styles.
|
||||||
Use the correspondent `getAlignment` and `setAlignment` methods instead.
|
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
|
### Removed
|
||||||
- `PhpOffice\PhpWord\Style\Alignment`. Style properties, which previously stored instances of this class, now deal with strings.
|
- `PhpOffice\PhpWord\Style\Alignment`. Style properties, which previously stored instances of this class, now deal with strings.
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,28 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* This file is part of PHPWord - A pure PHP library for reading and writing
|
||||||
|
* word processing documents.
|
||||||
|
*
|
||||||
|
* PHPWord is free software distributed under the terms of the GNU Lesser
|
||||||
|
* General Public License version 3 as published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* For the full copyright and license information, please read the LICENSE
|
||||||
|
* file that was distributed with this source code. For the full list of
|
||||||
|
* contributors, visit https://github.com/PHPOffice/PHPWord/contributors. test bootstrap
|
||||||
|
*
|
||||||
|
* @link https://github.com/PHPOffice/PHPWord
|
||||||
|
* @copyright 2010-2014 PHPWord contributors
|
||||||
|
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
|
||||||
|
*/
|
||||||
|
|
||||||
|
$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 --prefer-source\' or \'update --prefer-source\' Composer commands to move forward.',
|
||||||
|
$vendorDirPath . '/autoload.php'
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
@ -33,7 +33,8 @@
|
||||||
],
|
],
|
||||||
"require": {
|
"require": {
|
||||||
"php": ">=5.3.3",
|
"php": ">=5.3.3",
|
||||||
"ext-xml": "*"
|
"ext-xml": "*",
|
||||||
|
"zendframework/zend-validator": "2.5.*"
|
||||||
},
|
},
|
||||||
"require-dev": {
|
"require-dev": {
|
||||||
"phpunit/phpunit": "3.7.*",
|
"phpunit/phpunit": "3.7.*",
|
||||||
|
|
@ -44,14 +45,15 @@
|
||||||
"phploc/phploc": "2.*",
|
"phploc/phploc": "2.*",
|
||||||
"dompdf/dompdf":"0.6.*",
|
"dompdf/dompdf":"0.6.*",
|
||||||
"tecnick.com/tcpdf": "6.*",
|
"tecnick.com/tcpdf": "6.*",
|
||||||
"mpdf/mpdf": "5.*"
|
"mpdf/mpdf": "5.*",
|
||||||
|
"zendframework/zend-validator": "2.5.*"
|
||||||
},
|
},
|
||||||
"suggest": {
|
"suggest": {
|
||||||
"ext-zip": "Used to write DOCX and ODT",
|
"ext-zip": "Allows writing DOCX and ODT",
|
||||||
"ext-gd2": "Used to add images",
|
"ext-gd2": "Allows adding images",
|
||||||
"ext-xmlwriter": "Used to write DOCX and ODT",
|
"ext-xmlwriter": "Allows writing DOCX and ODT",
|
||||||
"ext-xsl": "Used to apply XSL style sheet to main document part of OOXML template",
|
"ext-xsl": "Allows applying XSL style sheet to main document part of OOXML template",
|
||||||
"dompdf/dompdf": "Used to write PDF"
|
"dompdf/dompdf": "Allows writing PDF"
|
||||||
},
|
},
|
||||||
"autoload": {
|
"autoload": {
|
||||||
"psr-4": {
|
"psr-4": {
|
||||||
|
|
|
||||||
|
|
@ -22,14 +22,12 @@ Installation
|
||||||
------------
|
------------
|
||||||
|
|
||||||
There are two ways to install PHPWord, i.e. via
|
There are two ways to install PHPWord, i.e. via
|
||||||
`Composer <http://getcomposer.org/>`__ or manually by downloading the
|
`Composer <http://getcomposer.org/>`__ or manually by downloading the library.
|
||||||
library.
|
|
||||||
|
|
||||||
Using Composer
|
Using Composer
|
||||||
~~~~~~~~~~~~~~
|
~~~~~~~~~~~~~~
|
||||||
|
|
||||||
To install via Composer, add the following lines to your
|
To install via Composer, add the following lines to your ``composer.json``:
|
||||||
``composer.json``:
|
|
||||||
|
|
||||||
.. code-block:: 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.
|
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
|
git clone https://github.com/PHPOffice/PHPWord.git
|
||||||
|
|
||||||
To use the library, include ``src/PhpWord/Autoloader.php`` in your PHP script and
|
To use the library, include ``bootstrap.php`` in your PHP script and invoke ``Autoloader::register``.
|
||||||
invoke ``Autoloader::register``.
|
|
||||||
|
|
||||||
.. code-block:: php
|
.. code-block:: php
|
||||||
|
|
||||||
require_once '/path/to/src/PhpWord/Autoloader.php';
|
require_once "${path_to_the_cloned_repo}/bootstrap.php";
|
||||||
\PhpOffice\PhpWord\Autoloader::register();
|
\PhpOffice\PhpWord\Autoloader::register();
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,4 @@
|
||||||
<?php
|
<?php
|
||||||
/**
|
|
||||||
* Footer file
|
|
||||||
*/
|
|
||||||
if (CLI) {
|
if (CLI) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,14 +1,10 @@
|
||||||
<?php
|
<?php
|
||||||
require_once __DIR__ . '/../src/PhpWord/Autoloader.php';
|
require_once __DIR__ . '/../bootstrap.php';
|
||||||
|
|
||||||
date_default_timezone_set('UTC');
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Header file
|
|
||||||
*/
|
|
||||||
use PhpOffice\PhpWord\Autoloader;
|
use PhpOffice\PhpWord\Autoloader;
|
||||||
use PhpOffice\PhpWord\Settings;
|
use PhpOffice\PhpWord\Settings;
|
||||||
|
|
||||||
|
date_default_timezone_set('UTC');
|
||||||
error_reporting(E_ALL);
|
error_reporting(E_ALL);
|
||||||
define('CLI', (PHP_SAPI == 'cli') ? true : false);
|
define('CLI', (PHP_SAPI == 'cli') ? true : false);
|
||||||
define('EOL', CLI ? PHP_EOL : '<br />');
|
define('EOL', CLI ? PHP_EOL : '<br />');
|
||||||
|
|
|
||||||
|
|
@ -17,9 +17,6 @@
|
||||||
|
|
||||||
namespace PhpOffice\PhpWord;
|
namespace PhpOffice\PhpWord;
|
||||||
|
|
||||||
/**
|
|
||||||
* Autoloader
|
|
||||||
*/
|
|
||||||
class Autoloader
|
class Autoloader
|
||||||
{
|
{
|
||||||
/** @const string */
|
/** @const string */
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,8 @@
|
||||||
|
|
||||||
namespace PhpOffice\PhpWord\SimpleType;
|
namespace PhpOffice\PhpWord\SimpleType;
|
||||||
|
|
||||||
|
use Zend\Validator\InArray;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Horizontal Alignment Type.
|
* Horizontal Alignment Type.
|
||||||
*
|
*
|
||||||
|
|
@ -35,23 +37,45 @@ final class Jc
|
||||||
const LOW_KASHIDA = 'lowKashida';
|
const LOW_KASHIDA = 'lowKashida';
|
||||||
const THAI_DISTRIBUTE = 'thaiDistribute';
|
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
|
* @since 0.13.0
|
||||||
*
|
*
|
||||||
* @return string[]
|
* @return \Zend\Validator\InArray
|
||||||
*/
|
*/
|
||||||
final public static function getAllowedValues()
|
final public static function getValidator() {
|
||||||
{
|
// todo: consider caching validator instances.
|
||||||
return array(
|
return new InArray(
|
||||||
|
array (
|
||||||
|
'haystack' => array(
|
||||||
self::START,
|
self::START,
|
||||||
self::CENTER,
|
self::CENTER,
|
||||||
self::END,
|
self::END,
|
||||||
|
self::BOTH,
|
||||||
self::MEDIUM_KASHIDA,
|
self::MEDIUM_KASHIDA,
|
||||||
self::DISTRIBUTE,
|
self::DISTRIBUTE,
|
||||||
self::NUM_TAB,
|
self::NUM_TAB,
|
||||||
self::HIGH_KASHIDA,
|
self::HIGH_KASHIDA,
|
||||||
self::LOW_KASHIDA,
|
self::LOW_KASHIDA,
|
||||||
self::THAI_DISTRIBUTE,
|
self::THAI_DISTRIBUTE,
|
||||||
|
self::LEFT,
|
||||||
|
self::RIGHT,
|
||||||
|
self::JUSTIFY,
|
||||||
|
),
|
||||||
|
'strict' => InArray::COMPARE_STRICT,
|
||||||
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,8 @@
|
||||||
|
|
||||||
namespace PhpOffice\PhpWord\SimpleType;
|
namespace PhpOffice\PhpWord\SimpleType;
|
||||||
|
|
||||||
|
use Zend\Validator\InArray;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Table Alignment Type.
|
* Table Alignment Type.
|
||||||
*
|
*
|
||||||
|
|
@ -28,13 +30,31 @@ final class JcTable
|
||||||
const CENTER = 'center';
|
const CENTER = 'center';
|
||||||
const END = 'end';
|
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
|
* @since 0.13.0
|
||||||
*
|
*
|
||||||
* @return string[]
|
* @return \Zend\Validator\InArray
|
||||||
*/
|
*/
|
||||||
final public static function getAllowedValues()
|
final public static function getValidator() {
|
||||||
{
|
// todo: consider caching validator instances.
|
||||||
return array(self::START, self::CENTER, self::END);
|
return new InArray(
|
||||||
|
array (
|
||||||
|
'haystack' => array(self::START, self::CENTER, self::END, self::LEFT, self::RIGHT, self::JUSTIFY),
|
||||||
|
'strict' => InArray::COMPARE_STRICT,
|
||||||
|
)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -200,8 +200,25 @@ class Frame extends AbstractStyle
|
||||||
*/
|
*/
|
||||||
public function setAlignment($value)
|
public function setAlignment($value)
|
||||||
{
|
{
|
||||||
if (in_array($value, Jc::getAllowedValues(), true)) {
|
if (Jc::getValidator()->isValid($value)) {
|
||||||
$this->alignment = $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;
|
return $this;
|
||||||
|
|
|
||||||
|
|
@ -298,8 +298,25 @@ class NumberingLevel extends AbstractStyle
|
||||||
*/
|
*/
|
||||||
public function setAlignment($value)
|
public function setAlignment($value)
|
||||||
{
|
{
|
||||||
if (in_array($value, Jc::getAllowedValues(), true)) {
|
if (Jc::getValidator()->isValid($value)) {
|
||||||
$this->alignment = $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;
|
return $this;
|
||||||
|
|
|
||||||
|
|
@ -232,8 +232,25 @@ class Paragraph extends Border
|
||||||
*/
|
*/
|
||||||
public function setAlignment($value)
|
public function setAlignment($value)
|
||||||
{
|
{
|
||||||
if (in_array($value, Jc::getAllowedValues(), true)) {
|
if (Jc::getValidator()->isValid($value)) {
|
||||||
$this->alignment = $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;
|
return $this;
|
||||||
|
|
|
||||||
|
|
@ -509,8 +509,25 @@ class Table extends Border
|
||||||
*/
|
*/
|
||||||
public function setAlignment($value)
|
public function setAlignment($value)
|
||||||
{
|
{
|
||||||
if (in_array($value, JcTable::getAllowedValues(), true)) {
|
if (JcTable::getValidator()->isValid($value)) {
|
||||||
$this->alignment = $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;
|
return $this;
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,8 @@
|
||||||
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
|
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
require_once __DIR__ . '/../bootstrap.php';
|
||||||
|
|
||||||
date_default_timezone_set('UTC');
|
date_default_timezone_set('UTC');
|
||||||
|
|
||||||
// defining base dir for tests
|
// defining base dir for tests
|
||||||
|
|
@ -22,18 +24,6 @@ if (!defined('PHPWORD_TESTS_BASE_DIR')) {
|
||||||
define('PHPWORD_TESTS_BASE_DIR', realpath(__DIR__));
|
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) {
|
spl_autoload_register(function ($class) {
|
||||||
$class = ltrim($class, '\\');
|
$class = ltrim($class, '\\');
|
||||||
$prefix = 'PhpOffice\\PhpWord\\Tests';
|
$prefix = 'PhpOffice\\PhpWord\\Tests';
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue