2014-03-22 10:06:08 +04:00
|
|
|
<?php
|
|
|
|
|
/**
|
2014-03-26 16:33:20 +07:00
|
|
|
* PHPWord
|
2014-03-22 10:06:08 +04:00
|
|
|
*
|
2014-03-27 23:55:06 +07:00
|
|
|
* @link https://github.com/PHPOffice/PHPWord
|
|
|
|
|
* @copyright 2014 PHPWord
|
2014-05-04 17:55:54 +07:00
|
|
|
* @license http://www.gnu.org/licenses/lgpl.txt LGPL
|
2014-03-22 10:06:08 +04:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
namespace PhpOffice\PhpWord;
|
|
|
|
|
|
2014-03-31 01:13:02 +07:00
|
|
|
use PhpOffice\PhpWord\Exception\Exception;
|
2014-03-22 10:06:08 +04:00
|
|
|
|
2014-03-24 00:26:10 +07:00
|
|
|
/**
|
|
|
|
|
* IO factory
|
|
|
|
|
*/
|
2014-03-22 10:06:08 +04:00
|
|
|
abstract class IOFactory
|
|
|
|
|
{
|
|
|
|
|
/**
|
2014-03-24 00:26:10 +07:00
|
|
|
* Create new writer
|
|
|
|
|
*
|
2014-04-08 16:09:31 +07:00
|
|
|
* @param PhpWord $phpWord
|
2014-03-22 10:06:08 +04:00
|
|
|
* @param string $name
|
2014-04-16 17:22:30 +04:00
|
|
|
* @return \PhpOffice\PhpWord\Writer\WriterInterface
|
|
|
|
|
* @throws \PhpOffice\PhpWord\Exception\Exception
|
2014-03-22 10:06:08 +04:00
|
|
|
*/
|
2014-04-03 11:34:06 +07:00
|
|
|
public static function createWriter(PhpWord $phpWord, $name = 'Word2007')
|
2014-03-22 10:06:08 +04:00
|
|
|
{
|
2014-04-13 23:17:39 +07:00
|
|
|
if (!in_array($name, array('WriterInterface', 'Word2007', 'ODText', 'RTF', 'HTML', 'PDF'))) {
|
2014-03-23 12:14:07 -04:00
|
|
|
throw new Exception("\"{$name}\" is not a valid writer.");
|
2014-03-22 10:06:08 +04:00
|
|
|
}
|
2014-03-23 12:14:07 -04:00
|
|
|
|
|
|
|
|
$fqName = "PhpOffice\\PhpWord\\Writer\\{$name}";
|
|
|
|
|
return new $fqName($phpWord);
|
2014-03-22 10:06:08 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2014-03-24 00:26:10 +07:00
|
|
|
* Create new reader
|
|
|
|
|
*
|
2014-03-22 10:06:08 +04:00
|
|
|
* @param string $name
|
2014-04-16 17:22:30 +04:00
|
|
|
* @return \PhpOffice\PhpWord\Reader\ReaderInterface
|
|
|
|
|
* @throws \PhpOffice\PhpWord\Exception\Exception
|
2014-03-22 10:06:08 +04:00
|
|
|
*/
|
2014-04-03 11:34:06 +07:00
|
|
|
public static function createReader($name = 'Word2007')
|
2014-03-22 10:06:08 +04:00
|
|
|
{
|
2014-04-29 01:18:01 +07:00
|
|
|
if (!in_array($name, array('ReaderInterface', 'Word2007', 'ODText'))) {
|
2014-03-23 12:14:07 -04:00
|
|
|
throw new Exception("\"{$name}\" is not a valid reader.");
|
2014-03-22 10:06:08 +04:00
|
|
|
}
|
2014-03-23 12:14:07 -04:00
|
|
|
|
|
|
|
|
$fqName = "PhpOffice\\PhpWord\\Reader\\{$name}";
|
|
|
|
|
return new $fqName();
|
2014-03-22 10:06:08 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Loads PhpWord from file
|
|
|
|
|
*
|
|
|
|
|
* @param string $filename The name of the file
|
|
|
|
|
* @param string $readerName
|
2014-04-08 16:09:31 +07:00
|
|
|
* @return PhpWord
|
2014-03-22 10:06:08 +04:00
|
|
|
*/
|
|
|
|
|
public static function load($filename, $readerName = 'Word2007')
|
|
|
|
|
{
|
|
|
|
|
$reader = self::createReader($readerName);
|
|
|
|
|
return $reader->load($filename);
|
|
|
|
|
}
|
2014-03-23 17:37:26 +07:00
|
|
|
}
|