<?php
/**
 * This file is part of the mobileOK Pythia plug-in for Joomla! and defines the
 * {@link WURFLServiceConfiguration} class.
 * 
 * @author Sylvain Lequeux
 * @author Francois Daoust <fd@w3.org>
 * @package mobileOKPythia
 * @subpackage Joomla
 * @version $Revision: 1.4 $
 * @license http://www.gnu.org/licenses/gpl.html GNU General Public License v3 or later
 * @copyright Copyright (c) 2009, W3C (MIT, ERCIM, Keio)
 */

require_once(dirname(__FILE__) . '/../common/plugins/DDRServiceConfigurationFactory.php');
require_once(dirname(__FILE__) . '/../common/ddrsimpleapi/interface/systemException.php');


/**
 * The WURFLServiceConfiguration class defines the settings required
 * to instantiate a working {@link WURFLService}.   
 *
 * @author Sylvain Lequeux
 * @author Francois Daoust <fd@w3.org>
 * @package mobileOKPythia
 * @subpackage Joomla
 * @version $Revision: 1.4 $
 * @license http://www.gnu.org/licenses/gpl.html GNU General Public License v3 or later
 * @copyright Copyright (c) 2009, W3C (MIT, ERCIM, Keio)
 */
class WURFLServiceConfiguration implements DDRServiceConfiguration {
	/**
	 * @var array A pointer to the plug-ins parameters
	 */
	private $params;
	
	/**
	 * Constructor of the class.
	 * 
	 * @param JParameter $params The list of parameters of the plug-in
	 * @return WURFLServiceConfiguration Created instance.
	 */
	function WURFLServiceConfiguration($params) {
		$this->params = $params;
	}
	
	/**
	 * Retrieves the configuration settings to use to instantiate
	 * a {@link WURFLService}. The method throws an exception when
	 * the path to the WURFL database is incorrect. 
	 * 
	 * @return array<string=>string> An array with a 'wurfl_path'
	 *   key whose value is the path to the folder that contains
	 *   the prepared WURFL database.
	 */
	function getConfig() {
		$path = $this->params->get('mobileOKPythia_wurfl_path');
		
		// Make sure the path ends up with a '/'
		$lastChar = substr($path, strlen($path) -1);
		if($lastChar != '/' && $lastChar != '\\'){
			$path .= '/';
		}
		
		if(!file_exists($path)){
			throw new SystemException(
					"The path to the WURFL database does not exist",
					SystemException::$CANNOT_PROCEED
				);
		}
		return array('wurfl_path' => $path);
	}
	
	function addOptions() {
	}
	
	function printOptions() {
	}
	
	function getOptions() {
		return "mobileOKPythia_wurfl_path,";
	}
}
?>