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
|
||||
- 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.
|
||||
|
|
|
|||
|
|
@ -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": {
|
||||
"php": ">=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": {
|
||||
|
|
|
|||
|
|
@ -22,14 +22,12 @@ Installation
|
|||
------------
|
||||
|
||||
There are two ways to install PHPWord, i.e. via
|
||||
`Composer <http://getcomposer.org/>`__ or manually by downloading the
|
||||
library.
|
||||
`Composer <http://getcomposer.org/>`__ 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();
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,4 @@
|
|||
<?php
|
||||
/**
|
||||
* Footer file
|
||||
*/
|
||||
if (CLI) {
|
||||
return;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,14 +1,10 @@
|
|||
<?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\Settings;
|
||||
|
||||
date_default_timezone_set('UTC');
|
||||
error_reporting(E_ALL);
|
||||
define('CLI', (PHP_SAPI == 'cli') ? true : false);
|
||||
define('EOL', CLI ? PHP_EOL : '<br />');
|
||||
|
|
|
|||
|
|
@ -17,9 +17,6 @@
|
|||
|
||||
namespace PhpOffice\PhpWord;
|
||||
|
||||
/**
|
||||
* Autoloader
|
||||
*/
|
||||
class Autoloader
|
||||
{
|
||||
/** @const string */
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -200,8 +200,25 @@ class Frame extends AbstractStyle
|
|||
*/
|
||||
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;
|
||||
|
|
|
|||
|
|
@ -298,8 +298,25 @@ class NumberingLevel extends AbstractStyle
|
|||
*/
|
||||
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;
|
||||
|
|
|
|||
|
|
@ -232,8 +232,25 @@ class Paragraph extends Border
|
|||
*/
|
||||
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;
|
||||
|
|
|
|||
|
|
@ -509,8 +509,25 @@ class Table extends Border
|
|||
*/
|
||||
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;
|
||||
|
|
|
|||
|
|
@ -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 @@ if (!defined('PHPWORD_TESTS_BASE_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) {
|
||||
$class = ltrim($class, '\\');
|
||||
$prefix = 'PhpOffice\\PhpWord\\Tests';
|
||||
|
|
|
|||
Loading…
Reference in New Issue