| <?php |
|
|
| |
| |
| |
| |
| |
| |
|
|
| namespace Piwik\DataTable; |
|
|
| use Exception; |
| use Piwik\Common; |
| use Piwik\DataTable; |
|
|
| |
| |
| |
| |
| |
| class Manager extends \ArrayObject |
| { |
| |
| |
| |
| |
| protected $nextTableId = 0; |
|
|
| private static $instance; |
|
|
| public static function getInstance() |
| { |
| if (!isset(self::$instance)) { |
| self::$instance = new Manager(); |
| } |
|
|
| return self::$instance; |
| } |
|
|
| |
| |
| |
| |
| |
| |
| public function addTable($table) |
| { |
| $this->nextTableId++; |
| $this[$this->nextTableId] = $table; |
| return $this->nextTableId; |
| } |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| public function getTable($idTable) |
| { |
| if (!isset($this[$idTable])) { |
| throw new TableNotFoundException(sprintf("Error: table id %s not found in memory. (If this error is causing you problems in production, please report it in Matomo issue tracker.)", $idTable)); |
| } |
|
|
| return $this[$idTable]; |
| } |
|
|
| |
| |
| |
| |
| |
| public function getMostRecentTableId() |
| { |
| return $this->nextTableId; |
| } |
|
|
| |
| |
| |
| |
| |
| |
| public function deleteAll($deleteWhenIdTableGreaterThan = 0, $deleteUntil = null) |
| { |
| foreach ($this as $id => $table) { |
| if ( |
| $id > $deleteWhenIdTableGreaterThan |
| && ($deleteUntil === null || $id <= $deleteUntil) |
| ) { |
| $this->deleteTable($id); |
| } |
| } |
|
|
| if ($deleteWhenIdTableGreaterThan == 0) { |
| $this->exchangeArray(array()); |
| $this->nextTableId = 0; |
| } |
| } |
|
|
| |
| |
| |
| |
| |
| |
| public function deleteTable($id) |
| { |
| if (isset($this[$id])) { |
| Common::destroy($this[$id]); |
| $this->setTableDeleted($id); |
| } |
| } |
|
|
| |
| |
| |
| |
| |
| |
| |
| public function deleteTablesExceptIgnored($idsToBeIgnored, $firstTableId = 0) |
| { |
| $lastTableId = $this->getMostRecentTableId(); |
|
|
| for ($index = $firstTableId; $index <= $lastTableId; $index++) { |
| if (!in_array($index, $idsToBeIgnored)) { |
| $this->deleteTable($index); |
| } |
| } |
| } |
|
|
| |
| |
| |
| |
| |
| public function setTableDeleted($id) |
| { |
| $this[$id] = null; |
| } |
|
|
| |
| |
| |
| public function dumpAllTables() |
| { |
| echo "<hr />Manager->dumpAllTables()<br />"; |
| foreach ($this as $id => $table) { |
| if (!($table instanceof DataTable)) { |
| echo "Error table $id is not instance of datatable<br />"; |
| var_export($table); |
| } else { |
| echo "<hr />"; |
| echo "Table (index=$id) TableId = " . $table->getId() . "<br />"; |
| echo $table; |
| echo "<br />"; |
| } |
| } |
| echo "<br />-- End Manager->dumpAllTables()<hr />"; |
| } |
| } |
|
|