The WebAbility® Network Developers - Documentation
WebAbility Site
\datasource\LanguageSource reference

I. Structure:


- namespace:
\datasource\

- Direct superclass:
\datasource\DataSource

- Direct known subclasses:
none

II. Description:


The language source is an example of 4-level cache, using an origin source, a fast object and a shared memory cache.
The origin source is generally a human readable file (in the case of the language, an XML file). The fast object is a serialized version of the compiled file, and the local memory is an array of value directly usable.

The 4 levels cache are:
- An origin XML language data source, kept in any support (file, database, downloadable over network, etc.).
- A first serialized cache portable fast object, kept in any support (file, database, downloadable over network, etc.).
- A second serialized cache into the shared memory.
- A third array cache directly into the object as a local information fastly accesible.

The origin source is an XML file, i.e. a raw not compiled file. Compiling the file into a computer readable format is a time and i/o access consumer. This task will be done only when the original XML file is modified.
The fast object read is also a time and i/o cosumer, and will be read only when it desynchronizes with the original source.
The shared memory cache is optional but highly recommended to not read the fast object on each page hit (only the timestamp stat).
The memory is loaded when the data is needed with read() method.

To create a language object, you need a \datasource\DataSource origin instance (generally a \datasource\FileSource) and a \datasource\FastObjectSource instance.
The fast object will be charged to always be consistant and synchronized with the origin, but save a lot of access and CPU time.

unlink will physically deletes the origin source file, afo file and shared memory if write access is granted.

The language origin table is a specific XML file.
Please check the \core\WALanguage documentation.


III. Reference:


3.1. Contructor:


\datasource\LanguageSource($originsource, $fastobjectsource)
Creates the instance.
  • $originsource: \datasource\DataSource extended instance, the origin of our language XML.
  • $fastobjectsource: \datasource\FastObjectSource instance, the instance to stock the fast object and shared memory.
If the originsource does not exists, the object will be invalid until the file is created.
If the fast object, shared memory or the local memory is empty or desynchronized (creation time before the origin creation time) then the object will be invalid until synchronization.


3.2. Constants:

There is no constant into this class.


3.3. Attributes:


protected DataSource $originsource
Is used to store the origin datasource instance.

protected FastObjectSource $fastobjectsource
Is used to store the fast object instance.

protected boolean $loaded
Is used to know if the language data is in local memory.
false means the data is not loaded yet.


3.4. Methods:


public boolean static isValid()
This method is used to know if the data into the LanguageSource is valid or not.
If the originsource is invalid, the object will be invalid until the source is created.
If the fast object or the local memory are empty or desynchronized (creation time before the origin creation time) then the object will be invalid until synchronization (generally when read or write).

public integer getTimeStamp()
This method is used to get the last write access to the local information data.
If the object has no local data yet, it will return null.
Note: The returned value is a unix timestamp that you can format to a human readable date with date().

public void setLanguage($id, $lang)
This method is used to set the unique identificator and the language of the language table. Use this method only if you are going to create a new language XML file. The id and language are loaded automatically from any already existing source.
  • $id: string, the unique identificator of the language table.
  • $lang: string, the ISO 2 letters of the language in the table.

public array read()
This method is used to read our language data.
If the origin source object is invalid (file not accesible), it will return null.
if the origin source object is valid and available, the 4 levels of the language object will be synchronized.

public void write($data)
This method is used to write the data into our language object.
The 4 levels of the fast object will be synchronized.
If the language object is NEW and have no origin file, you must set id and language to create your origin XML file.
  • $data: array of string => string, the data to write in the fast object.

public void unlink()
This method is used to physically deletes the language object, fast object and shared memory variable.
The object becomes invalid.