Ejemplo n.º 1
0
 /**
  * 
  * 
  * @todo Support for object instance error handlers
  * 
  */
 public static function callErrorHandler($Driver, $errmap, $errnum, $errmsg, $user, $requestID, $action, $ident, $extra, &$errerr, $xml, $callback_config)
 {
     // $Driver, &$map, $action, $which, $user, $action, $ident, $extra, &$err, $last_action_time, $last_actionident_time, $xml_or_version = '', $qb_identifier_or_locale = array(), $callback_config = array(), $qbxml = null
     // Build the requestID
     //$requestID = QuickBooks_Utilities::constructRequestID($action, $ident);
     $callback = '';
     /*if (is_object($this->_instance_onerror) and 
     			method_exists($this->_instance_onerror, 'e' . $errnum))
     		{
     			$func = get_class($this->_instance_onerror) . '->e' . $errnum;
     		}*/
     //else
     if (isset($errmap[$errnum])) {
         $callback = $errmap[$errnum];
     } else {
         if (isset($errmap[$action])) {
             $callback = $errmap[$action];
         } else {
             if (isset($errmap['!'])) {
                 $callback = $errmap['!'];
             } else {
                 if (isset($errmap['*'])) {
                     $callback = $errmap['*'];
                 }
             }
         }
     }
     // Determine the type of hook
     $type = QuickBooks_Callbacks::_type($callback, $Driver, null);
     $vars = array($requestID, $user, $action, $ident, $extra, &$errerr, $xml, $errnum, $errmsg, $callback_config);
     $errerr = '';
     if ($type == QUICKBOOKS_CALLBACKS_TYPE_OBJECT_METHOD) {
         $Driver->log('Object method error handler: ' . get_class($callback[0]) . '->' . $callback[1], null, QUICKBOOKS_LOG_VERBOSE);
         $errerr = '';
         $continue = QuickBooks_Callbacks::_callObjectMethod($callback, $vars, $errerr, 5);
         if ($errerr) {
             $Driver->log('Error handler returned an error: ' . $errerr, null, QUICKBOOKS_LOG_NORMAL);
             return false;
         }
     } else {
         if ($type == QUICKBOOKS_CALLBACKS_TYPE_FUNCTION) {
             // It's a callback FUNCTION
             $Driver->log('Function error handler: ' . $callback, null, QUICKBOOKS_LOG_VERBOSE);
             $errerr = '';
             // This is an error message *returned by* the error handler function
             $continue = QuickBooks_Callbacks::_callFunction($callback, $vars, $errerr, 5);
             //$continue = $func($requestID, $user, $action, $ident, $extra, $errerr, $xml, $errnum, $errmsg, $callback_config);
             if ($errerr) {
                 $Driver->log('Error handler returned an error: ' . $errerr, null, QUICKBOOKS_LOG_NORMAL);
                 return false;
             }
         } else {
             if ($type == QUICKBOOKS_CALLBACKS_TYPE_STATIC_METHOD) {
                 // It's a callback STATIC METHOD
                 //$tmp = explode('::', $func);
                 //$class = trim(current($tmp));
                 //$method = trim(end($tmp));
                 $Driver->log('Static method error handler: ' . $callback, null, QUICKBOOKS_LOG_VERBOSE);
                 $errerr = '';
                 $continue = QuickBooks_Callbacks::_callStaticMethod($callback, $vars, $errerr, 5);
                 if ($errerr) {
                     $Driver->log('Error handler returned an error: ' . $errerr, null, QUICKBOOKS_LOG_NORMAL);
                     return false;
                 }
             } else {
                 return false;
             }
         }
     }
     return $continue;
 }
Ejemplo n.º 2
0
 /**
  * 
  * 
  * @todo Support for object instance callbacks
  */
 protected static function _callRequestOrResponseHandler($Driver, &$map, $action, $which, $user, $action, $ident, $extra, &$err, $last_action_time, $last_actionident_time, $xml_or_version = '', $qb_identifier_or_locale = array(), $callback_config = array(), $qbxml = null)
 {
     //print_r($map);
     //print('action: ' . $action . "\n");
     //print('which: ' . $which . "\n");
     if (isset($map[$action])) {
         $tmp =& $map[$action];
     } else {
         if (isset($map['*'])) {
             $tmp =& $map['*'];
         } else {
             $tmp = null;
         }
     }
     // Call the appropriate callback function
     if (is_array($tmp)) {
         if (isset($tmp[$which])) {
             $callback = $tmp[$which];
             //$class = '';
             //$method = '';
             /*if (false !== strpos($func, '::'))
             		{
             			$tmp = explode('::', $func);
             			$class = current($tmp);
             			$method = end($tmp);
             		}*/
             $type = QuickBooks_Callbacks::_type($callback, $Driver, null);
             $requestID = QuickBooks_Utilities::constructRequestID($action, $ident);
             $vars = array($requestID, $user, $action, $ident, $extra, &$err, $last_action_time, $last_actionident_time, $xml_or_version, $qb_identifier_or_locale, $callback_config, $qbxml);
             // $class and $method and method_exists($class, $method))
             if ($type == QUICKBOOKS_CALLBACKS_TYPE_OBJECT_METHOD) {
                 $xml = QuickBooks_Callbacks::_callObjectMethod($callback, $vars, $err);
                 return $xml;
             } else {
                 if ($type == QUICKBOOKS_CALLBACKS_TYPE_STATIC_METHOD) {
                     $err = '';
                     //if (version_compare(PHP_VERSION, '5.3.0', '>='))
                     //{
                     //	$xml = $class::$method($requestID, $user, $action, $ident, $extra, $err, $xml, $qb_identifier);
                     //}
                     //else
                     //{
                     $xml = QuickBooks_Callbacks::_callStaticMethod($callback, $vars, $err);
                     //$xml = call_user_func(array( $class, $method ), $requestID, $user, $action, $ident, $extra, $err, $last_action_time, $last_actionident_time, $xml_or_version, $qb_identifier_or_locale, $callback_config, $qbxml);
                     //}
                     return $xml;
                 } else {
                     if ($type == QUICKBOOKS_CALLBACKS_TYPE_FUNCTION) {
                         $err = '';
                         $xml = QuickBooks_Callbacks::_callFunction($callback, $vars, $err);
                         //$xml = $func($requestID, $user, $action, $ident, $extra, $err, $last_action_time, $last_actionident_time, $xml_or_version, $qb_identifier_or_locale, $callback_config, $qbxml);
                         return $xml;
                     } else {
                         // A function was registered, but the function doesn't exist
                         $err = 'Unknown callback type for: ' . $tmp[$which];
                     }
                 }
             }
             if ($err) {
                 $Driver->log('A request handler returned an error: ' . $err);
             }
         } else {
             // There was no function registered for that action and request/response
             $err = 'No function handlers for action: ' . $action;
         }
     } else {
         // There are *no* functions registered for that action
         $err = 'No registered functions for action: ' . $action;
     }
     return '';
 }