diff --git a/CHANGELOG.md b/CHANGELOG.md index 8b81a016..84952a3c 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -39,6 +39,7 @@ This is the changelog between releases of PHPWord. Releases are listed in revers - Reader: Rename AbstractReader > Reader - @ivanlanin - General: Refactor folders: Element, Container, and Exception - @ivanlanin GH-187 - Container: Create new Container abstract class - @ivanlanin GH-187 +- General: Remove legacy HashTable and all related properties/methods - @ivanlanin GH-187 ## 0.9.1 - 27 Mar 2014 diff --git a/src/PhpWord/HashTable.php b/src/PhpWord/HashTable.php deleted file mode 100644 index 93bcb689..00000000 --- a/src/PhpWord/HashTable.php +++ /dev/null @@ -1,203 +0,0 @@ -addFromSource($pSource); - } - } - - /** - * Add HashTable items from source - * - * @param \PhpOffice\PhpWord\IComparable[] $pSource Source array to create HashTable from - * @throws \PhpOffice\PhpWord\Exception\Exception - */ - public function addFromSource($pSource = null) - { - // Check if an array was passed - if ($pSource == null) { - return; - } elseif (!is_array($pSource)) { - throw new Exception('Invalid array parameter passed.'); - } - - foreach ($pSource as $item) { - $this->add($item); - } - } - - /** - * Add HashTable item - * - * @param \PhpOffice\PhpWord\IComparable $pSource Item to add - */ - public function add(IComparable $pSource = null) - { - // Determine hashcode - $hashCode = null; - $hashIndex = $pSource->getHashIndex(); - if (is_null($hashIndex)) { - $hashCode = $pSource->getHashCode(); - } elseif (isset ($this->_keyMap[$hashIndex])) { - $hashCode = $this->_keyMap[$hashIndex]; - } else { - $hashCode = $pSource->getHashCode(); - } - - // Add value - if (!isset($this->_items[$hashCode])) { - $this->_items[$hashCode] = $pSource; - $index = count($this->_items) - 1; - $this->_keyMap[$index] = $hashCode; - $pSource->setHashIndex($index); - } else { - $pSource->setHashIndex($this->_items[$hashCode]->getHashIndex()); - } - } - - /** - * Remove HashTable item - * - * @param \PhpOffice\PhpWord\IComparable $pSource Item to remove - */ - public function remove(IComparable $pSource = null) - { - if (isset($this->_items[$pSource->getHashCode()])) { - unset($this->_items[$pSource->getHashCode()]); - - $deleteKey = -1; - foreach ($this->_keyMap as $key => $value) { - if ($deleteKey >= 0) { - $this->_keyMap[$key - 1] = $value; - } - - if ($value == $pSource->getHashCode()) { - $deleteKey = $key; - } - } - unset($this->_keyMap[count($this->_keyMap) - 1]); - } - } - - /** - * Clear HashTable - * - */ - public function clear() - { - $this->_items = array(); - $this->_keyMap = array(); - } - - /** - * Get item count - * - * @return int - */ - public function count() - { - return count($this->_items); - } - - /** - * Get hash code index - * - * @param string $pHashCode - * @return int Index - */ - public function getIndexForHashCode($pHashCode = '') - { - return array_search($pHashCode, $this->_keyMap); - } - - /** - * Get by index - * - * @param int $pIndex - * @return \PhpOffice\PhpWord\IComparable - */ - public function getByIndex($pIndex = 0) - { - if (isset($this->_keyMap[$pIndex])) { - return $this->getByHashCode($this->_keyMap[$pIndex]); - } - - return null; - } - - /** - * Get by hashcode - * @param string $pHashCode - * @return \PhpOffice\PhpWord\IComparable - * - */ - public function getByHashCode($pHashCode = '') - { - if (isset($this->_items[$pHashCode])) { - return $this->_items[$pHashCode]; - } - - return null; - } - - /** - * Convert to array - * - * @return \PhpOffice\PhpWord\IComparable[] - */ - public function toArray() - { - return $this->_items; - } - - /** - * Implement PHP __clone to create a deep clone, not just a shallow copy. - */ - public function __clone() - { - $vars = get_object_vars($this); - foreach ($vars as $key => $value) { - if (is_object($value)) { - $this->$key = clone $value; - } - } - } -} diff --git a/src/PhpWord/Writer/ODText.php b/src/PhpWord/Writer/ODText.php index 72955ef1..04ec0bec 100755 --- a/src/PhpWord/Writer/ODText.php +++ b/src/PhpWord/Writer/ODText.php @@ -11,7 +11,6 @@ namespace PhpOffice\PhpWord\Writer; use PhpOffice\PhpWord\Exception\Exception; use PhpOffice\PhpWord\PhpWord; -use PhpOffice\PhpWord\HashTable; use PhpOffice\PhpWord\Settings; use PhpOffice\PhpWord\Writer\ODText\Content; use PhpOffice\PhpWord\Writer\ODText\Manifest; @@ -24,12 +23,6 @@ use PhpOffice\PhpWord\Writer\ODText\Styles; */ class ODText extends Writer implements IWriter { - /** - * Private unique PHPWord_Worksheet_BaseDrawing HashTable - * - * @var HashTable - */ - private $drawingHashTable; /** * Create new ODText writer @@ -49,9 +42,6 @@ class ODText extends Writer implements IWriter foreach ($this->writerParts as $writer) { $writer->setParentWriter($this); } - - // Set HashTable variables - $this->drawingHashTable = new HashTable(); } /** @@ -103,42 +93,6 @@ class ODText extends Writer implements IWriter // Add META-INF/manifest.xml $objZip->addFromString('META-INF/manifest.xml', $this->getWriterPart('manifest')->writeManifest($this->phpWord)); - // Add media. Has not used yet. Legacy from PHPExcel. - // @codeCoverageIgnoreStart - for ($i = 0; $i < $this->getDrawingHashTable()->count(); ++$i) { - if ($this->getDrawingHashTable()->getByIndex($i) instanceof PHPWord_Shape_Drawing) { - $imageContents = null; - $imagePath = $this->getDrawingHashTable()->getByIndex($i)->getPath(); - - if (strpos($imagePath, 'zip://') !== false) { - $imagePath = substr($imagePath, 6); - $imagePathSplitted = explode('#', $imagePath); - - $zipClass = Settings::getZipClass(); - $imageZip = new $zipClass(); - $imageZip->open($imagePathSplitted[0]); - $imageContents = $imageZip->getFromName($imagePathSplitted[1]); - $imageZip->close(); - unset($imageZip); - } else { - $imageContents = file_get_contents($imagePath); - } - - $objZip->addFromString('Pictures/' . str_replace(' ', '_', $this->getDrawingHashTable()->getByIndex($i)->getIndexedFilename()), $imageContents); - } elseif ($this->getDrawingHashTable()->getByIndex($i) instanceof PHPWord_Shape_MemoryDrawing) { - ob_start(); - call_user_func( - $this->getDrawingHashTable()->getByIndex($i)->getRenderingFunction(), - $this->getDrawingHashTable()->getByIndex($i)->getImageResource() - ); - $imageContents = ob_get_contents(); - ob_end_clean(); - - $objZip->addFromString('Pictures/' . str_replace(' ', '_', $this->getDrawingHashTable()->getByIndex($i)->getIndexedFilename()), $imageContents); - } - } - // @codeCoverageIgnoreEnd - // Close file if ($objZip->close() === false) { throw new Exception("Could not close zip file $pFilename."); @@ -149,14 +103,4 @@ class ODText extends Writer implements IWriter throw new Exception("PhpWord object unassigned."); } } - - /** - * Get PHPWord_Worksheet_BaseDrawing HashTable - * - * @return HashTable - */ - public function getDrawingHashTable() - { - return $this->drawingHashTable; - } } diff --git a/src/PhpWord/Writer/ODText/Manifest.php b/src/PhpWord/Writer/ODText/Manifest.php index 69949c73..d7ab6cdc 100755 --- a/src/PhpWord/Writer/ODText/Manifest.php +++ b/src/PhpWord/Writer/ODText/Manifest.php @@ -59,33 +59,7 @@ class Manifest extends WriterPart $xmlWriter->writeAttribute('manifest:full-path', 'styles.xml'); $xmlWriter->endElement(); - // Not used yet. Legacy from PHPExcel - // @codeCoverageIgnoreStart - for ($i = 0; $i < $this->getParentWriter()->getDrawingHashTable()->count(); ++$i) { - if ($this->getParentWriter()->getDrawingHashTable()->getByIndex($i) instanceof PHPWord_Shape_Drawing) { - $extension = strtolower($this->getParentWriter()->getDrawingHashTable()->getByIndex($i)->getExtension()); - $mimeType = $this->getImageMimeType($this->getParentWriter()->getDrawingHashTable()->getByIndex($i)->getPath()); - - $xmlWriter->startElement('manifest:file-entry'); - $xmlWriter->writeAttribute('manifest:media-type', $mimeType); - $xmlWriter->writeAttribute('manifest:full-path', 'Pictures/' . str_replace(' ', '_', $this->getParentWriter()->getDrawingHashTable()->getByIndex($i)->getIndexedFilename())); - $xmlWriter->endElement(); - } elseif ($this->getParentWriter()->getDrawingHashTable()->getByIndex($i) instanceof PHPWord_Shape_MemoryDrawing) { - $extension = strtolower($this->getParentWriter()->getDrawingHashTable()->getByIndex($i)->getMimeType()); - $extension = explode('/', $extension); - $extension = $extension[1]; - - $mimeType = $this->getParentWriter()->getDrawingHashTable()->getByIndex($i)->getMimeType(); - - $xmlWriter->startElement('manifest:file-entry'); - $xmlWriter->writeAttribute('manifest:media-type', $mimeType); - $xmlWriter->writeAttribute('manifest:full-path', 'Pictures/' . str_replace(' ', '_', $this->getParentWriter()->getDrawingHashTable()->getByIndex($i)->getIndexedFilename())); - $xmlWriter->endElement(); - } - } - // @codeCoverageIgnoreEnd - - $xmlWriter->endElement(); + $xmlWriter->endElement(); // manifest:manifest // Return return $xmlWriter->getData(); diff --git a/src/PhpWord/Writer/RTF.php b/src/PhpWord/Writer/RTF.php index b5ce20a7..6d693f17 100755 --- a/src/PhpWord/Writer/RTF.php +++ b/src/PhpWord/Writer/RTF.php @@ -11,7 +11,6 @@ namespace PhpOffice\PhpWord\Writer; use PhpOffice\PhpWord\Exception\Exception; use PhpOffice\PhpWord\PhpWord; -use PhpOffice\PhpWord\HashTable; use PhpOffice\PhpWord\Element\Image; use PhpOffice\PhpWord\Element\Link; use PhpOffice\PhpWord\Element\ListItem; @@ -33,13 +32,6 @@ use PhpOffice\PhpWord\TOC; */ class RTF extends Writer implements IWriter { - /** - * Private unique PHPWord_Worksheet_BaseDrawing HashTable - * - * @var HashTable - */ - private $drawingHashTable; - /** * Color register * @@ -69,9 +61,6 @@ class RTF extends Writer implements IWriter { // Assign PhpWord $this->setPhpWord($phpWord); - - // Set HashTable variables - $this->drawingHashTable = new HashTable(); } /** @@ -95,16 +84,6 @@ class RTF extends Writer implements IWriter } } - /** - * Get PHPWord_Worksheet_BaseDrawing HashTable - * - * @return HashTable - */ - public function getDrawingHashTable() - { - return $this->drawingHashTable; - } - /** * Get all data * diff --git a/tests/PhpWord/Tests/Writer/ODTextTest.php b/tests/PhpWord/Tests/Writer/ODTextTest.php index 9ee31432..82263c0f 100644 --- a/tests/PhpWord/Tests/Writer/ODTextTest.php +++ b/tests/PhpWord/Tests/Writer/ODTextTest.php @@ -26,7 +26,6 @@ class ODTextTest extends \PHPUnit_Framework_TestCase $object = new ODText(new PhpWord()); $this->assertInstanceOf('PhpOffice\\PhpWord\\PhpWord', $object->getPhpWord()); - $this->assertInstanceOf('PhpOffice\\PhpWord\\HashTable', $object->getDrawingHashTable()); $this->assertEquals('./', $object->getDiskCachingDirectory()); foreach (array('Content', 'Manifest', 'Meta', 'Mimetype', 'Styles') as $part) { diff --git a/tests/PhpWord/Tests/Writer/RTFTest.php b/tests/PhpWord/Tests/Writer/RTFTest.php index 4016cb85..4872ef39 100644 --- a/tests/PhpWord/Tests/Writer/RTFTest.php +++ b/tests/PhpWord/Tests/Writer/RTFTest.php @@ -26,7 +26,6 @@ class RTFTest extends \PHPUnit_Framework_TestCase $object = new RTF(new PhpWord); $this->assertInstanceOf('PhpOffice\\PhpWord\\PhpWord', $object->getPhpWord()); - $this->assertInstanceOf('PhpOffice\\PhpWord\\HashTable', $object->getDrawingHashTable()); } /**