Remove HashTable and all related properties/methods. PHPWord doesn't (yet) need it.
This commit is contained in:
parent
495930be9d
commit
a2a00393c1
|
|
@ -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
|
||||
|
||||
|
|
|
|||
|
|
@ -1,203 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* PHPWord
|
||||
*
|
||||
* @link https://github.com/PHPOffice/PHPWord
|
||||
* @copyright 2014 PHPWord
|
||||
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
|
||||
*/
|
||||
|
||||
namespace PhpOffice\PhpWord;
|
||||
|
||||
use PhpOffice\PhpWord\Exception\Exception;
|
||||
|
||||
/**
|
||||
* Hash table
|
||||
*
|
||||
* @codeCoverageIgnore Legacy from PHPExcel
|
||||
*/
|
||||
class HashTable
|
||||
{
|
||||
/**
|
||||
* HashTable elements
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $_items = array();
|
||||
|
||||
/**
|
||||
* HashTable key map
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $_keyMap = array();
|
||||
|
||||
/**
|
||||
* Create new
|
||||
*
|
||||
* @param \PhpOffice\PhpWord\IComparable[] $pSource Optional source array to create HashTable from
|
||||
*/
|
||||
public function __construct($pSource = null)
|
||||
{
|
||||
if (!is_null($pSource)) {
|
||||
$this->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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
|
|
|||
|
|
@ -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
|
||||
*
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
|
|
|
|||
|
|
@ -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());
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Reference in New Issue