00001 <?php
00044 class Zend_Crypt_Math_BigInteger
00045 {
00046
00052 protected $_math = null;
00053
00062 public function __construct($extension = null)
00063 {
00064 if (!is_null($extension) && !in_array($extension, array('bcmath', 'gmp', 'bigint'))) {
00065 require_once('Zend/Crypt/Math/BigInteger/Exception.php');
00066 throw new Zend_Crypt_Math_BigInteger_Exception('Invalid extension type; please use one of bcmath, gmp or bigint');
00067 }
00068 $this->_loadAdapter($extension);
00069 }
00070
00078 public function __call($methodName, $args)
00079 {
00080 if(!method_exists($this->_math, $methodName)) {
00081 require_once 'Zend/Crypt/Math/BigInteger/Exception.php';
00082 throw new Zend_Crypt_Math_BigInteger_Exception('invalid method call: ' . get_class($this->_math) . '::' . $methodName . '() does not exist');
00083 }
00084 return call_user_func_array(array($this->_math, $methodName), $args);
00085 }
00086
00091 protected function _loadAdapter($extension = null)
00092 {
00093 if (is_null($extension)) {
00094 if (extension_loaded('gmp')) {
00095 $extension = 'gmp';
00096
00097
00098 } else {
00099 $extension = 'bcmath';
00100 }
00101 }
00102 if($extension == 'gmp' && extension_loaded('gmp')) {
00103 require_once 'Zend/Crypt/Math/BigInteger/Gmp.php';
00104 $this->_math = new Zend_Crypt_Math_BigInteger_Gmp();
00105
00106
00107
00108 } elseif ($extension == 'bcmath') {
00109 require_once 'Zend/Crypt/Math/BigInteger/Bcmath.php';
00110 $this->_math = new Zend_Crypt_Math_BigInteger_Bcmath();
00111 } else {
00112 require_once 'Zend/Crypt/Math/BigInteger/Exception.php';
00113 throw new Zend_Crypt_Math_BigInteger_Exception($extension . ' big integer precision math support not detected');
00114 }
00115 }
00116
00117 }