コード例 #1
0
 /**
  * Read custom document properties.
  *
  * @param \PhpOffice\PhpWord\PhpWord $phpWord
  * @return void
  */
 public function read(PhpWord $phpWord)
 {
     $xmlReader = new XMLReader();
     $xmlReader->getDomFromZip($this->docFile, $this->xmlFile);
     $docProps = $phpWord->getDocInfo();
     $nodes = $xmlReader->getElements('*');
     if ($nodes->length > 0) {
         foreach ($nodes as $node) {
             $propertyName = $xmlReader->getAttribute('name', $node);
             $attributeNode = $xmlReader->getElement('*', $node);
             $attributeType = $attributeNode->nodeName;
             $attributeValue = $attributeNode->nodeValue;
             $attributeValue = DocInfo::convertProperty($attributeValue, $attributeType);
             $attributeType = DocInfo::convertPropertyType($attributeType);
             $docProps->setCustomProperty($propertyName, $attributeValue, $attributeType);
         }
     }
 }
コード例 #2
0
ファイル: DocInfoTest.php プロジェクト: brunodebarros/phpword
 /**
  * Convert property
  */
 public function testConvertProperty()
 {
     $this->assertEquals('', DocInfo::convertProperty('a', 'empty'));
     $this->assertNull(DocInfo::convertProperty('a', 'null'));
     $this->assertEquals(8, DocInfo::convertProperty('8', 'int'));
     $this->assertEquals(8, DocInfo::convertProperty('8.3', 'uint'));
     $this->assertEquals(8.300000000000001, DocInfo::convertProperty('8.3', 'decimal'));
     $this->assertEquals('8.3', DocInfo::convertProperty('8.3', 'lpstr'));
     $this->assertEquals(strtotime('10/11/2013'), DocInfo::convertProperty('10/11/2013', 'date'));
     $this->assertTrue(DocInfo::convertProperty('true', 'bool'));
     // todo: change to assertNotTrue when got upgraded to PHPUnit 4.x
     $this->assertEquals(false, DocInfo::convertProperty('1', 'bool'));
     $this->assertEquals('1', DocInfo::convertProperty('1', 'array'));
     $this->assertEquals('1', DocInfo::convertProperty('1', ''));
     $this->assertEquals(DocInfo::PROPERTY_TYPE_INTEGER, DocInfo::convertPropertyType('int'));
     $this->assertEquals(DocInfo::PROPERTY_TYPE_INTEGER, DocInfo::convertPropertyType('uint'));
     $this->assertEquals(DocInfo::PROPERTY_TYPE_FLOAT, DocInfo::convertPropertyType('decimal'));
     $this->assertEquals(DocInfo::PROPERTY_TYPE_STRING, DocInfo::convertPropertyType('lpstr'));
     $this->assertEquals(DocInfo::PROPERTY_TYPE_DATE, DocInfo::convertPropertyType('date'));
     $this->assertEquals(DocInfo::PROPERTY_TYPE_BOOLEAN, DocInfo::convertPropertyType('bool'));
     $this->assertEquals(DocInfo::PROPERTY_TYPE_UNKNOWN, DocInfo::convertPropertyType('array'));
     $this->assertEquals(DocInfo::PROPERTY_TYPE_UNKNOWN, DocInfo::convertPropertyType(''));
 }
コード例 #3
0
ファイル: DocInfoTest.php プロジェクト: Senasum/PHPWord
 /**
  * Convert property
  */
 public function testConvertProperty()
 {
     $this->assertEquals('', DocInfo::convertProperty('a', 'empty'));
     $this->assertEquals(null, DocInfo::convertProperty('a', 'null'));
     $this->assertEquals(8, DocInfo::convertProperty('8', 'int'));
     $this->assertEquals(8, DocInfo::convertProperty('8.3', 'uint'));
     $this->assertEquals(8.300000000000001, DocInfo::convertProperty('8.3', 'decimal'));
     $this->assertEquals('8.3', DocInfo::convertProperty('8.3', 'lpstr'));
     $this->assertEquals(strtotime('10/11/2013'), DocInfo::convertProperty('10/11/2013', 'date'));
     $this->assertEquals(true, DocInfo::convertProperty('true', 'bool'));
     $this->assertEquals(false, DocInfo::convertProperty('1', 'bool'));
     $this->assertEquals('1', DocInfo::convertProperty('1', 'array'));
     $this->assertEquals('1', DocInfo::convertProperty('1', ''));
     $this->assertEquals(DocInfo::PROPERTY_TYPE_INTEGER, DocInfo::convertPropertyType('int'));
     $this->assertEquals(DocInfo::PROPERTY_TYPE_INTEGER, DocInfo::convertPropertyType('uint'));
     $this->assertEquals(DocInfo::PROPERTY_TYPE_FLOAT, DocInfo::convertPropertyType('decimal'));
     $this->assertEquals(DocInfo::PROPERTY_TYPE_STRING, DocInfo::convertPropertyType('lpstr'));
     $this->assertEquals(DocInfo::PROPERTY_TYPE_DATE, DocInfo::convertPropertyType('date'));
     $this->assertEquals(DocInfo::PROPERTY_TYPE_BOOLEAN, DocInfo::convertPropertyType('bool'));
     $this->assertEquals(DocInfo::PROPERTY_TYPE_UNKNOWN, DocInfo::convertPropertyType('array'));
     $this->assertEquals(DocInfo::PROPERTY_TYPE_UNKNOWN, DocInfo::convertPropertyType(''));
 }