Ejemplo n.º 1
0
 public function __construct($message, $code = 0, $field = null, Exception $previousException = null)
 {
     parent::__construct($message, $code, $previousException);
     if ($field) {
         $this->setField($field);
     }
 }
Ejemplo n.º 2
0
 public static function checkResponseData($response, $mustcheck_data, $specs)
 {
     $resp_keys = array();
     foreach ($specs as $name => $spec) {
         list($maxlen, $required, $mustcheck, $is_response, $regexp) = $spec;
         if ($required && !isset($response[$name])) {
             $e = new WebToPayException(self::_("'%s' is required but missing.", $name), WebToPayException::E_MISSING);
             $e->setField($name);
             throw $e;
         }
         if ($mustcheck) {
             if (!isset($mustcheck_data[$name])) {
                 $e = new WebToPayException(self::_("'%s' must exists in array of second parameter " . "of checkResponse() method.", $name), WebToPayException::E_USER_PARAMS);
                 $e->setField($name);
                 throw $e;
             }
             if ($is_response) {
                 if ($response[$name] != $mustcheck_data[$name]) {
                     $e = new WebToPayException(self::_("'%s' yours and requested value is not " . "equal ('%s' != '%s') ", $name, $mustcheck_data[$name], $response[$name]), WebToPayException::E_INVALID);
                     $e->setField($name);
                     throw $e;
                 }
             }
         }
         if (!empty($response[$name])) {
             if ($maxlen && strlen($response[$name]) > $maxlen) {
                 $e = new WebToPayException(self::_("'%s' value '%s' is too long, %d characters allowed.", $name, $response[$name], $maxlen), WebToPayException::E_MAXLEN);
                 $e->setField($name);
                 throw $e;
             }
             if ('' != $regexp && !preg_match($regexp, $response[$name])) {
                 $e = new WebToPayException(self::_("'%s' value '%s' is invalid.", $name, $response[$name]), WebToPayException::E_REGEXP);
                 $e->setField($name);
                 throw $e;
             }
         }
         if (isset($response[$name])) {
             $resp_keys[] = $name;
         }
     }
     // Filter only parameters passed from webtopay
     $_response = array();
     foreach (array_keys($response) as $key) {
         if (in_array($key, $resp_keys)) {
             $_response[$key] = $response[$key];
         }
     }
     return $_response;
 }