This commit is contained in:
parent
f25833c60d
commit
56c3d8eda2
|
|
@ -47,6 +47,7 @@ This release added form fields (textinput, checkbox, and dropdown), drawing shap
|
||||||
- Autoloader: Add the ability to set the autoloader options - @bskrtich GH-267
|
- Autoloader: Add the ability to set the autoloader options - @bskrtich GH-267
|
||||||
- Element: Refactor elements to move set relation Id from container to element - @ivanlanin
|
- Element: Refactor elements to move set relation Id from container to element - @ivanlanin
|
||||||
- Introduced CreateTemporaryFileException, CopyFileException - @RomanSyroeshko
|
- Introduced CreateTemporaryFileException, CopyFileException - @RomanSyroeshko
|
||||||
|
- Settings: added method to set user defined temporary directory - @RomanSyroeshko GH-310
|
||||||
|
|
||||||
## 0.11.1 - 2 June 2014
|
## 0.11.1 - 2 June 2014
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,7 @@ compatibility = true
|
||||||
zipClass = ZipArchive
|
zipClass = ZipArchive
|
||||||
pdfRendererName = DomPDF
|
pdfRendererName = DomPDF
|
||||||
pdfRendererPath =
|
pdfRendererPath =
|
||||||
|
; tempDir = "C:\PhpWordTemp"
|
||||||
|
|
||||||
[Font]
|
[Font]
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@ include_once 'Sample_Header.php';
|
||||||
$requirements = array(
|
$requirements = array(
|
||||||
'php' => array('PHP 5.3.0', version_compare(phpversion(), '5.3.0', '>=')),
|
'php' => array('PHP 5.3.0', version_compare(phpversion(), '5.3.0', '>=')),
|
||||||
'xml' => array('PHP extension XML', extension_loaded('xml')),
|
'xml' => array('PHP extension XML', extension_loaded('xml')),
|
||||||
'temp' => array('Temp folder "<code>' . sys_get_temp_dir() . '</code>" is writable', is_writable(sys_get_temp_dir())),
|
'temp' => array('Temp folder "<code>' . Settings::getTempDir() . '</code>" is writable', is_writable(Settings::getTempDir())),
|
||||||
'zip' => array('PHP extension ZipArchive (optional)', extension_loaded('zip')),
|
'zip' => array('PHP extension ZipArchive (optional)', extension_loaded('zip')),
|
||||||
'gd' => array('PHP extension GD (optional)', extension_loaded('gd')),
|
'gd' => array('PHP extension GD (optional)', extension_loaded('gd')),
|
||||||
'xmlw' => array('PHP extension XMLWriter (optional)', extension_loaded('xmlwriter')),
|
'xmlw' => array('PHP extension XMLWriter (optional)', extension_loaded('xmlwriter')),
|
||||||
|
|
|
||||||
|
|
@ -19,6 +19,7 @@ namespace PhpOffice\PhpWord\Element;
|
||||||
|
|
||||||
use PhpOffice\PhpWord\Exception\InvalidImageException;
|
use PhpOffice\PhpWord\Exception\InvalidImageException;
|
||||||
use PhpOffice\PhpWord\Exception\UnsupportedImageTypeException;
|
use PhpOffice\PhpWord\Exception\UnsupportedImageTypeException;
|
||||||
|
use PhpOffice\PhpWord\Settings;
|
||||||
use PhpOffice\PhpWord\Shared\ZipArchive;
|
use PhpOffice\PhpWord\Shared\ZipArchive;
|
||||||
use PhpOffice\PhpWord\Style\Image as ImageStyle;
|
use PhpOffice\PhpWord\Style\Image as ImageStyle;
|
||||||
|
|
||||||
|
|
@ -313,8 +314,8 @@ class Image extends AbstractElement
|
||||||
if ($zip->open($zipFilename) !== false) {
|
if ($zip->open($zipFilename) !== false) {
|
||||||
if ($zip->locateName($imageFilename)) {
|
if ($zip->locateName($imageFilename)) {
|
||||||
$isTemp = true;
|
$isTemp = true;
|
||||||
$zip->extractTo(sys_get_temp_dir(), $imageFilename);
|
$zip->extractTo(Settings::getTempDir(), $imageFilename);
|
||||||
$actualSource = sys_get_temp_dir() . DIRECTORY_SEPARATOR . $imageFilename;
|
$actualSource = Settings::getTempDir() . DIRECTORY_SEPARATOR . $imageFilename;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$zip->close();
|
$zip->close();
|
||||||
|
|
@ -428,7 +429,7 @@ class Image extends AbstractElement
|
||||||
$imageData = null;
|
$imageData = null;
|
||||||
$source = substr($source, 6);
|
$source = substr($source, 6);
|
||||||
list($zipFilename, $imageFilename) = explode('#', $source);
|
list($zipFilename, $imageFilename) = explode('#', $source);
|
||||||
$tempFilename = tempnam(sys_get_temp_dir(), 'PHPWordImage');
|
$tempFilename = tempnam(Settings::getTempDir(), 'PHPWordImage');
|
||||||
|
|
||||||
$zip = new ZipArchive();
|
$zip = new ZipArchive();
|
||||||
if ($zip->open($zipFilename) !== false) {
|
if ($zip->open($zipFilename) !== false) {
|
||||||
|
|
|
||||||
|
|
@ -119,6 +119,13 @@ class Settings
|
||||||
*/
|
*/
|
||||||
private static $defaultFontSize = self::DEFAULT_FONT_SIZE;
|
private static $defaultFontSize = self::DEFAULT_FONT_SIZE;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The user defined temporary directory.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
private static $tempDir = '';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the compatibility option used by the XMLWriter
|
* Return the compatibility option used by the XMLWriter
|
||||||
*
|
*
|
||||||
|
|
@ -269,6 +276,35 @@ class Settings
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the user defined path to temporary directory.
|
||||||
|
*
|
||||||
|
* @param string $tempDir The user defined path to temporary directory.
|
||||||
|
* @return void
|
||||||
|
* @since 0.12.0
|
||||||
|
*/
|
||||||
|
public static function setTempDir($tempDir)
|
||||||
|
{
|
||||||
|
self::$tempDir = $tempDir;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns path to temporary directory.
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
* @since 0.12.0
|
||||||
|
*/
|
||||||
|
public static function getTempDir()
|
||||||
|
{
|
||||||
|
$tempDir = sys_get_temp_dir();
|
||||||
|
|
||||||
|
if (!empty(self::$tempDir)) {
|
||||||
|
$tempDir = self::$tempDir;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $tempDir;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get default font name
|
* Get default font name
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -83,7 +83,7 @@ class ZipArchive
|
||||||
$this->usePclzip = (Settings::getZipClass() != 'ZipArchive');
|
$this->usePclzip = (Settings::getZipClass() != 'ZipArchive');
|
||||||
if ($this->usePclzip) {
|
if ($this->usePclzip) {
|
||||||
if (!defined('PCLZIP_TEMPORARY_DIR')) {
|
if (!defined('PCLZIP_TEMPORARY_DIR')) {
|
||||||
define('PCLZIP_TEMPORARY_DIR', sys_get_temp_dir() . '/');
|
define('PCLZIP_TEMPORARY_DIR', Settings::getTempDir() . '/');
|
||||||
}
|
}
|
||||||
require_once 'PCLZip/pclzip.lib.php';
|
require_once 'PCLZip/pclzip.lib.php';
|
||||||
}
|
}
|
||||||
|
|
@ -139,7 +139,7 @@ class ZipArchive
|
||||||
$this->numFiles = $zip->numFiles;
|
$this->numFiles = $zip->numFiles;
|
||||||
} else {
|
} else {
|
||||||
$zip = new \PclZip($this->filename);
|
$zip = new \PclZip($this->filename);
|
||||||
$this->tempDir = sys_get_temp_dir();
|
$this->tempDir = Settings::getTempDir();
|
||||||
$this->numFiles = count($zip->listContent());
|
$this->numFiles = count($zip->listContent());
|
||||||
}
|
}
|
||||||
$this->zip = $zip;
|
$this->zip = $zip;
|
||||||
|
|
|
||||||
|
|
@ -67,7 +67,7 @@ class Template
|
||||||
*/
|
*/
|
||||||
public function __construct($fileName)
|
public function __construct($fileName)
|
||||||
{
|
{
|
||||||
$this->tempFileName = tempnam(sys_get_temp_dir(), '');
|
$this->tempFileName = tempnam(Settings::getTempDir(), 'PhpWord');
|
||||||
if (false === $this->tempFileName) {
|
if (false === $this->tempFileName) {
|
||||||
throw new CreateTemporaryFileException();
|
throw new CreateTemporaryFileException();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -20,6 +20,7 @@ namespace PhpOffice\PhpWord\Writer;
|
||||||
use PhpOffice\PhpWord\Exception\CopyFileException;
|
use PhpOffice\PhpWord\Exception\CopyFileException;
|
||||||
use PhpOffice\PhpWord\Exception\Exception;
|
use PhpOffice\PhpWord\Exception\Exception;
|
||||||
use PhpOffice\PhpWord\PhpWord;
|
use PhpOffice\PhpWord\PhpWord;
|
||||||
|
use PhpOffice\PhpWord\Settings;
|
||||||
use PhpOffice\PhpWord\Shared\ZipArchive;
|
use PhpOffice\PhpWord\Shared\ZipArchive;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -214,12 +215,12 @@ abstract class AbstractWriter implements WriterInterface
|
||||||
protected function getTempFile($filename)
|
protected function getTempFile($filename)
|
||||||
{
|
{
|
||||||
// Temporary directory
|
// Temporary directory
|
||||||
$this->setTempDir(sys_get_temp_dir() . '/PHPWordWriter/');
|
$this->setTempDir(Settings::getTempDir() . '/PHPWordWriter/');
|
||||||
|
|
||||||
// Temporary file
|
// Temporary file
|
||||||
$this->originalFilename = $filename;
|
$this->originalFilename = $filename;
|
||||||
if (strtolower($filename) == 'php://output' || strtolower($filename) == 'php://stdout') {
|
if (strtolower($filename) == 'php://output' || strtolower($filename) == 'php://stdout') {
|
||||||
$filename = @tempnam(sys_get_temp_dir(), 'phpword_');
|
$filename = tempnam(Settings::getTempDir(), 'phpword_');
|
||||||
// @codeCoverageIgnoreStart
|
// @codeCoverageIgnoreStart
|
||||||
// Can't find any test case. Uncomment when found.
|
// Can't find any test case. Uncomment when found.
|
||||||
if ($filename == '') {
|
if ($filename == '') {
|
||||||
|
|
|
||||||
|
|
@ -22,6 +22,7 @@ use PhpOffice\PhpWord\Settings;
|
||||||
/**
|
/**
|
||||||
* Test class for PhpOffice\PhpWord\Settings
|
* Test class for PhpOffice\PhpWord\Settings
|
||||||
*
|
*
|
||||||
|
* @coversDefaultClass \PhpOffice\PhpWord\Settings
|
||||||
* @runTestsInSeparateProcesses
|
* @runTestsInSeparateProcesses
|
||||||
*/
|
*/
|
||||||
class SettingsTest extends \PHPUnit_Framework_TestCase
|
class SettingsTest extends \PHPUnit_Framework_TestCase
|
||||||
|
|
@ -70,6 +71,31 @@ class SettingsTest extends \PHPUnit_Framework_TestCase
|
||||||
$this->assertFalse(Settings::setMeasurementUnit('foo'));
|
$this->assertFalse(Settings::setMeasurementUnit('foo'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers ::getTempDir
|
||||||
|
* @test
|
||||||
|
*/
|
||||||
|
public function testPhpTempDirIsUsedByDefault()
|
||||||
|
{
|
||||||
|
$this->assertEquals(sys_get_temp_dir(), Settings::getTempDir());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers ::setTempDir
|
||||||
|
* @covers ::getTempDir
|
||||||
|
* @depends testPhpTempDirIsUsedByDefault
|
||||||
|
* @test
|
||||||
|
*/
|
||||||
|
public function testTempDirCanBeSet()
|
||||||
|
{
|
||||||
|
$userDefinedTempDir = 'C:\PhpWordTemp';
|
||||||
|
Settings::setTempDir($userDefinedTempDir);
|
||||||
|
$currentTempDir = Settings::getTempDir();
|
||||||
|
$this->assertEquals($userDefinedTempDir, $currentTempDir);
|
||||||
|
$this->assertNotEquals(sys_get_temp_dir(), $currentTempDir);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test set/get default font name
|
* Test set/get default font name
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
|
|
@ -71,7 +71,7 @@ class DomPDFTest extends \PHPUnit_Framework_TestCase
|
||||||
$writer->setOrientation();
|
$writer->setOrientation();
|
||||||
$this->assertEquals('default', $writer->getOrientation());
|
$this->assertEquals('default', $writer->getOrientation());
|
||||||
|
|
||||||
$writer->setTempDir(sys_get_temp_dir());
|
$writer->setTempDir(Settings::getTempDir());
|
||||||
$this->assertEquals(sys_get_temp_dir(), $writer->getTempDir());
|
$this->assertEquals(Settings::getTempDir(), $writer->getTempDir());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -19,6 +19,7 @@ namespace PhpOffice\PhpWord\Tests;
|
||||||
|
|
||||||
use PhpOffice\PhpWord\IOFactory;
|
use PhpOffice\PhpWord\IOFactory;
|
||||||
use PhpOffice\PhpWord\PhpWord;
|
use PhpOffice\PhpWord\PhpWord;
|
||||||
|
use PhpOffice\PhpWord\Settings;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test helper class
|
* Test helper class
|
||||||
|
|
@ -41,9 +42,9 @@ class TestHelperDOCX
|
||||||
*/
|
*/
|
||||||
public static function getDocument(PhpWord $phpWord, $writerName = 'Word2007')
|
public static function getDocument(PhpWord $phpWord, $writerName = 'Word2007')
|
||||||
{
|
{
|
||||||
self::$file = tempnam(sys_get_temp_dir(), 'PhpWord');
|
self::$file = tempnam(Settings::getTempDir(), 'PhpWord');
|
||||||
if (!is_dir(sys_get_temp_dir() . '/PhpWord_Unit_Test/')) {
|
if (!is_dir(Settings::getTempDir() . '/PhpWord_Unit_Test/')) {
|
||||||
mkdir(sys_get_temp_dir() . '/PhpWord_Unit_Test/');
|
mkdir(Settings::getTempDir() . '/PhpWord_Unit_Test/');
|
||||||
}
|
}
|
||||||
|
|
||||||
$xmlWriter = IOFactory::createWriter($phpWord, $writerName);
|
$xmlWriter = IOFactory::createWriter($phpWord, $writerName);
|
||||||
|
|
@ -52,11 +53,11 @@ class TestHelperDOCX
|
||||||
$zip = new \ZipArchive;
|
$zip = new \ZipArchive;
|
||||||
$res = $zip->open(self::$file);
|
$res = $zip->open(self::$file);
|
||||||
if ($res === true) {
|
if ($res === true) {
|
||||||
$zip->extractTo(sys_get_temp_dir() . '/PhpWord_Unit_Test/');
|
$zip->extractTo(Settings::getTempDir() . '/PhpWord_Unit_Test/');
|
||||||
$zip->close();
|
$zip->close();
|
||||||
}
|
}
|
||||||
|
|
||||||
return new XmlDocument(sys_get_temp_dir() . '/PhpWord_Unit_Test/');
|
return new XmlDocument(Settings::getTempDir() . '/PhpWord_Unit_Test/');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -67,8 +68,8 @@ class TestHelperDOCX
|
||||||
if (file_exists(self::$file)) {
|
if (file_exists(self::$file)) {
|
||||||
unlink(self::$file);
|
unlink(self::$file);
|
||||||
}
|
}
|
||||||
if (is_dir(sys_get_temp_dir() . '/PhpWord_Unit_Test/')) {
|
if (is_dir(Settings::getTempDir() . '/PhpWord_Unit_Test/')) {
|
||||||
self::deleteDir(sys_get_temp_dir() . '/PhpWord_Unit_Test/');
|
self::deleteDir(Settings::getTempDir() . '/PhpWord_Unit_Test/');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue