QuickBooks/WebConnector/Server.php
public function handle($return = false, $debug = false)
	{
		// Get the raw input
		$input = $this->_input;
		
		// 
		if ($_SERVER['REQUEST_METHOD'] == 'POST')
		{
			$this->_headers();
			
			$output_buffering = false;
			
			/*
			if (isset($this->_hooks[QUICKBOOKS_SERVER_HOOK_PREHANDLE]))
			{
				foreach ($this->_hooks[QUICKBOOKS_SERVER_HOOK_PREHANDLE] as $func)
				{
					$func($input, $this->_callback_config);
				}
			}
			*/
			
			$hook_data = array(
				'input' => $input, 			   
				);
			
			$err = '';
			$this->_callHooks(QUICKBOOKS_SERVER_HOOK_PREHANDLE, null, null, null, $err, $hook_data);
			//QuickBooks_Callbacks::callHook($this->_driver, $this->_hooks, QUICKBOOKS_SERVER_HOOK_PREHANDLE, null, null, null, $err, $hook_data, $this->_callback_config, __FILE__, __LINE__);
			
			if ($this->_loglevel >= QUICKBOOKS_LOG_DEVELOP)
			{
				if (function_exists('apache_request_headers'))
				{
					$headers = '';
					foreach (apache_request_headers() as $header => $value)
					{
						$headers .= $header . ': ' . $value . "\n"; 
					}
					
					//$this->_driver->log('Incoming HTTP Headers: ' . $headers, null, QUICKBOOKS_LOG_DEVELOP);
					$this->_log('Incoming HTTP Headers: ' . $headers, null, QUICKBOOKS_LOG_DEVELOP);
				}
				
				//$this->_driver->log('Incoming SOAP Request: ' . $input, null, QUICKBOOKS_LOG_DEVELOP);
				$this->_log('Incoming SOAP Request: ' . $input, null, QUICKBOOKS_LOG_DEVELOP);
			}
			
			if ($return or isset($this->_hooks[QUICKBOOKS_SERVER_HOOK_POSTHANDLE]))
			{
				$output_buffering = true;
				ob_start();
			}
			
			$this->_server->handle($input);
			
			if ($return or 
				isset($this->_hooks[QUICKBOOKS_SERVER_HOOK_POSTHANDLE]) or 
				$this->_loglevel >= QUICKBOOKS_LOG_DEVELOP)
			{
				$output = '';
				if ($output_buffering)
				{
					$output = ob_get_contents();
					ob_end_flush();
				}
				
				/*
				if (isset($this->_hooks[QUICKBOOKS_SERVER_HOOK_POSTHANDLE]))
				{
					foreach ($this->_hooks[QUICKBOOKS_SERVER_HOOK_POSTHANDLE] as $func)
					{
						$func($output, $this->_callback_config);
					}
				}
				*/
				
				$hook_data = array(
					'input' => $input,
					'output' => $output, 
					);
				
				$err = '';
				$this->_callHooks(QUICKBOOKS_SERVER_HOOK_POSTHANDLE, null, null, null, $err, $hook_data);
				//QuickBooks_Callbacks::callHook($this->_driver, $this->_hooks, QUICKBOOKS_SERVER_HOOK_POSTHANDLE, null, null, null, $err, $hook_data, $this->_callback_config);
				
				if ($this->_loglevel >= QUICKBOOKS_LOG_DEVELOP)
				{
					//$this->_driver->log('Outgoing SOAP Response: ' . $output, null, QUICKBOOKS_LOG_DEVELOP);
					$this->_log('Outgoing SOAP Response: ' . $output, null, QUICKBOOKS_LOG_DEVELOP);
				}
				
				if ($return)
				{
					return $output;
				}
			}
			
			return;
		}
		else if (isset($_GET['WSDL']) or isset($_GET['wsdl']))
		{
			if ($contents = file_get_contents($this->_wsdl))
			{
				$this->_headers();
				print($contents);
				exit;
			}
		}
		else
		{
			$this->_headers();

			print(QUICKBOOKS_PACKAGE_NAME . ' Server v' . QUICKBOOKS_PACKAGE_VERSION . ' at ' . $_SERVER['REQUEST_URI'] . "\n");
			print('   (c) ' . QUICKBOOKS_PACKAGE_AUTHOR . ' ' . "\n");
			print('   Visit us at: ' . QUICKBOOKS_PACKAGE_WEBSITE . ' ' . "\n");
			print("\n");
			print('Use the QuickBooks Web Connector to access this SOAP server.' . "\n");
			print("\n");
			
			if ($debug)
			{
				print(get_class($this) . str_replace(__CLASS__, '', __METHOD__) . '() parameters: ' . "\n");
				print(' - $return = ' . $return . "\n");
				print(' - $debug  = ' . $debug . "\n");
				print("\n");
				print('Misc. information: ' . "\n");
				print(' - Logging: ' . $this->_loglevel . "\n");
				
				if (function_exists('date_default_timezone_get'))
				{
					print(' - Timezone: ' . date_default_timezone_get() . ' (Auto-set: ');
					
					if (QUICKBOOKS_TIMEZONE_AUTOSET)
					{
						print('Yes');
					}
					
					print(')' . "\n");
				}
				print(' - Current Date/Time: ' . date('Y-m-d H:i:s') . "\n");
				print(' - Error Reporting: ' . error_reporting() . "\n");
				
				print("\n");
				print('SOAP adapter: ' . "\n");
				print(' - ' . get_class($this->_server) . "\n");
				print("\n");
				print('Registered handler functions: ' . "\n");
				print_r($this->_server->getFunctions());
				
				/*
				print("\n");
				print('Registered hooks: ' . "\n");
				//print_r($this->_hooks);		// This is bad because it prints passwords
				foreach ($this->_hooks as $hook => $arr)
				{
					if (!is_array($arr))
					{
						continue;
					}
					
					print(' - ' . $hook . QUICKBOOKS_CRLF);
					foreach ($arr as $x)
					{
						$y = current(explode("\n", print_r($x, true)));
						
						print('    ' . $y . QUICKBOOKS_CRLF);
					}
				}
				*/
				
				print("\n");
				print('Detected input: ' . "\n");
				print($input);
				print("\n");
				print("\n");
				print('Timestamp: ' . "\n");
				print(' - ' . date('Y-m-d H:i:s') . ' -- process ' . round(microtime(true) - QUICKBOOKS_TIMESTAMP, 5) . "\n");
			}
			
			return;
		}
	}
