123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185 |
- <?php
- /**
- * Created by PhpStorm.
- * User: phperstar
- * Date: 2020/8/10
- * Time: 6:19 PM
- */
- namespace Util\PHPExcel\CachedObjectStorage;
- use Util\PHPExcel\Worksheet;
- use Util\PHPExcel\Cell;
- abstract class CacheBase
- {
- /**
- * Coordinate address of the currently active Cell
- *
- * @var string
- */
- protected $currentObjectID = null;
- /**
- * The currently active Cell
- *
- * @var PHPExcel_Cell
- */
- protected $currentObject = null;
- /**
- * Flag indicating whether the currently active Cell requires saving
- *
- * @var boolean
- */
- protected $currentCellIsDirty = true;
- /**
- * An array of cells or cell pointers for the worksheet cells held in this cache,
- * and indexed by their coordinate address within the worksheet
- *
- * @var array of mixed
- */
- protected $cellCache = array();
- /**
- * Parent worksheet
- *
- * @var PHPExcel_Worksheet
- */
- protected $parent;
- /**
- * Initialise this new cell collection
- *
- * @param PHPExcel_Worksheet $parent The worksheet for this cell collection
- */
- public function __construct(Worksheet $parent)
- {
- // Set our parent worksheet.
- // This is maintained within the cache controller to facilitate re-attaching it to PHPExcel_Cell objects when
- // they are woken from a serialized state
- $this->parent = $parent;
- }
- /**
- * Return the parent worksheet for this cell collection
- *
- * @return PHPExcel_Worksheet
- */
- public function getParent()
- {
- return $this->parent;
- }
- /**
- * Identify whether the caching method is currently available
- * Some methods are dependent on the availability of certain extensions being enabled in the PHP build
- *
- * @return boolean
- */
- public static function cacheMethodIsAvailable()
- {
- return true;
- }
- /**
- * Add or Update a cell in cache
- *
- * @param PHPExcel_Cell $cell Cell to update
- * @return PHPExcel_Cell
- * @throws PHPExcel_Exception
- */
- public function updateCacheData(Cell $cell)
- {
- return $this->addCacheData($cell->getCoordinate(), $cell);
- }
- /**
- * Delete a cell in cache identified by coordinate address
- *
- * @param string $pCoord Coordinate address of the cell to delete
- * @throws PHPExcel_Exception
- */
- public function deleteCacheData($pCoord)
- {
- if ($pCoord === $this->currentObjectID && !is_null($this->currentObject)) {
- $this->currentObject->detach();
- $this->currentObjectID = $this->currentObject = null;
- }
- if (is_object($this->cellCache[$pCoord])) {
- $this->cellCache[$pCoord]->detach();
- unset($this->cellCache[$pCoord]);
- }
- $this->currentCellIsDirty = false;
- }
- /**
- * Is a value set in the current PHPExcel_CachedObjectStorage_ICache for an indexed cell?
- *
- * @param string $pCoord Coordinate address of the cell to check
- * @return boolean
- */
- public function isDataSet($pCoord)
- {
- if ($pCoord === $this->currentObjectID) {
- return true;
- }
- // Check if the requested entry exists in the cache
- return isset($this->cellCache[$pCoord]);
- }
- /**
- * Clone the cell collection
- *
- * @param PHPExcel_Worksheet $parent The new worksheet
- * @return void
- */
- public function copyCellCollection(Worksheet $parent)
- {
- $this->currentCellIsDirty;
- $this->storeData();
- $this->parent = $parent;
- if (($this->currentObject !== null) && (is_object($this->currentObject))) {
- $this->currentObject->attach($this);
- }
- }
- /**
- * Sort the list of all cell addresses currently held in cache by row and column
- *
- * @return string[]
- */
- public function getSortedCellList()
- {
- $sortKeys = array();
- foreach ($this->getCellList() as $coord) {
- sscanf($coord, '%[A-Z]%d', $column, $row);
- $sortKeys[sprintf('%09d%3s', $row, $column)] = $coord;
- }
- ksort($sortKeys);
- return array_values($sortKeys);
- }
- /**
- * Get a list of all cell addresses currently held in cache
- *
- * @return string[]
- */
- public function getCellList()
- {
- return array_keys($this->cellCache);
- }
- /**
- * Return the cell address of the currently active cell object
- *
- * @return string
- */
- public function getCurrentAddress()
- {
- return $this->currentObjectID;
- }
- }
|