Ability to define document protection and new `Metadata` subnamespace
This commit is contained in:
parent
6a81691d45
commit
384107e7cf
|
|
@ -18,6 +18,7 @@ This release added form fields (textinput, checkbox, and dropdown), drawing shap
|
||||||
- Chart: Basic 2D chart (pie, doughnut, bar, line, area, scatter, radar) - @ivanlanin GH-278
|
- Chart: Basic 2D chart (pie, doughnut, bar, line, area, scatter, radar) - @ivanlanin GH-278
|
||||||
- Chart: 3D charts and ability to set width and height - @ivanlanin
|
- Chart: 3D charts and ability to set width and height - @ivanlanin
|
||||||
- FormField: Ability to add textinput, checkbox, and dropdown form elements - @ivanlanin GH-266
|
- FormField: Ability to add textinput, checkbox, and dropdown form elements - @ivanlanin GH-266
|
||||||
|
- Security: Ability to define document protection (readOnly, comments, trackedChanges, forms) - @ivanlanin
|
||||||
|
|
||||||
### Bugfixes
|
### Bugfixes
|
||||||
|
|
||||||
|
|
@ -30,7 +31,7 @@ This release added form fields (textinput, checkbox, and dropdown), drawing shap
|
||||||
- `Element\Link::getTarget()` replaced by `Element\Link::getSource()`
|
- `Element\Link::getTarget()` replaced by `Element\Link::getSource()`
|
||||||
- `Element\Section::getSettings()` and `Element\Section::setSettings()` replaced by `Element\Section::getStyle()` and `Element\Section::setStyle()`
|
- `Element\Section::getSettings()` and `Element\Section::setSettings()` replaced by `Element\Section::getStyle()` and `Element\Section::setStyle()`
|
||||||
- `Shared\Drawing` and `Shared\Font` merged into `Shared\Converter`
|
- `Shared\Drawing` and `Shared\Font` merged into `Shared\Converter`
|
||||||
|
- `DocumentProperties` replaced by `Metadata\DocInfo`
|
||||||
|
|
||||||
### Miscellaneous
|
### Miscellaneous
|
||||||
|
|
||||||
|
|
|
||||||
13
README.md
13
README.md
|
|
@ -11,6 +11,17 @@ PHPWord is a library written in pure PHP that provides a set of classes to write
|
||||||
|
|
||||||
PHPWord is an open source project licensed under the terms of [LGPL version 3](https://github.com/PHPOffice/PHPWord/blob/develop/COPYING.LESSER). PHPWord is aimed to be a high quality software product by incorporating [continuous integration](https://travis-ci.org/PHPOffice/PHPWord) and [unit testing](http://phpoffice.github.io/PHPWord/coverage/develop/). You can learn more about PHPWord by reading the [Developers' Documentation](http://phpword.readthedocs.org/) and the [API Documentation](http://phpoffice.github.io/PHPWord/docs/develop/).
|
PHPWord is an open source project licensed under the terms of [LGPL version 3](https://github.com/PHPOffice/PHPWord/blob/develop/COPYING.LESSER). PHPWord is aimed to be a high quality software product by incorporating [continuous integration](https://travis-ci.org/PHPOffice/PHPWord) and [unit testing](http://phpoffice.github.io/PHPWord/coverage/develop/). You can learn more about PHPWord by reading the [Developers' Documentation](http://phpword.readthedocs.org/) and the [API Documentation](http://phpoffice.github.io/PHPWord/docs/develop/).
|
||||||
|
|
||||||
|
Read more about PHPWord:
|
||||||
|
|
||||||
|
- [Features](#features)
|
||||||
|
- [Requirements](#requirements)
|
||||||
|
- [Installation](#installation)
|
||||||
|
- [Getting started](#getting-started)
|
||||||
|
- [Known issues](#known-issues)
|
||||||
|
- [Contributing](#contributing)
|
||||||
|
- [Developers' Documentation](http://phpword.readthedocs.org/)
|
||||||
|
- [API Documentation](http://phpoffice.github.io/PHPWord/docs/master/)
|
||||||
|
|
||||||
## Features
|
## Features
|
||||||
|
|
||||||
With PHPWord, you can create DOCX, ODT, or RTF documents dynamically using your PHP 5.3+ scripts. Below are some of the things that you can do with PHPWord library:
|
With PHPWord, you can create DOCX, ODT, or RTF documents dynamically using your PHP 5.3+ scripts. Below are some of the things that you can do with PHPWord library:
|
||||||
|
|
@ -113,7 +124,7 @@ $phpWord->save('helloWorld.odt', 'ODText');
|
||||||
$phpWord->save('helloWorld.rtf', 'RTF');
|
$phpWord->save('helloWorld.rtf', 'RTF');
|
||||||
```
|
```
|
||||||
|
|
||||||
More examples are provided in the [samples folder](samples/). You can also read the [Developers' Documentation](http://phpword.readthedocs.org/) and the [API Documentation](http://phpoffice.github.io/PHPWord/docs/develop/) for more detail.
|
More examples are provided in the [samples folder](samples/). You can also read the [Developers' Documentation](http://phpword.readthedocs.org/) and the [API Documentation](http://phpoffice.github.io/PHPWord/docs/master/) for more detail.
|
||||||
|
|
||||||
## Known issues
|
## Known issues
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -97,15 +97,15 @@ default font by using the following two functions:
|
||||||
$phpWord->setDefaultFontName('Times New Roman');
|
$phpWord->setDefaultFontName('Times New Roman');
|
||||||
$phpWord->setDefaultFontSize(12);
|
$phpWord->setDefaultFontSize(12);
|
||||||
|
|
||||||
Document properties
|
Document information
|
||||||
-------------------
|
--------------------
|
||||||
|
|
||||||
You can set the document properties such as title, creator, and company
|
You can set the document information such as title, creator, and company
|
||||||
name. Use the following functions:
|
name. Use the following functions:
|
||||||
|
|
||||||
.. code-block:: php
|
.. code-block:: php
|
||||||
|
|
||||||
$properties = $phpWord->getDocumentProperties();
|
$properties = $phpWord->getDocInfo();
|
||||||
$properties->setCreator('My name');
|
$properties->setCreator('My name');
|
||||||
$properties->setCompany('My factory');
|
$properties->setCompany('My factory');
|
||||||
$properties->setTitle('My title');
|
$properties->setTitle('My title');
|
||||||
|
|
|
||||||
|
|
@ -279,12 +279,12 @@ $phpWord->setDefaultFontName('Times New Roman');
|
||||||
$phpWord->setDefaultFontSize(12);
|
$phpWord->setDefaultFontSize(12);
|
||||||
```
|
```
|
||||||
|
|
||||||
## Document properties
|
## Document information
|
||||||
|
|
||||||
You can set the document properties such as title, creator, and company name. Use the following functions:
|
You can set the document information such as title, creator, and company name. Use the following functions:
|
||||||
|
|
||||||
```php
|
```php
|
||||||
$properties = $phpWord->getDocumentProperties();
|
$properties = $phpWord->getDocInfo();
|
||||||
$properties->setCreator('My name');
|
$properties->setCreator('My name');
|
||||||
$properties->setCompany('My factory');
|
$properties->setCompany('My factory');
|
||||||
$properties->setTitle('My title');
|
$properties->setTitle('My title');
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ include_once 'Sample_Header.php';
|
||||||
// New Word document
|
// New Word document
|
||||||
echo date('H:i:s'), " Create new PhpWord object", EOL;
|
echo date('H:i:s'), " Create new PhpWord object", EOL;
|
||||||
$phpWord = new \PhpOffice\PhpWord\PhpWord();
|
$phpWord = new \PhpOffice\PhpWord\PhpWord();
|
||||||
|
$phpWord->getProtection()->setEditing('forms');
|
||||||
|
|
||||||
$section = $phpWord->addSection();
|
$section = $phpWord->addSection();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -142,7 +142,7 @@ function getEndingNotes($writers)
|
||||||
</ul>
|
</ul>
|
||||||
<ul class="nav navbar-nav navbar-right">
|
<ul class="nav navbar-nav navbar-right">
|
||||||
<li><a href="https://github.com/PHPOffice/PHPWord"><i class="fa fa-github fa-lg" title="GitHub"></i> </a></li>
|
<li><a href="https://github.com/PHPOffice/PHPWord"><i class="fa fa-github fa-lg" title="GitHub"></i> </a></li>
|
||||||
<li><a href="http://phpword.readthedocs.org/en/develop/"><i class="fa fa-book fa-lg" title="Docs"></i> </a></li>
|
<li><a href="http://phpword.readthedocs.org/"><i class="fa fa-book fa-lg" title="Docs"></i> </a></li>
|
||||||
<li><a href="http://twitter.com/PHPWord"><i class="fa fa-twitter fa-lg" title="Twitter"></i> </a></li>
|
<li><a href="http://twitter.com/PHPWord"><i class="fa fa-twitter fa-lg" title="Twitter"></i> </a></li>
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,7 @@ if (!CLI) {
|
||||||
<p> </p>
|
<p> </p>
|
||||||
<p>
|
<p>
|
||||||
<a class="btn btn-lg btn-primary" href="https://github.com/PHPOffice/PHPWord" role="button"><i class="fa fa-github fa-lg" title="GitHub"></i> Fork us on Github!</a>
|
<a class="btn btn-lg btn-primary" href="https://github.com/PHPOffice/PHPWord" role="button"><i class="fa fa-github fa-lg" title="GitHub"></i> Fork us on Github!</a>
|
||||||
<a class="btn btn-lg btn-primary" href="http://phpword.readthedocs.org/en/develop/" role="button"><i class="fa fa-book fa-lg" title="Docs"></i> Read the Docs</a>
|
<a class="btn btn-lg btn-primary" href="http://phpword.readthedocs.org/" role="button"><i class="fa fa-book fa-lg" title="Docs"></i> Read the Docs</a>
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
<?php
|
<?php
|
||||||
|
|
|
||||||
|
|
@ -15,12 +15,12 @@
|
||||||
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
|
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace PhpOffice\PhpWord;
|
namespace PhpOffice\PhpWord\Metadata;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Document properties
|
* Document information
|
||||||
*/
|
*/
|
||||||
class DocumentProperties
|
class DocInfo
|
||||||
{
|
{
|
||||||
/** @const string Property type constants */
|
/** @const string Property type constants */
|
||||||
const PROPERTY_TYPE_BOOLEAN = 'b';
|
const PROPERTY_TYPE_BOOLEAN = 'b';
|
||||||
|
|
@ -115,7 +115,7 @@ class DocumentProperties
|
||||||
private $customProperties = array();
|
private $customProperties = array();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create new DocumentProperties
|
* Create new instance
|
||||||
*/
|
*/
|
||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
|
|
@ -0,0 +1,69 @@
|
||||||
|
<?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.
|
||||||
|
*
|
||||||
|
* @link https://github.com/PHPOffice/PHPWord
|
||||||
|
* @copyright 2010-2014 PHPWord contributors
|
||||||
|
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace PhpOffice\PhpWord\Metadata;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Document protection class
|
||||||
|
*
|
||||||
|
* @since 0.12.0
|
||||||
|
* @link http://www.datypic.com/sc/ooxml/t-w_CT_DocProtect.html
|
||||||
|
* @todo Password!
|
||||||
|
*/
|
||||||
|
class Protection
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Editing restriction readOnly|comments|trackedChanges|forms
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
* @link http://www.datypic.com/sc/ooxml/a-w_edit-1.html
|
||||||
|
*/
|
||||||
|
private $editing;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new instance
|
||||||
|
*
|
||||||
|
* @param string $editing
|
||||||
|
*/
|
||||||
|
public function __construct($editing = null)
|
||||||
|
{
|
||||||
|
$this->setEditing($editing);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get editing protection
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getEditing()
|
||||||
|
{
|
||||||
|
return $this->editing;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set editing protection
|
||||||
|
*
|
||||||
|
* @param string $editing
|
||||||
|
* @return self
|
||||||
|
*/
|
||||||
|
public function setEditing($editing = null)
|
||||||
|
{
|
||||||
|
$this->editing = $editing;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -52,13 +52,6 @@ class PhpWord
|
||||||
const DEFAULT_FONT_COLOR = Settings::DEFAULT_FONT_COLOR;
|
const DEFAULT_FONT_COLOR = Settings::DEFAULT_FONT_COLOR;
|
||||||
const DEFAULT_FONT_CONTENT_TYPE = Settings::DEFAULT_FONT_CONTENT_TYPE;
|
const DEFAULT_FONT_CONTENT_TYPE = Settings::DEFAULT_FONT_CONTENT_TYPE;
|
||||||
|
|
||||||
/**
|
|
||||||
* Document properties object
|
|
||||||
*
|
|
||||||
* @var DocumentProperties
|
|
||||||
*/
|
|
||||||
private $documentProperties;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Collection of sections
|
* Collection of sections
|
||||||
*
|
*
|
||||||
|
|
@ -73,6 +66,14 @@ class PhpWord
|
||||||
*/
|
*/
|
||||||
private $collections = array();
|
private $collections = array();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Metadata
|
||||||
|
*
|
||||||
|
* @var array
|
||||||
|
* @since 0.12.0
|
||||||
|
*/
|
||||||
|
private $metadata = array();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create new instance
|
* Create new instance
|
||||||
*
|
*
|
||||||
|
|
@ -80,13 +81,17 @@ class PhpWord
|
||||||
*/
|
*/
|
||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
$this->documentProperties = new DocumentProperties();
|
|
||||||
|
|
||||||
$collections = array('Titles', 'Footnotes', 'Endnotes', 'Charts');
|
$collections = array('Titles', 'Footnotes', 'Endnotes', 'Charts');
|
||||||
foreach ($collections as $collection) {
|
foreach ($collections as $collection) {
|
||||||
$class = 'PhpOffice\\PhpWord\\Collection\\' . $collection;
|
$class = 'PhpOffice\\PhpWord\\Collection\\' . $collection;
|
||||||
$this->collections[$collection] = new $class();
|
$this->collections[$collection] = new $class();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$metadata = 'PhpOffice\\PhpWord\\Metadata\\Protection';
|
||||||
|
$this->metadata['Protection'] = new $metadata();
|
||||||
|
|
||||||
|
$metadata = 'PhpOffice\\PhpWord\\Metadata\\DocInfo';
|
||||||
|
$this->metadata['DocInfo'] = new $metadata();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -150,24 +155,22 @@ class PhpWord
|
||||||
/**
|
/**
|
||||||
* Get document properties object
|
* Get document properties object
|
||||||
*
|
*
|
||||||
* @return DocumentProperties
|
* @return \PhpOffice\PhpWord\Metadata\DocInfo
|
||||||
*/
|
*/
|
||||||
public function getDocumentProperties()
|
public function getDocInfo()
|
||||||
{
|
{
|
||||||
return $this->documentProperties;
|
return $this->metadata['DocInfo'];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set document properties object
|
* Get protection
|
||||||
*
|
*
|
||||||
* @param DocumentProperties $documentProperties
|
* @return \PhpOffice\PhpWord\Metadata\Protection
|
||||||
* @return self
|
* @since 0.12.0
|
||||||
*/
|
*/
|
||||||
public function setDocumentProperties(DocumentProperties $documentProperties)
|
public function getProtection()
|
||||||
{
|
{
|
||||||
$this->documentProperties = $documentProperties;
|
return $this->metadata['Protection'];
|
||||||
|
|
||||||
return $this;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -312,4 +315,31 @@ class PhpWord
|
||||||
{
|
{
|
||||||
return $this->addSection($settings);
|
return $this->addSection($settings);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get document properties object
|
||||||
|
*
|
||||||
|
* @return \PhpOffice\PhpWord\Metadata\DocInfo
|
||||||
|
* @deprecated 0.12.0
|
||||||
|
* @codeCoverageIgnore
|
||||||
|
*/
|
||||||
|
public function getDocumentProperties()
|
||||||
|
{
|
||||||
|
return $this->getDocInfo();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set document properties object
|
||||||
|
*
|
||||||
|
* @param \PhpOffice\PhpWord\Metadata\DocInfo
|
||||||
|
* @return self
|
||||||
|
* @deprecated 0.12.0
|
||||||
|
* @codeCoverageIgnore
|
||||||
|
*/
|
||||||
|
public function setDocumentProperties($documentProperties)
|
||||||
|
{
|
||||||
|
$this->metadata['Document'] = $documentProperties;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -37,7 +37,7 @@ class Meta extends AbstractPart
|
||||||
{
|
{
|
||||||
$xmlReader = new XMLReader();
|
$xmlReader = new XMLReader();
|
||||||
$xmlReader->getDomFromZip($this->docFile, $this->xmlFile);
|
$xmlReader->getDomFromZip($this->docFile, $this->xmlFile);
|
||||||
$docProps = $phpWord->getDocumentProperties();
|
$docProps = $phpWord->getDocInfo();
|
||||||
|
|
||||||
$metaNode = $xmlReader->getElement('office:meta');
|
$metaNode = $xmlReader->getElement('office:meta');
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -61,7 +61,7 @@ class DocPropsCore extends AbstractPart
|
||||||
$xmlReader = new XMLReader();
|
$xmlReader = new XMLReader();
|
||||||
$xmlReader->getDomFromZip($this->docFile, $this->xmlFile);
|
$xmlReader->getDomFromZip($this->docFile, $this->xmlFile);
|
||||||
|
|
||||||
$docProps = $phpWord->getDocumentProperties();
|
$docProps = $phpWord->getDocInfo();
|
||||||
|
|
||||||
$nodes = $xmlReader->getElements('*');
|
$nodes = $xmlReader->getElements('*');
|
||||||
if ($nodes->length > 0) {
|
if ($nodes->length > 0) {
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,7 @@
|
||||||
|
|
||||||
namespace PhpOffice\PhpWord\Reader\Word2007;
|
namespace PhpOffice\PhpWord\Reader\Word2007;
|
||||||
|
|
||||||
use PhpOffice\PhpWord\DocumentProperties;
|
use PhpOffice\PhpWord\Metadata\DocInfo;
|
||||||
use PhpOffice\PhpWord\PhpWord;
|
use PhpOffice\PhpWord\PhpWord;
|
||||||
use PhpOffice\PhpWord\Shared\XMLReader;
|
use PhpOffice\PhpWord\Shared\XMLReader;
|
||||||
|
|
||||||
|
|
@ -37,7 +37,7 @@ class DocPropsCustom extends AbstractPart
|
||||||
{
|
{
|
||||||
$xmlReader = new XMLReader();
|
$xmlReader = new XMLReader();
|
||||||
$xmlReader->getDomFromZip($this->docFile, $this->xmlFile);
|
$xmlReader->getDomFromZip($this->docFile, $this->xmlFile);
|
||||||
$docProps = $phpWord->getDocumentProperties();
|
$docProps = $phpWord->getDocInfo();
|
||||||
|
|
||||||
$nodes = $xmlReader->getElements('*');
|
$nodes = $xmlReader->getElements('*');
|
||||||
if ($nodes->length > 0) {
|
if ($nodes->length > 0) {
|
||||||
|
|
@ -46,8 +46,8 @@ class DocPropsCustom extends AbstractPart
|
||||||
$attributeNode = $xmlReader->getElement('*', $node);
|
$attributeNode = $xmlReader->getElement('*', $node);
|
||||||
$attributeType = $attributeNode->nodeName;
|
$attributeType = $attributeNode->nodeName;
|
||||||
$attributeValue = $attributeNode->nodeValue;
|
$attributeValue = $attributeNode->nodeValue;
|
||||||
$attributeValue = DocumentProperties::convertProperty($attributeValue, $attributeType);
|
$attributeValue = DocInfo::convertProperty($attributeValue, $attributeType);
|
||||||
$attributeType = DocumentProperties::convertPropertyType($attributeType);
|
$attributeType = DocInfo::convertPropertyType($attributeType);
|
||||||
$docProps->setCustomProperty($propertyName, $attributeValue, $attributeType);
|
$docProps->setCustomProperty($propertyName, $attributeValue, $attributeType);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -39,7 +39,7 @@ class Head extends AbstractPart
|
||||||
*/
|
*/
|
||||||
public function write()
|
public function write()
|
||||||
{
|
{
|
||||||
$docProps = $this->getParentWriter()->getPhpWord()->getDocumentProperties();
|
$docProps = $this->getParentWriter()->getPhpWord()->getDocInfo();
|
||||||
$propertiesMapping = array(
|
$propertiesMapping = array(
|
||||||
'creator' => 'author',
|
'creator' => 'author',
|
||||||
'title' => '',
|
'title' => '',
|
||||||
|
|
|
||||||
|
|
@ -34,7 +34,7 @@ class Meta extends AbstractPart
|
||||||
public function write()
|
public function write()
|
||||||
{
|
{
|
||||||
$phpWord = $this->getParentWriter()->getPhpWord();
|
$phpWord = $this->getParentWriter()->getPhpWord();
|
||||||
$docProps = $phpWord->getDocumentProperties();
|
$docProps = $phpWord->getDocInfo();
|
||||||
$xmlWriter = $this->getXmlWriter();
|
$xmlWriter = $this->getXmlWriter();
|
||||||
|
|
||||||
$xmlWriter->startDocument('1.0', 'UTF-8');
|
$xmlWriter->startDocument('1.0', 'UTF-8');
|
||||||
|
|
|
||||||
|
|
@ -54,7 +54,7 @@ class MPDF extends AbstractRenderer implements WriterInterface
|
||||||
|
|
||||||
// Write document properties
|
// Write document properties
|
||||||
$phpWord = $this->getPhpWord();
|
$phpWord = $this->getPhpWord();
|
||||||
$docProps = $phpWord->getDocumentProperties();
|
$docProps = $phpWord->getDocInfo();
|
||||||
$pdf->setTitle($docProps->getTitle());
|
$pdf->setTitle($docProps->getTitle());
|
||||||
$pdf->setAuthor($docProps->getCreator());
|
$pdf->setAuthor($docProps->getCreator());
|
||||||
$pdf->setSubject($docProps->getSubject());
|
$pdf->setSubject($docProps->getSubject());
|
||||||
|
|
|
||||||
|
|
@ -58,7 +58,7 @@ class TCPDF extends AbstractRenderer implements WriterInterface
|
||||||
|
|
||||||
// Write document properties
|
// Write document properties
|
||||||
$phpWord = $this->getPhpWord();
|
$phpWord = $this->getPhpWord();
|
||||||
$docProps = $phpWord->getDocumentProperties();
|
$docProps = $phpWord->getDocInfo();
|
||||||
$pdf->setTitle($docProps->getTitle());
|
$pdf->setTitle($docProps->getTitle());
|
||||||
$pdf->setAuthor($docProps->getCreator());
|
$pdf->setAuthor($docProps->getCreator());
|
||||||
$pdf->setSubject($docProps->getSubject());
|
$pdf->setSubject($docProps->getSubject());
|
||||||
|
|
|
||||||
|
|
@ -52,7 +52,7 @@ class Document extends AbstractPart
|
||||||
*/
|
*/
|
||||||
private function writeInfo()
|
private function writeInfo()
|
||||||
{
|
{
|
||||||
$docProps = $this->getParentWriter()->getPhpWord()->getDocumentProperties();
|
$docProps = $this->getParentWriter()->getPhpWord()->getDocInfo();
|
||||||
$properties = array('title', 'subject', 'category', 'keywords', 'comment',
|
$properties = array('title', 'subject', 'category', 'keywords', 'comment',
|
||||||
'author', 'operator', 'creatim', 'revtim', 'company', 'manager');
|
'author', 'operator', 'creatim', 'revtim', 'company', 'manager');
|
||||||
$mapping = array('comment' => 'description', 'author' => 'creator', 'operator' => 'lastModifiedBy',
|
$mapping = array('comment' => 'description', 'author' => 'creator', 'operator' => 'lastModifiedBy',
|
||||||
|
|
|
||||||
|
|
@ -41,8 +41,8 @@ class DocPropsApp extends AbstractPart
|
||||||
$xmlWriter->writeAttribute('xmlns:vt', 'http://schemas.openxmlformats.org/officeDocument/2006/docPropsVTypes');
|
$xmlWriter->writeAttribute('xmlns:vt', 'http://schemas.openxmlformats.org/officeDocument/2006/docPropsVTypes');
|
||||||
|
|
||||||
$xmlWriter->writeElement('Application', 'PHPWord');
|
$xmlWriter->writeElement('Application', 'PHPWord');
|
||||||
$xmlWriter->writeElement('Company', $phpWord->getDocumentProperties()->getCompany());
|
$xmlWriter->writeElement('Company', $phpWord->getDocInfo()->getCompany());
|
||||||
$xmlWriter->writeElement('Manager', $phpWord->getDocumentProperties()->getManager());
|
$xmlWriter->writeElement('Manager', $phpWord->getDocInfo()->getManager());
|
||||||
|
|
||||||
$xmlWriter->endElement(); // Properties
|
$xmlWriter->endElement(); // Properties
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -43,24 +43,24 @@ class DocPropsCore extends AbstractPart
|
||||||
$xmlWriter->writeAttribute('xmlns:dcmitype', 'http://purl.org/dc/dcmitype/');
|
$xmlWriter->writeAttribute('xmlns:dcmitype', 'http://purl.org/dc/dcmitype/');
|
||||||
$xmlWriter->writeAttribute('xmlns:xsi', 'http://www.w3.org/2001/XMLSchema-instance');
|
$xmlWriter->writeAttribute('xmlns:xsi', 'http://www.w3.org/2001/XMLSchema-instance');
|
||||||
|
|
||||||
$xmlWriter->writeElement('dc:creator', $phpWord->getDocumentProperties()->getCreator());
|
$xmlWriter->writeElement('dc:creator', $phpWord->getDocInfo()->getCreator());
|
||||||
$xmlWriter->writeElement('dc:title', $phpWord->getDocumentProperties()->getTitle());
|
$xmlWriter->writeElement('dc:title', $phpWord->getDocInfo()->getTitle());
|
||||||
$xmlWriter->writeElement('dc:description', $phpWord->getDocumentProperties()->getDescription());
|
$xmlWriter->writeElement('dc:description', $phpWord->getDocInfo()->getDescription());
|
||||||
$xmlWriter->writeElement('dc:subject', $phpWord->getDocumentProperties()->getSubject());
|
$xmlWriter->writeElement('dc:subject', $phpWord->getDocInfo()->getSubject());
|
||||||
$xmlWriter->writeElement('cp:keywords', $phpWord->getDocumentProperties()->getKeywords());
|
$xmlWriter->writeElement('cp:keywords', $phpWord->getDocInfo()->getKeywords());
|
||||||
$xmlWriter->writeElement('cp:category', $phpWord->getDocumentProperties()->getCategory());
|
$xmlWriter->writeElement('cp:category', $phpWord->getDocInfo()->getCategory());
|
||||||
$xmlWriter->writeElement('cp:lastModifiedBy', $phpWord->getDocumentProperties()->getLastModifiedBy());
|
$xmlWriter->writeElement('cp:lastModifiedBy', $phpWord->getDocInfo()->getLastModifiedBy());
|
||||||
|
|
||||||
// dcterms:created
|
// dcterms:created
|
||||||
$xmlWriter->startElement('dcterms:created');
|
$xmlWriter->startElement('dcterms:created');
|
||||||
$xmlWriter->writeAttribute('xsi:type', 'dcterms:W3CDTF');
|
$xmlWriter->writeAttribute('xsi:type', 'dcterms:W3CDTF');
|
||||||
$xmlWriter->writeRaw(date($this->dateFormat, $phpWord->getDocumentProperties()->getCreated()));
|
$xmlWriter->writeRaw(date($this->dateFormat, $phpWord->getDocInfo()->getCreated()));
|
||||||
$xmlWriter->endElement();
|
$xmlWriter->endElement();
|
||||||
|
|
||||||
// dcterms:modified
|
// dcterms:modified
|
||||||
$xmlWriter->startElement('dcterms:modified');
|
$xmlWriter->startElement('dcterms:modified');
|
||||||
$xmlWriter->writeAttribute('xsi:type', 'dcterms:W3CDTF');
|
$xmlWriter->writeAttribute('xsi:type', 'dcterms:W3CDTF');
|
||||||
$xmlWriter->writeRaw(date($this->dateFormat, $phpWord->getDocumentProperties()->getModified()));
|
$xmlWriter->writeRaw(date($this->dateFormat, $phpWord->getDocInfo()->getModified()));
|
||||||
$xmlWriter->endElement();
|
$xmlWriter->endElement();
|
||||||
|
|
||||||
$xmlWriter->endElement(); // cp:coreProperties
|
$xmlWriter->endElement(); // cp:coreProperties
|
||||||
|
|
|
||||||
|
|
@ -39,7 +39,7 @@ class DocPropsCustom extends AbstractPart
|
||||||
$xmlWriter->writeAttribute('xmlns', 'http://schemas.openxmlformats.org/officeDocument/2006/custom-properties');
|
$xmlWriter->writeAttribute('xmlns', 'http://schemas.openxmlformats.org/officeDocument/2006/custom-properties');
|
||||||
$xmlWriter->writeAttribute('xmlns:vt', 'http://schemas.openxmlformats.org/officeDocument/2006/docPropsVTypes');
|
$xmlWriter->writeAttribute('xmlns:vt', 'http://schemas.openxmlformats.org/officeDocument/2006/docPropsVTypes');
|
||||||
|
|
||||||
$docProps = $phpWord->getDocumentProperties();
|
$docProps = $phpWord->getDocInfo();
|
||||||
$properties = $docProps->getCustomProperties();
|
$properties = $docProps->getCustomProperties();
|
||||||
foreach ($properties as $key => $property) {
|
foreach ($properties as $key => $property) {
|
||||||
$propertyValue = $docProps->getCustomPropertyValue($property);
|
$propertyValue = $docProps->getCustomPropertyValue($property);
|
||||||
|
|
|
||||||
|
|
@ -31,8 +31,91 @@ class Settings extends AbstractPart
|
||||||
*/
|
*/
|
||||||
public function write()
|
public function write()
|
||||||
{
|
{
|
||||||
$settings = array(
|
$settings = $this->getSettings();
|
||||||
|
|
||||||
|
$xmlWriter = $this->getXmlWriter();
|
||||||
|
|
||||||
|
$xmlWriter->startDocument('1.0', 'UTF-8', 'yes');
|
||||||
|
$xmlWriter->startElement('w:settings');
|
||||||
|
$xmlWriter->writeAttribute('xmlns:r', 'http://schemas.openxmlformats.org/officeDocument/2006/relationships');
|
||||||
|
$xmlWriter->writeAttribute('xmlns:w', 'http://schemas.openxmlformats.org/wordprocessingml/2006/main');
|
||||||
|
$xmlWriter->writeAttribute('xmlns:m', 'http://schemas.openxmlformats.org/officeDocument/2006/math');
|
||||||
|
$xmlWriter->writeAttribute('xmlns:sl', 'http://schemas.openxmlformats.org/schemaLibrary/2006/main');
|
||||||
|
$xmlWriter->writeAttribute('xmlns:o', 'urn:schemas-microsoft-com:office:office');
|
||||||
|
$xmlWriter->writeAttribute('xmlns:v', 'urn:schemas-microsoft-com:vml');
|
||||||
|
$xmlWriter->writeAttribute('xmlns:w10', 'urn:schemas-microsoft-com:office:word');
|
||||||
|
|
||||||
|
foreach ($settings as $settingKey => $settingValue) {
|
||||||
|
$this->writeSetting($xmlWriter, $settingKey, $settingValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
$xmlWriter->endElement(); // w:settings
|
||||||
|
|
||||||
|
return $xmlWriter->getData();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Write indivual setting, recursive to any child settings
|
||||||
|
*
|
||||||
|
* @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter
|
||||||
|
* @param string $settingKey
|
||||||
|
* @param array|string $settingValue
|
||||||
|
*/
|
||||||
|
protected function writeSetting($xmlWriter, $settingKey, $settingValue)
|
||||||
|
{
|
||||||
|
if ($settingValue == '') {
|
||||||
|
$xmlWriter->writeElement($settingKey);
|
||||||
|
} else {
|
||||||
|
$xmlWriter->startElement($settingKey);
|
||||||
|
|
||||||
|
/** @var array $settingValue Type hint */
|
||||||
|
foreach ($settingValue as $childKey => $childValue) {
|
||||||
|
if ($childKey == '@attributes') {
|
||||||
|
foreach ($childValue as $key => $val) {
|
||||||
|
$xmlWriter->writeAttribute($key, $val);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$this->writeSetting($xmlWriter, $childKey, $childValue);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$xmlWriter->endElement();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get settings
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
private function getSettings()
|
||||||
|
{
|
||||||
|
// Default settings
|
||||||
|
$settings = $this->getDefaultSettings();
|
||||||
|
|
||||||
|
// Protection
|
||||||
|
$protection = $this->getParentWriter()->getPhpWord()->getProtection();
|
||||||
|
if ($protection->getEditing() !== null) {
|
||||||
|
$settings['w:documentProtection'] = array(
|
||||||
|
'@attributes' => array(
|
||||||
|
'w:enforcement' => 1,
|
||||||
|
'w:edit' => $protection->getEditing(),
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $settings;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get default settings
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
private function getDefaultSettings()
|
||||||
|
{
|
||||||
|
return array(
|
||||||
'w:zoom' => array('@attributes' => array('w:percent' => '100')),
|
'w:zoom' => array('@attributes' => array('w:percent' => '100')),
|
||||||
|
'w:view' => array('@attributes' => array('w:val' => 'print')),
|
||||||
'w:embedSystemFonts' => '',
|
'w:embedSystemFonts' => '',
|
||||||
'w:defaultTabStop' => array('@attributes' => array('w:val' => '708')),
|
'w:defaultTabStop' => array('@attributes' => array('w:val' => '708')),
|
||||||
'w:hyphenationZone' => array('@attributes' => array('w:val' => '425')),
|
'w:hyphenationZone' => array('@attributes' => array('w:val' => '425')),
|
||||||
|
|
@ -94,53 +177,5 @@ class Settings extends AbstractPart
|
||||||
'w:decimalSymbol' => array('@attributes' => array('w:val' => ',')),
|
'w:decimalSymbol' => array('@attributes' => array('w:val' => ',')),
|
||||||
'w:listSeparator' => array('@attributes' => array('w:val' => ';')),
|
'w:listSeparator' => array('@attributes' => array('w:val' => ';')),
|
||||||
);
|
);
|
||||||
|
|
||||||
$xmlWriter = $this->getXmlWriter();
|
|
||||||
|
|
||||||
$xmlWriter->startDocument('1.0', 'UTF-8', 'yes');
|
|
||||||
$xmlWriter->startElement('w:settings');
|
|
||||||
$xmlWriter->writeAttribute('xmlns:r', 'http://schemas.openxmlformats.org/officeDocument/2006/relationships');
|
|
||||||
$xmlWriter->writeAttribute('xmlns:w', 'http://schemas.openxmlformats.org/wordprocessingml/2006/main');
|
|
||||||
$xmlWriter->writeAttribute('xmlns:m', 'http://schemas.openxmlformats.org/officeDocument/2006/math');
|
|
||||||
$xmlWriter->writeAttribute('xmlns:sl', 'http://schemas.openxmlformats.org/schemaLibrary/2006/main');
|
|
||||||
$xmlWriter->writeAttribute('xmlns:o', 'urn:schemas-microsoft-com:office:office');
|
|
||||||
$xmlWriter->writeAttribute('xmlns:v', 'urn:schemas-microsoft-com:vml');
|
|
||||||
$xmlWriter->writeAttribute('xmlns:w10', 'urn:schemas-microsoft-com:office:word');
|
|
||||||
|
|
||||||
foreach ($settings as $settingKey => $settingValue) {
|
|
||||||
$this->writeSetting($xmlWriter, $settingKey, $settingValue);
|
|
||||||
}
|
|
||||||
|
|
||||||
$xmlWriter->endElement(); // w:settings
|
|
||||||
|
|
||||||
return $xmlWriter->getData();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Write indivual setting, recursive to any child settings
|
|
||||||
*
|
|
||||||
* @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter
|
|
||||||
* @param string $settingKey
|
|
||||||
* @param array|string $settingValue
|
|
||||||
*/
|
|
||||||
protected function writeSetting($xmlWriter, $settingKey, $settingValue)
|
|
||||||
{
|
|
||||||
if ($settingValue == '') {
|
|
||||||
$xmlWriter->writeElement($settingKey);
|
|
||||||
} else {
|
|
||||||
$xmlWriter->startElement($settingKey);
|
|
||||||
|
|
||||||
/** @var array $settingValue Type hint */
|
|
||||||
foreach ($settingValue as $childKey => $childValue) {
|
|
||||||
if ($childKey == '@attributes') {
|
|
||||||
foreach ($childValue as $key => $val) {
|
|
||||||
$xmlWriter->writeAttribute($key, $val);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
$this->writeSetting($xmlWriter, $childKey, $childValue);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$xmlWriter->endElement();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -15,23 +15,23 @@
|
||||||
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
|
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace PhpOffice\PhpWord\Tests;
|
namespace PhpOffice\PhpWord\Tests\Metadata;
|
||||||
|
|
||||||
use PhpOffice\PhpWord\DocumentProperties;
|
use PhpOffice\PhpWord\Metadata\DocInfo;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test class for PhpOffice\PhpWord\DocumentProperties
|
* Test class for PhpOffice\PhpWord\Metadata\DocInfo
|
||||||
*
|
*
|
||||||
* @runTestsInSeparateProcesses
|
* @runTestsInSeparateProcesses
|
||||||
*/
|
*/
|
||||||
class DocumentPropertiesTest extends \PHPUnit_Framework_TestCase
|
class DocInfoTest extends \PHPUnit_Framework_TestCase
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Creator
|
* Creator
|
||||||
*/
|
*/
|
||||||
public function testCreator()
|
public function testCreator()
|
||||||
{
|
{
|
||||||
$oProperties = new DocumentProperties();
|
$oProperties = new DocInfo();
|
||||||
$oProperties->setCreator();
|
$oProperties->setCreator();
|
||||||
$this->assertEquals('', $oProperties->getCreator());
|
$this->assertEquals('', $oProperties->getCreator());
|
||||||
|
|
||||||
|
|
@ -44,7 +44,7 @@ class DocumentPropertiesTest extends \PHPUnit_Framework_TestCase
|
||||||
*/
|
*/
|
||||||
public function testLastModifiedBy()
|
public function testLastModifiedBy()
|
||||||
{
|
{
|
||||||
$oProperties = new DocumentProperties();
|
$oProperties = new DocInfo();
|
||||||
$oProperties->setLastModifiedBy();
|
$oProperties->setLastModifiedBy();
|
||||||
$this->assertEquals('', $oProperties->getLastModifiedBy());
|
$this->assertEquals('', $oProperties->getLastModifiedBy());
|
||||||
|
|
||||||
|
|
@ -57,7 +57,7 @@ class DocumentPropertiesTest extends \PHPUnit_Framework_TestCase
|
||||||
*/
|
*/
|
||||||
public function testCreated()
|
public function testCreated()
|
||||||
{
|
{
|
||||||
$oProperties = new DocumentProperties();
|
$oProperties = new DocInfo();
|
||||||
$oProperties->setCreated();
|
$oProperties->setCreated();
|
||||||
$this->assertEquals(time(), $oProperties->getCreated());
|
$this->assertEquals(time(), $oProperties->getCreated());
|
||||||
|
|
||||||
|
|
@ -71,7 +71,7 @@ class DocumentPropertiesTest extends \PHPUnit_Framework_TestCase
|
||||||
*/
|
*/
|
||||||
public function testModified()
|
public function testModified()
|
||||||
{
|
{
|
||||||
$oProperties = new DocumentProperties();
|
$oProperties = new DocInfo();
|
||||||
$oProperties->setModified();
|
$oProperties->setModified();
|
||||||
$this->assertEquals(time(), $oProperties->getModified());
|
$this->assertEquals(time(), $oProperties->getModified());
|
||||||
|
|
||||||
|
|
@ -85,7 +85,7 @@ class DocumentPropertiesTest extends \PHPUnit_Framework_TestCase
|
||||||
*/
|
*/
|
||||||
public function testTitle()
|
public function testTitle()
|
||||||
{
|
{
|
||||||
$oProperties = new DocumentProperties();
|
$oProperties = new DocInfo();
|
||||||
$oProperties->setTitle();
|
$oProperties->setTitle();
|
||||||
$this->assertEquals('', $oProperties->getTitle());
|
$this->assertEquals('', $oProperties->getTitle());
|
||||||
|
|
||||||
|
|
@ -98,7 +98,7 @@ class DocumentPropertiesTest extends \PHPUnit_Framework_TestCase
|
||||||
*/
|
*/
|
||||||
public function testDescription()
|
public function testDescription()
|
||||||
{
|
{
|
||||||
$oProperties = new DocumentProperties();
|
$oProperties = new DocInfo();
|
||||||
$oProperties->setDescription();
|
$oProperties->setDescription();
|
||||||
$this->assertEquals('', $oProperties->getDescription());
|
$this->assertEquals('', $oProperties->getDescription());
|
||||||
|
|
||||||
|
|
@ -111,7 +111,7 @@ class DocumentPropertiesTest extends \PHPUnit_Framework_TestCase
|
||||||
*/
|
*/
|
||||||
public function testSubject()
|
public function testSubject()
|
||||||
{
|
{
|
||||||
$oProperties = new DocumentProperties();
|
$oProperties = new DocInfo();
|
||||||
$oProperties->setSubject();
|
$oProperties->setSubject();
|
||||||
$this->assertEquals('', $oProperties->getSubject());
|
$this->assertEquals('', $oProperties->getSubject());
|
||||||
|
|
||||||
|
|
@ -124,7 +124,7 @@ class DocumentPropertiesTest extends \PHPUnit_Framework_TestCase
|
||||||
*/
|
*/
|
||||||
public function testKeywords()
|
public function testKeywords()
|
||||||
{
|
{
|
||||||
$oProperties = new DocumentProperties();
|
$oProperties = new DocInfo();
|
||||||
$oProperties->setKeywords();
|
$oProperties->setKeywords();
|
||||||
$this->assertEquals('', $oProperties->getKeywords());
|
$this->assertEquals('', $oProperties->getKeywords());
|
||||||
|
|
||||||
|
|
@ -137,7 +137,7 @@ class DocumentPropertiesTest extends \PHPUnit_Framework_TestCase
|
||||||
*/
|
*/
|
||||||
public function testCategory()
|
public function testCategory()
|
||||||
{
|
{
|
||||||
$oProperties = new DocumentProperties();
|
$oProperties = new DocInfo();
|
||||||
$oProperties->setCategory();
|
$oProperties->setCategory();
|
||||||
$this->assertEquals('', $oProperties->getCategory());
|
$this->assertEquals('', $oProperties->getCategory());
|
||||||
|
|
||||||
|
|
@ -150,7 +150,7 @@ class DocumentPropertiesTest extends \PHPUnit_Framework_TestCase
|
||||||
*/
|
*/
|
||||||
public function testCompany()
|
public function testCompany()
|
||||||
{
|
{
|
||||||
$oProperties = new DocumentProperties();
|
$oProperties = new DocInfo();
|
||||||
$oProperties->setCompany();
|
$oProperties->setCompany();
|
||||||
$this->assertEquals('', $oProperties->getCompany());
|
$this->assertEquals('', $oProperties->getCompany());
|
||||||
|
|
||||||
|
|
@ -163,7 +163,7 @@ class DocumentPropertiesTest extends \PHPUnit_Framework_TestCase
|
||||||
*/
|
*/
|
||||||
public function testManager()
|
public function testManager()
|
||||||
{
|
{
|
||||||
$oProperties = new DocumentProperties();
|
$oProperties = new DocInfo();
|
||||||
$oProperties->setManager();
|
$oProperties->setManager();
|
||||||
$this->assertEquals('', $oProperties->getManager());
|
$this->assertEquals('', $oProperties->getManager());
|
||||||
|
|
||||||
|
|
@ -176,30 +176,30 @@ class DocumentPropertiesTest extends \PHPUnit_Framework_TestCase
|
||||||
*/
|
*/
|
||||||
public function testCustomProperty()
|
public function testCustomProperty()
|
||||||
{
|
{
|
||||||
$oProperties = new DocumentProperties();
|
$oProperties = new DocInfo();
|
||||||
$oProperties->setCustomProperty('key1', null);
|
$oProperties->setCustomProperty('key1', null);
|
||||||
$oProperties->setCustomProperty('key2', true);
|
$oProperties->setCustomProperty('key2', true);
|
||||||
$oProperties->setCustomProperty('key3', 3);
|
$oProperties->setCustomProperty('key3', 3);
|
||||||
$oProperties->setCustomProperty('key4', 4.4);
|
$oProperties->setCustomProperty('key4', 4.4);
|
||||||
$oProperties->setCustomProperty('key5', 'value5');
|
$oProperties->setCustomProperty('key5', 'value5');
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
DocumentProperties::PROPERTY_TYPE_STRING,
|
DocInfo::PROPERTY_TYPE_STRING,
|
||||||
$oProperties->getCustomPropertyType('key1')
|
$oProperties->getCustomPropertyType('key1')
|
||||||
);
|
);
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
DocumentProperties::PROPERTY_TYPE_BOOLEAN,
|
DocInfo::PROPERTY_TYPE_BOOLEAN,
|
||||||
$oProperties->getCustomPropertyType('key2')
|
$oProperties->getCustomPropertyType('key2')
|
||||||
);
|
);
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
DocumentProperties::PROPERTY_TYPE_INTEGER,
|
DocInfo::PROPERTY_TYPE_INTEGER,
|
||||||
$oProperties->getCustomPropertyType('key3')
|
$oProperties->getCustomPropertyType('key3')
|
||||||
);
|
);
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
DocumentProperties::PROPERTY_TYPE_FLOAT,
|
DocInfo::PROPERTY_TYPE_FLOAT,
|
||||||
$oProperties->getCustomPropertyType('key4')
|
$oProperties->getCustomPropertyType('key4')
|
||||||
);
|
);
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
DocumentProperties::PROPERTY_TYPE_STRING,
|
DocInfo::PROPERTY_TYPE_STRING,
|
||||||
$oProperties->getCustomPropertyType('key5')
|
$oProperties->getCustomPropertyType('key5')
|
||||||
);
|
);
|
||||||
$this->assertEquals(null, $oProperties->getCustomPropertyType('key6'));
|
$this->assertEquals(null, $oProperties->getCustomPropertyType('key6'));
|
||||||
|
|
@ -225,50 +225,50 @@ class DocumentPropertiesTest extends \PHPUnit_Framework_TestCase
|
||||||
*/
|
*/
|
||||||
public function testConvertProperty()
|
public function testConvertProperty()
|
||||||
{
|
{
|
||||||
$this->assertEquals('', DocumentProperties::convertProperty('a', 'empty'));
|
$this->assertEquals('', DocInfo::convertProperty('a', 'empty'));
|
||||||
$this->assertEquals(null, DocumentProperties::convertProperty('a', 'null'));
|
$this->assertEquals(null, DocInfo::convertProperty('a', 'null'));
|
||||||
$this->assertEquals(8, DocumentProperties::convertProperty('8', 'int'));
|
$this->assertEquals(8, DocInfo::convertProperty('8', 'int'));
|
||||||
$this->assertEquals(8, DocumentProperties::convertProperty('8.3', 'uint'));
|
$this->assertEquals(8, DocInfo::convertProperty('8.3', 'uint'));
|
||||||
$this->assertEquals(8.3, DocumentProperties::convertProperty('8.3', 'decimal'));
|
$this->assertEquals(8.3, DocInfo::convertProperty('8.3', 'decimal'));
|
||||||
$this->assertEquals('8.3', DocumentProperties::convertProperty('8.3', 'lpstr'));
|
$this->assertEquals('8.3', DocInfo::convertProperty('8.3', 'lpstr'));
|
||||||
$this->assertEquals(strtotime('10/11/2013'), DocumentProperties::convertProperty('10/11/2013', 'date'));
|
$this->assertEquals(strtotime('10/11/2013'), DocInfo::convertProperty('10/11/2013', 'date'));
|
||||||
$this->assertEquals(true, DocumentProperties::convertProperty('true', 'bool'));
|
$this->assertEquals(true, DocInfo::convertProperty('true', 'bool'));
|
||||||
$this->assertEquals(false, DocumentProperties::convertProperty('1', 'bool'));
|
$this->assertEquals(false, DocInfo::convertProperty('1', 'bool'));
|
||||||
$this->assertEquals('1', DocumentProperties::convertProperty('1', 'array'));
|
$this->assertEquals('1', DocInfo::convertProperty('1', 'array'));
|
||||||
$this->assertEquals('1', DocumentProperties::convertProperty('1', ''));
|
$this->assertEquals('1', DocInfo::convertProperty('1', ''));
|
||||||
|
|
||||||
|
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
DocumentProperties::PROPERTY_TYPE_INTEGER,
|
DocInfo::PROPERTY_TYPE_INTEGER,
|
||||||
DocumentProperties::convertPropertyType('int')
|
DocInfo::convertPropertyType('int')
|
||||||
);
|
);
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
DocumentProperties::PROPERTY_TYPE_INTEGER,
|
DocInfo::PROPERTY_TYPE_INTEGER,
|
||||||
DocumentProperties::convertPropertyType('uint')
|
DocInfo::convertPropertyType('uint')
|
||||||
);
|
);
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
DocumentProperties::PROPERTY_TYPE_FLOAT,
|
DocInfo::PROPERTY_TYPE_FLOAT,
|
||||||
DocumentProperties::convertPropertyType('decimal')
|
DocInfo::convertPropertyType('decimal')
|
||||||
);
|
);
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
DocumentProperties::PROPERTY_TYPE_STRING,
|
DocInfo::PROPERTY_TYPE_STRING,
|
||||||
DocumentProperties::convertPropertyType('lpstr')
|
DocInfo::convertPropertyType('lpstr')
|
||||||
);
|
);
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
DocumentProperties::PROPERTY_TYPE_DATE,
|
DocInfo::PROPERTY_TYPE_DATE,
|
||||||
DocumentProperties::convertPropertyType('date')
|
DocInfo::convertPropertyType('date')
|
||||||
);
|
);
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
DocumentProperties::PROPERTY_TYPE_BOOLEAN,
|
DocInfo::PROPERTY_TYPE_BOOLEAN,
|
||||||
DocumentProperties::convertPropertyType('bool')
|
DocInfo::convertPropertyType('bool')
|
||||||
);
|
);
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
DocumentProperties::PROPERTY_TYPE_UNKNOWN,
|
DocInfo::PROPERTY_TYPE_UNKNOWN,
|
||||||
DocumentProperties::convertPropertyType('array')
|
DocInfo::convertPropertyType('array')
|
||||||
);
|
);
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
DocumentProperties::PROPERTY_TYPE_UNKNOWN,
|
DocInfo::PROPERTY_TYPE_UNKNOWN,
|
||||||
DocumentProperties::convertPropertyType('')
|
DocInfo::convertPropertyType('')
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -17,7 +17,7 @@
|
||||||
|
|
||||||
namespace PhpOffice\PhpWord\Tests;
|
namespace PhpOffice\PhpWord\Tests;
|
||||||
|
|
||||||
use PhpOffice\PhpWord\DocumentProperties;
|
use PhpOffice\PhpWord\Metadata\DocInfo;
|
||||||
use PhpOffice\PhpWord\PhpWord;
|
use PhpOffice\PhpWord\PhpWord;
|
||||||
use PhpOffice\PhpWord\Settings;
|
use PhpOffice\PhpWord\Settings;
|
||||||
use PhpOffice\PhpWord\Style;
|
use PhpOffice\PhpWord\Style;
|
||||||
|
|
@ -35,24 +35,11 @@ class PhpWordTest extends \PHPUnit_Framework_TestCase
|
||||||
public function testConstruct()
|
public function testConstruct()
|
||||||
{
|
{
|
||||||
$phpWord = new PhpWord();
|
$phpWord = new PhpWord();
|
||||||
$this->assertEquals(new DocumentProperties(), $phpWord->getDocumentProperties());
|
$this->assertEquals(new DocInfo(), $phpWord->getDocInfo());
|
||||||
$this->assertEquals(Settings::DEFAULT_FONT_NAME, $phpWord->getDefaultFontName());
|
$this->assertEquals(Settings::DEFAULT_FONT_NAME, $phpWord->getDefaultFontName());
|
||||||
$this->assertEquals(Settings::DEFAULT_FONT_SIZE, $phpWord->getDefaultFontSize());
|
$this->assertEquals(Settings::DEFAULT_FONT_SIZE, $phpWord->getDefaultFontSize());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Test set/get document properties
|
|
||||||
*/
|
|
||||||
public function testSetGetDocumentProperties()
|
|
||||||
{
|
|
||||||
$phpWord = new PhpWord();
|
|
||||||
$creator = 'PhpWord';
|
|
||||||
$properties = $phpWord->getDocumentProperties();
|
|
||||||
$properties->setCreator($creator);
|
|
||||||
$phpWord->setDocumentProperties($properties);
|
|
||||||
$this->assertEquals($creator, $phpWord->getDocumentProperties()->getCreator());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test create/get section
|
* Test create/get section
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
|
|
@ -61,7 +61,7 @@ class HTMLTest extends \PHPUnit_Framework_TestCase
|
||||||
|
|
||||||
$phpWord = new PhpWord();
|
$phpWord = new PhpWord();
|
||||||
|
|
||||||
$docProps = $phpWord->getDocumentProperties();
|
$docProps = $phpWord->getDocInfo();
|
||||||
$docProps->setTitle('HTML Test');
|
$docProps->setTitle('HTML Test');
|
||||||
|
|
||||||
$phpWord->addTitleStyle(1, array('bold' => true));
|
$phpWord->addTitleStyle(1, array('bold' => true));
|
||||||
|
|
|
||||||
|
|
@ -47,7 +47,7 @@ class ContentTest extends \PHPUnit_Framework_TestCase
|
||||||
|
|
||||||
$phpWord = new PhpWord();
|
$phpWord = new PhpWord();
|
||||||
|
|
||||||
$docProps = $phpWord->getDocumentProperties();
|
$docProps = $phpWord->getDocInfo();
|
||||||
$docProps->setCustomProperty('Company', 'PHPWord');
|
$docProps->setCustomProperty('Company', 'PHPWord');
|
||||||
|
|
||||||
$phpWord->setDefaultFontName('Verdana');
|
$phpWord->setDefaultFontName('Verdana');
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,52 @@
|
||||||
|
<?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.
|
||||||
|
*
|
||||||
|
* @link https://github.com/PHPOffice/PHPWord
|
||||||
|
* @copyright 2010-2014 PHPWord contributors
|
||||||
|
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
|
||||||
|
*/
|
||||||
|
namespace PhpOffice\PhpWord\Tests\Writer\Word2007\Part;
|
||||||
|
|
||||||
|
use PhpOffice\PhpWord\PhpWord;
|
||||||
|
use PhpOffice\PhpWord\Tests\TestHelperDOCX;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test class for PhpOffice\PhpWord\Writer\Word2007\Part\Settings
|
||||||
|
*
|
||||||
|
* @coversDefaultClass \PhpOffice\PhpWord\Writer\Word2007\Part\Settings
|
||||||
|
*/
|
||||||
|
class SettingsTest extends \PHPUnit_Framework_TestCase
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Executed before each method of the class
|
||||||
|
*/
|
||||||
|
public function tearDown()
|
||||||
|
{
|
||||||
|
TestHelperDOCX::clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test document protection
|
||||||
|
*/
|
||||||
|
public function testDocumentProtection()
|
||||||
|
{
|
||||||
|
$phpWord = new PhpWord();
|
||||||
|
$phpWord->getProtection()->setEditing('forms');
|
||||||
|
|
||||||
|
$doc = TestHelperDOCX::getDocument($phpWord);
|
||||||
|
|
||||||
|
$file = 'word/settings.xml';
|
||||||
|
|
||||||
|
$path = '/w:settings/w:documentProtection';
|
||||||
|
$this->assertTrue($doc->elementExists($path, $file));
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue