~begerega/ihris-chw-sl/trunk

« back to all changes in this revision

Viewing changes to tools/PHPExcel/PHPExcel/CachedObjectStorage/MemoryGZip.php

  • Committer: Ese Egerega
  • Date: 2018-05-03 14:17:04 UTC
  • Revision ID: egerega@gmail.com-20180503141704-3br8dto013rgx65x
Initial import of Sierra Leone  CHW registry

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?php
 
2
 
 
3
/**
 
4
 * PHPExcel_CachedObjectStorage_MemoryGZip
 
5
 *
 
6
 * Copyright (c) 2006 - 2015 PHPExcel
 
7
 *
 
8
 * This library is free software; you can redistribute it and/or
 
9
 * modify it under the terms of the GNU Lesser General Public
 
10
 * License as published by the Free Software Foundation; either
 
11
 * version 2.1 of the License, or (at your option) any later version.
 
12
 *
 
13
 * This library is distributed in the hope that it will be useful,
 
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
16
 * Lesser General Public License for more details.
 
17
 *
 
18
 * You should have received a copy of the GNU Lesser General Public
 
19
 * License along with this library; if not, write to the Free Software
 
20
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 
21
 *
 
22
 * @category   PHPExcel
 
23
 * @package    PHPExcel_CachedObjectStorage
 
24
 * @copyright  Copyright (c) 2006 - 2015 PHPExcel (http://www.codeplex.com/PHPExcel)
 
25
 * @license    http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt    LGPL
 
26
 * @version    ##VERSION##, ##DATE##
 
27
 */
 
28
class PHPExcel_CachedObjectStorage_MemoryGZip extends PHPExcel_CachedObjectStorage_CacheBase implements PHPExcel_CachedObjectStorage_ICache
 
29
{
 
30
    /**
 
31
     * Store cell data in cache for the current cell object if it's "dirty",
 
32
     *     and the 'nullify' the current cell object
 
33
     *
 
34
     * @return    void
 
35
     * @throws    PHPExcel_Exception
 
36
     */
 
37
    protected function storeData()
 
38
    {
 
39
        if ($this->currentCellIsDirty && !empty($this->currentObjectID)) {
 
40
            $this->currentObject->detach();
 
41
 
 
42
            $this->cellCache[$this->currentObjectID] = gzdeflate(serialize($this->currentObject));
 
43
            $this->currentCellIsDirty = false;
 
44
        }
 
45
        $this->currentObjectID = $this->currentObject = null;
 
46
    }
 
47
 
 
48
 
 
49
    /**
 
50
     * Add or Update a cell in cache identified by coordinate address
 
51
     *
 
52
     * @param    string            $pCoord        Coordinate address of the cell to update
 
53
     * @param    PHPExcel_Cell    $cell        Cell to update
 
54
     * @return    PHPExcel_Cell
 
55
     * @throws    PHPExcel_Exception
 
56
     */
 
57
    public function addCacheData($pCoord, PHPExcel_Cell $cell)
 
58
    {
 
59
        if (($pCoord !== $this->currentObjectID) && ($this->currentObjectID !== null)) {
 
60
            $this->storeData();
 
61
        }
 
62
 
 
63
        $this->currentObjectID = $pCoord;
 
64
        $this->currentObject = $cell;
 
65
        $this->currentCellIsDirty = true;
 
66
 
 
67
        return $cell;
 
68
    }
 
69
 
 
70
 
 
71
    /**
 
72
     * Get cell at a specific coordinate
 
73
     *
 
74
     * @param     string             $pCoord        Coordinate of the cell
 
75
     * @throws     PHPExcel_Exception
 
76
     * @return     PHPExcel_Cell     Cell that was found, or null if not found
 
77
     */
 
78
    public function getCacheData($pCoord)
 
79
    {
 
80
        if ($pCoord === $this->currentObjectID) {
 
81
            return $this->currentObject;
 
82
        }
 
83
        $this->storeData();
 
84
 
 
85
        //    Check if the entry that has been requested actually exists
 
86
        if (!isset($this->cellCache[$pCoord])) {
 
87
            //    Return null if requested entry doesn't exist in cache
 
88
            return null;
 
89
        }
 
90
 
 
91
        //    Set current entry to the requested entry
 
92
        $this->currentObjectID = $pCoord;
 
93
        $this->currentObject = unserialize(gzinflate($this->cellCache[$pCoord]));
 
94
        //    Re-attach this as the cell's parent
 
95
        $this->currentObject->attach($this);
 
96
 
 
97
        //    Return requested entry
 
98
        return $this->currentObject;
 
99
    }
 
100
 
 
101
 
 
102
    /**
 
103
     * Get a list of all cell addresses currently held in cache
 
104
     *
 
105
     * @return  string[]
 
106
     */
 
107
    public function getCellList()
 
108
    {
 
109
        if ($this->currentObjectID !== null) {
 
110
            $this->storeData();
 
111
        }
 
112
 
 
113
        return parent::getCellList();
 
114
    }
 
115
 
 
116
 
 
117
    /**
 
118
     * Clear the cell collection and disconnect from our parent
 
119
     *
 
120
     * @return    void
 
121
     */
 
122
    public function unsetWorksheetCells()
 
123
    {
 
124
        if (!is_null($this->currentObject)) {
 
125
            $this->currentObject->detach();
 
126
            $this->currentObject = $this->currentObjectID = null;
 
127
        }
 
128
        $this->cellCache = array();
 
129
 
 
130
        //    detach ourself from the worksheet, so that it can then delete this object successfully
 
131
        $this->parent = null;
 
132
    }
 
133
}