<?php
/**
* Author: Kevin Hagel <hide@address.com>
* Since: April 28, 2004
* Requires: PEAR.php, Config.php, class.ianacclister.php
*
* Both writes and reads a country-codes.xml file. I suggest running
* the writeConfig once, and then after that only rarely - for example
* when you're sure that the IANA database has changed.
*
* Once the file exists, you can use this class to read from that
* config file, and have an array keyed by the country code, for
* example with "us"
*
* array['us'] = array("name" => "United States",
* "page" => "http://www.iana.org/root-whois/us.htm"
*
* Usage(s):
*
* CountryConfig::writeConfig($yourXMLFile);
*
* $countryArray = CountryConfig::readConfig($yourXMLFile);
*
* Note: be sure you have write permission in the destination directory.
*/
require_once "PEAR.php";
require_once "Config.php";
require_once "class.ianacclister.php";
class CountryConfig {
/**
* Initialize
*/
function CountryConfig()
{
}
/**
* Output the country codes to the file.
*
*/
function writeConfig($destFile = "country-codes.xml")
{
$c = new Config();
$hash =& ianacclister::getHash();
$root =& $c->parseConfig($hash,'PHPArray');
$root->setName("countries");
$c->writeConfig($destFile,"XML");
}
/**
* Read country code configuration from an existing file.
* Returns PEAR_ERROR on error, TRUE no success
*
*/
function &readConfig($file)
{
$config = new Config();
$root =& $config->parseConfig($file,"XML");
if ( PEAR::isError($root) ) {
return $root;
}
$countries =& $root->getItem("section","conf");
$countriesConf =& $countries->toArray();
return $countriesConf['conf'];
}
} // class CountryConfig
?>