Permalink
Browse files

Merge pull request #2 from CloCkWeRX/master

Drop PHP4 style, PEAR dep in favour of exceptions & misc cleanup
  • Loading branch information...
2 parents a7edc9a + e57f918 commit f876a90436270859eadaf42e2e82d36e4659f420 @kouber kouber committed Jul 1, 2012
View
@@ -2,7 +2,7 @@
/**
* Numbers_Words
*
- * PHP version 4
+ * PHP version 5
*
* Copyright (c) 1997-2006 The PHP Group
*
@@ -25,6 +25,7 @@
*/
// {{{ Numbers_Words
+require_once 'Numbers/Words/Exception.php';
/**
* The Numbers_Words class provides method to convert arabic numerals to words.
@@ -80,13 +81,13 @@ function toWords($num, $locale = '', $options = array())
$classname = "Numbers_Words_${locale}";
if (!class_exists($classname)) {
- return Numbers_Words::raiseError("Unable to include the Numbers/Words/lang.${locale}.php file");
+ throw new Numbers_Words_Exception("Unable to include the Numbers/Words/lang.${locale}.php file");
}
$methods = get_class_methods($classname);
if (!in_array('_toWords', $methods) && !in_array('_towords', $methods)) {
- return Numbers_Words::raiseError("Unable to find _toWords method in '$classname' class");
+ throw new Numbers_Words_Exception("Unable to find _toWords method in '$classname' class");
}
if (!is_int($num)) {
@@ -164,13 +165,13 @@ function toCurrency($num, $locale = 'en_US', $int_curr = '')
$classname = "Numbers_Words_${locale}";
if (!class_exists($classname)) {
- return Numbers_Words::raiseError("Unable to include the Numbers/Words/lang.${locale}.php file");
+ throw new Numbers_Words_Exception("Unable to include the Numbers/Words/lang.${locale}.php file");
}
$methods = get_class_methods($classname);
if (!in_array('toCurrencyWords', $methods) && !in_array('tocurrencywords', $methods)) {
- return Numbers_Words::raiseError("Unable to find toCurrencyWords method in '$classname' class");
+ throw new Numbers_Words_Exception("Unable to find toCurrencyWords method in '$classname' class");
}
@$obj = new $classname;
@@ -263,23 +264,6 @@ function getLocales($locale = null)
return $ret;
}
// }}}
-
- // {{{ raiseError()
- /**
- * Trigger a PEAR error
- *
- * To improve performances, the PEAR.php file is included dynamically.
- *
- * @param string $msg error message
- *
- * @return PEAR_Error
- */
- function raiseError($msg)
- {
- include_once 'PEAR.php';
- return PEAR::raiseError($msg);
- }
- // }}}
}
// }}}
@@ -0,0 +1,2 @@
+<?php
+class Numbers_Words_Exception extends Exception {}
@@ -2,7 +2,7 @@
/**
* Numbers_Words
*
- * PHP version 4
+ * PHP version 5
*
* Copyright (c) 1997-2006 The PHP Group
*
@@ -2,7 +2,7 @@
/**
* Numbers_Words
*
- * PHP version 4
+ * PHP version 5
*
* Copyright (c) 1997-2006 The PHP Group
*
@@ -2,7 +2,7 @@
/**
* Numbers_Words
*
- * PHP version 4
+ * PHP version 5
*
* Copyright (c) 1997-2006 The PHP Group
*
@@ -2,7 +2,7 @@
/**
* Numbers_Words
*
- * PHP version 4
+ * PHP version 5
*
* Copyright (c) 1997-2006 The PHP Group
*
@@ -2,7 +2,7 @@
/**
* Numbers_Words
*
- * PHP version 4
+ * PHP version 5
*
* Copyright (c) 1997-2006 The PHP Group
*
@@ -2,7 +2,7 @@
/**
* Numbers_Words
*
- * PHP version 4
+ * PHP version 5
*
* Copyright (c) 1997-2006 The PHP Group
*
@@ -2,7 +2,7 @@
/**
* Numbers_Words
*
- * PHP version 4
+ * PHP version 5
*
* Copyright (c) 1997-2006 The PHP Group
*
@@ -2,7 +2,7 @@
/**
* Numbers_Words
*
- * PHP version 4
+ * PHP version 5
*
* Copyright (c) 1997-2006 The PHP Group
*
@@ -2,7 +2,7 @@
/**
* Numbers_Words
*
- * PHP version 4
+ * PHP version 5
*
* Copyright (c) 1997-2006 The PHP Group
*
@@ -2,7 +2,7 @@
/**
* Numbers_Words
*
- * PHP version 4
+ * PHP version 5
*
* Copyright (c) 1997-2006 The PHP Group
*
@@ -2,7 +2,7 @@
/**
* Numbers_Words
*
- * PHP version 4
+ * PHP version 5
*
* Copyright (c) 1997-2012 The PHP Group
*
@@ -2,7 +2,7 @@
/**
* Numbers_Words
*
- * PHP version 4
+ * PHP version 5
*
* Copyright (c) 1997-2006 The PHP Group
*
@@ -2,7 +2,7 @@
/**
* Numbers_Words
*
- * PHP version 4
+ * PHP version 5
*
* Copyright (c) 1997-2006 The PHP Group
*
@@ -2,7 +2,7 @@
/**
* Numbers_Words
*
- * PHP version 4
+ * PHP version 5
*
* Copyright (c) 1997-2006 The PHP Group
*
@@ -2,7 +2,7 @@
/**
* Numbers_Words
*
- * PHP version 4
+ * PHP version 5
*
* Copyright (c) 1997-2006 The PHP Group
*
@@ -2,7 +2,7 @@
/**
* Numbers_Words
*
- * PHP version 4
+ * PHP version 5
*
* Copyright (c) 1997-2006 The PHP Group
*
@@ -2,7 +2,7 @@
/**
* Numbers_Words
*
- * PHP version 4
+ * PHP version 5
*
* Copyright (c) 1997-2006 The PHP Group
*
@@ -23,7 +23,6 @@
* @link http://pear.php.net/package/Numbers_Words
*/
-require_once "PEAR.php";
require_once "Numbers/Words.php";
/**
@@ -2,7 +2,7 @@
/**
* Numbers_Words
*
- * PHP version 4
+ * PHP version 5
*
* Copyright (c) 1997-2006 The PHP Group
*
@@ -2,7 +2,7 @@
/**
* Numbers_Words
*
- * PHP version 4
+ * PHP version 5
*
* Copyright (c) 1997-2006 The PHP Group
*
@@ -2,7 +2,7 @@
/**
* Numbers_Words
*
- * PHP version 4
+ * PHP version 5
*
* Copyright (c) 1997-2006 The PHP Group
*
@@ -2,7 +2,7 @@
/**
* Numbers_Words
*
- * PHP version 4
+ * PHP version 5
*
* Copyright (c) 1997-2006 The PHP Group
*
@@ -270,7 +270,7 @@ function _toWords($num)
* Testing Range
*/
if (!array_key_exists($index, $this->_exponent)) {
- return Numbers_Words::raiseError('Number out of range.');
+ throw new Numbers_Words_Exception('Number out of range.');
}
/**
@@ -489,7 +489,7 @@ function toCurrencyWords($int_curr, $decimal, $fraction = false, $convert_fracti
* Testing Range
*/
if ($num < 0 || $num > 99) {
- return Numbers_Words::raiseError('Fraction out of range.');
+ throw new Numbers_Words_Exception('Fraction out of range.');
}
/**
@@ -2,7 +2,7 @@
/**
* Numbers_Words
*
- * PHP version 4
+ * PHP version 5
*
* Copyright (c) 1997-2006 The PHP Group
*
@@ -2,7 +2,7 @@
/**
* Numbers_Words
*
- * PHP version 4
+ * PHP version 5
*
* Copyright (c) 1997-2006 The PHP Group
*
@@ -5,7 +5,7 @@
*
* Numbers_Words class extension to spell numbers in Turkish.
*
- * PHP version 4
+ * PHP version 5
*
* This source file is subject to version 3.01 of the PHP license,
* that is bundled with this package in the file LICENSE, and is
@@ -76,7 +76,7 @@ class Numbers_Words_tr_TR extends Numbers_Words
var $_minus = 'eksi';
/**
- * The sufixes for exponents (singular and plural)
+ * The sufixes for exponents - singular only
* @var array
* @access private
*/
@@ -304,13 +304,7 @@ function _toWords($num, $power = 0)
return null;
}
- // if it's only one use the singular suffix
- if (($d == 1) and ($t == 0) and ($h == 0)) {
- $suffix = $lev[0];
- }
- else {
- $suffix = $lev[1];
- }
+ $suffix = $lev[0];
if ($num != 0) {
$ret .= $this->_sep . $suffix;
}
Oops, something went wrong.

0 comments on commit f876a90

Please sign in to comment.