public function handle($return = false, $debug = false)
	{
		// Get the raw input
		$input = $this->_input;
		
		// 
		if ($_SERVER['REQUEST_METHOD'] == 'POST')
		{
			$this->_headers();
			
			$output_buffering = false;
			
			/*
			if (isset($this->_hooks[QUICKBOOKS_SERVER_HOOK_PREHANDLE]))
			{
				foreach ($this->_hooks[QUICKBOOKS_SERVER_HOOK_PREHANDLE] as $func)
				{
					$func($input, $this->_callback_config);
				}
			}
			*/
			
			$hook_data = array(
				'input' => $input, 			   
				);
			
			$err = '';
			$this->_callHooks(QUICKBOOKS_SERVER_HOOK_PREHANDLE, null, null, null, $err, $hook_data);
			//QuickBooks_Callbacks::callHook($this->_driver, $this->_hooks, QUICKBOOKS_SERVER_HOOK_PREHANDLE, null, null, null, $err, $hook_data, $this->_callback_config, __FILE__, __LINE__);
			
			if ($this->_loglevel >= QUICKBOOKS_LOG_DEVELOP)
			{
				if (function_exists('apache_request_headers'))
				{
					$headers = '';
					foreach (apache_request_headers() as $header => $value)
					{
						$headers .= $header . ': ' . $value . "\n"; 
					}
					
					//$this->_driver->log('Incoming HTTP Headers: ' . $headers, null, QUICKBOOKS_LOG_DEVELOP);
					$this->_log('Incoming HTTP Headers: ' . $headers, null, QUICKBOOKS_LOG_DEVELOP);
				}
				
				//$this->_driver->log('Incoming SOAP Request: ' . $input, null, QUICKBOOKS_LOG_DEVELOP);
				$this->_log('Incoming SOAP Request: ' . $input, null, QUICKBOOKS_LOG_DEVELOP);
			}
			
			if ($return or isset($this->_hooks[QUICKBOOKS_SERVER_HOOK_POSTHANDLE]))
			{
				$output_buffering = true;
				ob_start();
			}
			
			$this->_server->handle($input);
			
			if ($return or 
				isset($this->_hooks[QUICKBOOKS_SERVER_HOOK_POSTHANDLE]) or 
				$this->_loglevel >= QUICKBOOKS_LOG_DEVELOP)
			{
				$output = '';
				if ($output_buffering)
				{
					$output = ob_get_contents();
					ob_end_flush();
				}
				
				/*
				if (isset($this->_hooks[QUICKBOOKS_SERVER_HOOK_POSTHANDLE]))
				{
					foreach ($this->_hooks[QUICKBOOKS_SERVER_HOOK_POSTHANDLE] as $func)
					{
						$func($output, $this->_callback_config);
					}
				}
				*/
				
				$hook_data = array(
					'input' => $input,
					'output' => $output, 
					);
				
				$err = '';
				$this->_callHooks(QUICKBOOKS_SERVER_HOOK_POSTHANDLE, null, null, null, $err, $hook_data);
				//QuickBooks_Callbacks::callHook($this->_driver, $this->_hooks, QUICKBOOKS_SERVER_HOOK_POSTHANDLE, null, null, null, $err, $hook_data, $this->_callback_config);
				
				if ($this->_loglevel >= QUICKBOOKS_LOG_DEVELOP)
				{
					//$this->_driver->log('Outgoing SOAP Response: ' . $output, null, QUICKBOOKS_LOG_DEVELOP);
					$this->_log('Outgoing SOAP Response: ' . $output, null, QUICKBOOKS_LOG_DEVELOP);
				}
				
				if ($return)
				{
					return $output;
				}
			}
			
			return;
		}
		else if (isset($_GET['WSDL']) or isset($_GET['wsdl']))
		{
			if ($contents = file_get_contents($this->_wsdl))
			{
				$this->_headers();
				print($contents);
				exit;
			}
		}
		else
		{
			$this->_headers();

			print(QUICKBOOKS_PACKAGE_NAME . ' Server v' . QUICKBOOKS_PACKAGE_VERSION . ' at ' . $_SERVER['REQUEST_URI'] . "\n");
			print('   (c) ' . QUICKBOOKS_PACKAGE_AUTHOR . ' ' . "\n");
			print('   Visit us at: ' . QUICKBOOKS_PACKAGE_WEBSITE . ' ' . "\n");
			print("\n");
			print('Use the QuickBooks Web Connector to access this SOAP server.' . "\n");
			print("\n");
			
			if ($debug)
			{
				print(get_class($this) . str_replace(__CLASS__, '', __METHOD__) . '() parameters: ' . "\n");
				print(' - $return = ' . $return . "\n");
				print(' - $debug  = ' . $debug . "\n");
				print("\n");
				print('Misc. information: ' . "\n");
				print(' - Logging: ' . $this->_loglevel . "\n");
				
				if (function_exists('date_default_timezone_get'))
				{
					print(' - Timezone: ' . date_default_timezone_get() . ' (Auto-set: ');
					
					if (QUICKBOOKS_TIMEZONE_AUTOSET)
					{
						print('Yes');
					}
					
					print(')' . "\n");
				}
				print(' - Current Date/Time: ' . date('Y-m-d H:i:s') . "\n");
				print(' - Error Reporting: ' . error_reporting() . "\n");
				
				print("\n");
				print('SOAP adapter: ' . "\n");
				print(' - ' . get_class($this->_server) . "\n");
				print("\n");
				print('Registered handler functions: ' . "\n");
				print_r($this->_server->getFunctions());
				
				/*
				print("\n");
				print('Registered hooks: ' . "\n");
				//print_r($this->_hooks);		// This is bad because it prints passwords
				foreach ($this->_hooks as $hook => $arr)
				{
					if (!is_array($arr))
					{
						continue;
					}
					
					print(' - ' . $hook . QUICKBOOKS_CRLF);
					foreach ($arr as $x)
					{
						$y = current(explode("\n", print_r($x, true)));
						
						print('    ' . $y . QUICKBOOKS_CRLF);
					}
				}
				*/
				
				print("\n");
				print('Detected input: ' . "\n");
				print($input);
				print("\n");
				print("\n");
				print('Timestamp: ' . "\n");
				print(' - ' . date('Y-m-d H:i:s') . ' -- process ' . round(microtime(true) - QUICKBOOKS_TIMESTAMP, 5) . "\n");
			}
			
			return;
		}
	}
Handle the SOAP request

@param boolean $return
@param boolean $debug
@return void