<commit_before><?php
/* This file provides the SOAP service sapi for the XP framework
 * 
 * $Id$
 */

  uses('xml.soap.rpc.SoapRpcRouter');
  
  define('EPREPEND_IDENTIFIER', "\6100");
  
  // {{{ final class sapisoapservice
  class sapisoapservice {
  
    // {{{ internal string fault(&lang.Throwable exception)
    //     Convert an exception to XML
    function fault(&$exception) {
      $answer= &new SOAPMessage();
      $answer->create('Server', 'Error');

      foreach ($exception->getStackTrace() as $element) {
        $stacktrace[]= $element->toString();
      }

      $answer->setFault(
        HTTP_INTERNAL_SERVER_ERROR,
        $exception->getMessage(),
        getenv('SERVER_NAME').':'.getenv('SERVER_PORT'),
        $stacktrace
      );
      
      header('Content-type: text/xml; charset=iso-8859-1');
      return (
        $answer->getDeclaration()."\n".
        $answer->getSource(0)
      );      
    }

    // {{{ internal string output(string buf)
    //     Output handler
    function output($buf) {
      
      // Check for fatal errors
      if (FALSE !== ($p= strpos($buf, EPREPEND_IDENTIFIER))) {
        return sapisoapservice::fault(new Error(str_replace(EPREPEND_IDENTIFIER, '', substr($buf, $p))));
      }

      // Check for uncaught exceptions
      if ($exceptions= &xp::registry('exceptions')) {
        return sapisoapservice::fault($exceptions[key($exceptions)]);
      }

      return $buf;
    }
    // }}}
    
  }
  // }}}
  
  ini_set('html_errors', 0);
  ini_set('display_errors', 0);
    
  ob_start(array('sapisoapservice', 'output'));
?>
<commit_msg>- Configuration directive "display_errors" must be on for fatal error to be able to work - Add code parameter to fault()   Example XML representation: <faultcode xsi:type="xsd:string">xp.internalerror</faultcode><commit_after><?php
/* This file provides the SOAP service sapi for the XP framework
 * 
 * $Id$
 */

  uses('xml.soap.rpc.SoapRpcRouter');
  
  define('EPREPEND_IDENTIFIER', "\6100");
  
  // {{{ final class sapisoapservice
  class sapisoapservice {
  
    // {{{ internal string fault(&lang.Throwable exception, string code)
    //     Convert an exception to XML
    function fault(&$exception, $code) {
      $answer= &new SOAPMessage();
      $answer->create('Server', 'Error');

      foreach ($exception->getStackTrace() as $element) {
        $stacktrace[]= $element->toString();
      }

      $answer->setFault(
        $code,
        $exception->getMessage(),
        getenv('SERVER_NAME').':'.getenv('SERVER_PORT'),
        $stacktrace
      );
      
      header('Content-type: text/xml; charset=iso-8859-1');
      return (
        $answer->getDeclaration()."\n".
        $answer->getSource(0)
      );      
    }

    // {{{ internal string output(string buf)
    //     Output handler
    function output($buf) {

      // Check for fatal errors
      if (FALSE !== ($p= strpos($buf, EPREPEND_IDENTIFIER))) {
        return sapisoapservice::fault(
          new Error(str_replace(EPREPEND_IDENTIFIER, '', substr($buf, $p))),
          'xp.internalerror'
        );
      }

      // Check for uncaught exceptions
      if ($exceptions= &xp::registry('exceptions')) {
        return sapisoapservice::fault(
          $exceptions[key($exceptions)],
          'xp.uncaughtexception'
        );
      }

      return $buf;
    }
    // }}}
    
  }
  // }}}
  
  ini_set('html_errors', 0);
  ini_set('display_errors', 1);
  ini_set('error_prepend_string', EPREPEND_IDENTIFIER);

  ob_start(array('sapisoapservice', 'output'));
?>

{'fraction_non_alphanumeric': 0.15600448933782268, 'fraction_numerical': 0.006734006734006734, 'mean_word_length': 2.575727181544634, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 4}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1866471', 'n_tokens_mistral': 1132, 'n_tokens_neox': 1095, 'n_words': 219}