Source for file Words.php
Documentation is available at Words.php
* Copyright (C) 2009 Mai (Me Artificial Intelligence)
* This program 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.
* This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
* @author Wouter Bulten (wouterbulten@mai-ai.org)
* @copyright Copyright (C) 2009 Mai (Me Artificial Intelligence)
* @license http://opensource.org/licenses/gpl-3.0.html GNU General Public License version 3 (GPLv3)
* @link http://www.launchpad.net/mai
/** Load required file */
require_once 'Zend/CodeGenerator/Php/File.php';
require_once 'Mai/Cache/Interface.php';
* Mai_Cache_Words is a way to cache words.
* @author Wouter Bulten (wouterbulten@mai-ai.org)
* @copyright Copyright (C) 2009 Mai (Me Artificial Intelligence)
* @license http://opensource.org/licenses/gpl-3.0.html GNU General Public License version 3 (GPLv3)
* @link http://www.launchpad.net/mai
* @uses Zend_CodeGenerator_Php_File
* Location of the cache file.
* Name of the cache file.
* Name of the cache variable.
* Constructor sets the path and filename for saving and loading the cache.
* @param $location Location of the file. Use null to use the value in the ini file.
* @param $filename Name of the file.
* @param $varName Name of the variable.
* @param $creator Creator of this class.
function __construct($location = null, $filename, $varName, $creator = null)
//This class should only be created by Mai_Cache
trigger_error('Please use Mai_Cache to create an instance of Mai_Cache_Words.', E_USER_NOTICE);
//Load the location if null.
throw new InvalidArgumentException('$filename must be a string.');
throw new InvalidArgumentException('$varName must be a string.');
* Creates an cache file with date from the base database.
* @param $words The words to cache.
$body = $this->convertArrayToSourceCode($words);
$this->createCacheFile($body);
* Converts an double array to an php array.
$output = '$' . $this->_cacheVariableName . ' = array(';
foreach($data as $key_1 => $value_1)
$output .= $key_1 . ' => array(';
foreach($value_1 as $key_2 => $value_2)
//Integers should not be transformed to strings
$output .= '\'' . $key_2 . '\'' . ' => ' . $value_2 . ', ';
$output .= '\'' . $key_2 . '\'' . ' => \'' . $value_2 . '\', ';
* Creates the cache file.
$file = new Zend_CodeGenerator_Php_File(array(
'docblock' => new Zend_CodeGenerator_Php_Docblock(array(
'shortDescription' => 'Cache file by Mai Lib.',
'longDescription' => 'Cache file generated by Mai_Cache_Words. Part of Mai Lib library (www.mai-ai.org). Usage of words granted by OpenTaal.org',
'description' => date(DATE_RFC822)
'description' => 'http://creativecommons.org/licenses/by/3.0/legalcode'
* Loads the class array from a defined php file.
//Do not show an error message, just return false
//Test the file (it should contain an array named $variableName)
if(isset ($ $variableName) && is_array($ $variableName))
|