<?php
/*
LanguageSource.lib, DomCore, the WebAbility(r) Core System
Contains the language 3-level cache access object
(c) 2008-2012 Philippe Thomassigny
This file is part of DomCore
DomCore is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
DomCore is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with DomCore. If not, see <http://www.gnu.org/licenses/>.
*/
/* @UML_Box -- Do not edit
|------------------------------------------------------------------|
| LanguageSource : Language 3-level access object |
|------------------------------------------------------------------|
| # originsource : DataSource extended object |
| # fastobjectsource : FastObjectSource extended object |
| # loaded : boolean |
| - tm1 : timestamp of originsource |
| - tm2 : timestamp of fastobjectsource |
|------------------------------------------------------------------|
| + new LanguageSource($originsource: DataSource, $fastobjectsource: FastObjectSource) |
| + isValid() : boolean |
| + getTimestamp() : integer |
| + read() : mixed |
| + write($data: mixed) : void |
| + unlink() : void |
|------------------------------------------------------------------|
|------------------------------------------------------------------|
@End_UML_Box */
class LanguageSource extends DataSource
{
protected $originsource = null;
protected $fastobjectsource = null;
protected $loaded = false;
private $tm1;
private $tm2;
public function __construct($originsource, $fastobjectsource)
{
parent::__construct(null);
if (self::$debug || $this->localdebug)
$this->doDebug("include/datasources/LanguageSource->__construct($originsource, $fastobjectsource)", WADebug::SYSTEM);
$this->originsource = $originsource;
$this->fastobjectsource = $fastobjectsource;
}
public function isValid()
{
if (self::$debug || $this->localdebug)
$this->doDebug('include/datasources/LanguageSource->isValid()', WADebug::SYSTEM);
$this->tm1 = $this->originsource->getTimeStamp();
$this->tm2 = $this->fastobjectsource->getTimeStamp();
// true if anything has good time
return ($this->tm1 && $this->tm2 && $this->tm1 <= $this->tm2);
}
public function getTimeStamp()
{
if (self::$debug || $this->localdebug)
$this->doDebug('include/datasources/LanguageSource->getTimeStamp()', WADebug::SYSTEM);
return $this->fastobjectsource->getTimeStamp();
}
public function write($data)
{
if (self::$debug || $this->localdebug)
$this->doDebug("include/datasources/LanguageSource->write($data)", WADebug::SYSTEM);
$this->fastobjectsource->write($data);
$this->originsource->write($data);
parent::write($data);
$this->loaded = true;
}
public function read()
{
if (self::$debug || $this->localdebug)
$this->doDebug('include/datasources/LanguageSource->read()', WADebug::SYSTEM);
if ($this->isValid() && $this->loaded)
return $this->data;
// we sinchronize
// origin source is new, we recalculate all the chain
if ($this->tm1 > $this->tm2)
{
parent::write(new WALanguage($this->originsource->read()));
$this->fastobjectsource->write($this->data);
}
elseif ($this->tm2 > $this->timestamp)
{
parent::write($this->fastobjectsource->read());
}
$this->loaded = true;
return $this->data;
}
// destroy anything
public function unlink()
{
if (self::$debug || $this->localdebug)
$this->doDebug('include/datasource/LanguageSource->unlink()', WADebug::SYSTEM);
$this->originsource->unlink();
$this->fastobjectsource->unlink();
parent::unlink();
}
}
?> |