Skip to content

Commit 5a75d84

Browse files
author
Roman Syroeshko
committed
Merge remote-tracking branch 'origin/develop' into develop
2 parents ec25dd3 + 1a40f66 commit 5a75d84

File tree

10 files changed

+2849
-67
lines changed

10 files changed

+2849
-67
lines changed

.gitignore

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,16 @@
44
.Trashes
55
Thumbs.db
66
Desktop.ini
7-
composer.phar
7+
.idea
8+
_build
89
phpunit.xml
10+
composer.lock
11+
composer.phar
12+
vendor
13+
/report
14+
/samples/resources
15+
/samples/results
16+
/.settings
917
phpword.ini
1018
/.buildpath
11-
/.idea
12-
/.project
13-
/.settings
14-
/build
15-
/vendor
16-
/phpunit.bat
19+
/.project

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ This is the changelog between releases of PHPWord. Releases are listed in revers
44

55
## 0.12.0 - Not yet released
66

7-
This release added form fields (textinput, checkbox, and dropdown), drawing shapes (arc, curve, line, polyline, rect, oval), and basic 2D chart (pie, doughnut, bar, line, area, scatter, radar) elements along with some new styles.
7+
This release added form fields (textinput, checkbox, and dropdown), drawing shapes (arc, curve, line, polyline, rect, oval), and basic 2D chart (pie, doughnut, bar, line, area, scatter, radar) elements along with some new styles. Basic MsDoc reader is introduced.
88

99
### Features
1010

@@ -23,6 +23,7 @@ This release added form fields (textinput, checkbox, and dropdown), drawing shap
2323
- SDT: Ability to add structured document tag elements (comboBox, dropDownList, date) - @ivanlanin
2424
- Paragraph: Support for paragraph with borders - @ivanlanin GH-294
2525
- Word2007 Writer : Support for RTL - @Progi1984 GH-331
26+
- MsDOC Reader: Basic MsDOC Reader - @Progi1984 GH-23 GH-287
2627

2728
### Bugfixes
2829

samples/Sample_11_ReadWord97.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
include_once 'Sample_Header.php';
3+
4+
// Read contents
5+
$name = basename(__FILE__, '.php');
6+
$source = "resources/{$name}.doc";
7+
echo date('H:i:s'), " Reading contents from `{$source}`", EOL;
8+
$phpWord = \PhpOffice\PhpWord\IOFactory::load($source, 'MsDoc');
9+
10+
// (Re)write contents
11+
$writers = array('Word2007' => 'docx', 'ODText' => 'odt', 'RTF' => 'rtf');
12+
foreach ($writers as $writer => $extension) {
13+
echo date('H:i:s'), " Write to {$writer} format", EOL;
14+
$xmlWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, $writer);
15+
$xmlWriter->save("{$name}.{$extension}");
16+
rename("{$name}.{$extension}", "results/{$name}.{$extension}");
17+
}
18+
19+
include_once 'Sample_Footer.php';

samples/Sample_Footer.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
/**
33
* Footer file
44
*/
5+
if (CLI) {
6+
return;
7+
}
58
?>
69
</div>
710
<script src="bootstrap/js/jquery.min.js"></script>

samples/Sample_Header.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
<?php
2+
3+
date_default_timezone_set('Europe/Paris');
4+
25
/**
36
* Header file
47
*/
48.5 KB
Binary file not shown.

src/PhpWord/IOFactory.php

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,47 @@
11
<?php
22
/**
3-
* This file is part of PHPWord - A pure PHP library for reading and writing
4-
* word processing documents.
5-
*
6-
* PHPWord is free software distributed under the terms of the GNU Lesser
7-
* General Public License version 3 as published by the Free Software Foundation.
8-
*
9-
* For the full copyright and license information, please read the LICENSE
10-
* file that was distributed with this source code. For the full list of
11-
* contributors, visit https://github.com/PHPOffice/PHPWord/contributors.
3+
* PHPWord
124
*
135
* @link https://github.com/PHPOffice/PHPWord
14-
* @copyright 2010-2014 PHPWord contributors
15-
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
6+
* @copyright 2014 PHPWord
7+
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
168
*/
179

1810
namespace PhpOffice\PhpWord;
1911

2012
use PhpOffice\PhpWord\Exception\Exception;
13+
use PhpOffice\PhpWord\Writer\WriterInterface;
14+
use PhpOffice\PhpWord\Reader\ReaderInterface;
2115

2216
/**
23-
* IO Factory
17+
* IO factory
2418
*/
2519
abstract class IOFactory
2620
{
2721
/**
2822
* Create new writer
2923
*
30-
* @param \PhpOffice\PhpWord\PhpWord $phpWord
24+
* @param PhpWord $phpWord
3125
* @param string $name
32-
* @return \PhpOffice\PhpWord\Writer\WriterInterface
26+
* @return WriterInterface
27+
* @throws Exception
3328
*/
3429
public static function createWriter(PhpWord $phpWord, $name = 'Word2007')
3530
{
36-
return self::createObject('Writer', $name, $phpWord);
31+
if ($name !== 'WriterInterface' && $name !== 'ODText' && $name !== 'RTF' && $name !== 'Word2007') {
32+
throw new Exception("\"{$name}\" is not a valid writer.");
33+
}
34+
35+
$fqName = "PhpOffice\\PhpWord\\Writer\\{$name}";
36+
return new $fqName($phpWord);
3737
}
3838

3939
/**
4040
* Create new reader
4141
*
4242
* @param string $name
43-
* @return \PhpOffice\PhpWord\Reader\ReaderInterface
43+
* @return ReaderInterface
44+
* @throws Exception
4445
*/
4546
public static function createReader($name = 'Word2007')
4647
{
@@ -65,7 +66,6 @@ private static function createObject($type, $name, $phpWord = null)
6566
throw new Exception("\"{$name}\" is not a valid {$type}.");
6667
}
6768
}
68-
6969
/**
7070
* Loads PhpWord from file
7171
*
@@ -77,10 +77,8 @@ public static function load($filename, $readerName = 'Word2007')
7777
{
7878
/** @var \PhpOffice\PhpWord\Reader\ReaderInterface $reader */
7979
$reader = self::createReader($readerName);
80-
8180
return $reader->load($filename);
8281
}
83-
8482
/**
8583
* Check if it's a concrete class (not abstract nor interface)
8684
*
@@ -90,7 +88,6 @@ public static function load($filename, $readerName = 'Word2007')
9088
private static function isConcreteClass($class)
9189
{
9290
$reflection = new \ReflectionClass($class);
93-
9491
return !$reflection->isAbstract() && !$reflection->isInterface();
9592
}
9693
}

0 commit comments

Comments
 (0)