* @author Phergie Development Team <team@phergie.org>
* @license http://phergie.org/license New BSD License
* @link http://pear.phergie.org/package/Phergie_Plugin_Tld
- * @uses Phergie_Plugin_Http pear.phergie.org
* @uses extension PDO
* @uses extension pdo_sqlite
*
* @var PDO
*/
protected $db;
- /**
- * Some fixed TLD values, keys must be lowercase
- * @var array
- */
- protected static $fixedTlds;
/**
* Prepared statement for selecting a single tld
*/
public function onLoad()
{
+ if (!extension_loaded('PDO') || !extension_loaded('pdo_sqlite')) {
+ $this->fail('PDO and pdo_sqlite extensions must be installed');
+ }
+
$help = $this->getPluginHandler()->getPlugin('Help');
$help->register($this);
- if (!is_array(self::$fixedTlds)) {
- self::$fixedTlds = array(
- 'phergie' => 'You can find Phergie at http://www.phergie.org',
- 'spoon' => 'Don\'t you know? There is no spoon!',
- 'poo' => 'Do you really think that\'s funny?',
- 'root' => 'Diagnostic marker to indicate '
- . 'a root zone load was not truncated.'
- );
- }
-
$dbFile = dirname(__FILE__) . '/Tld/tld.db';
try {
$this->db = new PDO('sqlite:' . $dbFile);
*
* @param string $tld TLD to search for
*
- * @return string Definition of the given TLD
+ * @return mixed Definition of the given TLD as a string or false if unknown
*/
public function getTld($tld)
{
$tld = trim(strtolower($tld));
- if (isset(self::$fixedTlds[$tld])) {
- return self::$fixedTlds[$tld];
- } else {
- if ($this->select->execute(array('tld' => $tld))) {
- $tlds = $this->select->fetch();
- if (is_array($tlds)) {
- return '(' . $tlds['type'] . ') ' . $tlds['description'];
- }
+ if ($this->select->execute(array('tld' => $tld))) {
+ $tlds = $this->select->fetch();
+ if (is_array($tlds)) {
+ return '(' . $tlds['type'] . ') ' . $tlds['description'];
}
}
return false;
/**
* Retrieves a list of all the TLDs and their definitions
*
- * @return array Array of all the TLDs and their definitions
+ * @return mixed Array of all the TLDs and their definitions or FALSE on
+ * failure
*/
public function getTlds()
{
. $tld['description'];
}
}
- unset($tlds);
return $tldinfo;
}
}