[ Index ]
 

Code source de eZ Publish 3.9.0

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/lib/ezsoap/classes/ -> ezsoapserver.php (source)

   1  <?php
   2  //
   3  // Definition of eZSOAPServer class
   4  //
   5  // Created on: <14-May-2002 10:45:38 bf>
   6  //
   7  // SOFTWARE NAME: eZ publish
   8  // SOFTWARE RELEASE: 3.9.0
   9  // BUILD VERSION: 17785
  10  // COPYRIGHT NOTICE: Copyright (C) 1999-2006 eZ systems AS
  11  // SOFTWARE LICENSE: GNU General Public License v2.0
  12  // NOTICE: >
  13  //   This program is free software; you can redistribute it and/or
  14  //   modify it under the terms of version 2.0  of the GNU General
  15  //   Public License as published by the Free Software Foundation.
  16  //
  17  //   This program is distributed in the hope that it will be useful,
  18  //   but WITHOUT ANY WARRANTY; without even the implied warranty of
  19  //   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  20  //   GNU General Public License for more details.
  21  //
  22  //   You should have received a copy of version 2.0 of the GNU General
  23  //   Public License along with this program; if not, write to the Free
  24  //   Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
  25  //   MA 02110-1301, USA.
  26  //
  27  //
  28  
  29  /*!
  30    \class eZSOAPServer ezsoapserver.php
  31    \ingroup eZSOAP
  32    \brief The class eZSOAPServer handles SOAP server requensts
  33  
  34    Sample code for a SOAP server with one function, addNumbers.
  35    \code
  36  include_once( "lib/ezsoap/classes/ezsoapserver.php" );
  37  
  38  $server = new eZSOAPServer( );
  39  $server->registerFunction( "addNumbers", array( "valueA" => "integer", "valueB" => "integer" ) );
  40  $server->registerObject( "Collection" );
  41  $server->processRequest();
  42  
  43  function addNumbers( $valueA, $valueB )
  44  {
  45      $return = $valueA + $valueB;
  46      settype( $return, "integer" );
  47      return $return;
  48  }
  49  
  50  class Collection
  51  {
  52      function Collection ()
  53      {
  54  
  55      }
  56      function subNumbers( $valueA, $valueB )
  57      {
  58          $return = $valueA - $valueB;
  59          settype( $return, "integer" );
  60          return $return;
  61      }
  62  }
  63    \endcode
  64    \sa eZSOAPClient eZSOAPRequest eZSOAPResponse
  65  
  66  */
  67  
  68  include_once ( "lib/ezsoap/classes/ezsoaprequest.php" );
  69  include_once ( "lib/ezsoap/classes/ezsoapfault.php" );
  70  include_once ( "lib/ezsoap/classes/ezsoapresponse.php" );
  71  include_once ( "lib/ezxml/classes/ezxml.php" );
  72  
  73  class eZSOAPServer
  74  {
  75      /*!
  76        Creates a new eZSOAPServer object.
  77      */
  78      function eZSOAPServer()
  79      {
  80          global $HTTP_RAW_POST_DATA;
  81          $this->RawPostData = $HTTP_RAW_POST_DATA;
  82      }
  83  
  84  
  85      function showResponse( $functionName, $namespaceURI, &$value )
  86      {
  87          // Convert input data to XML
  88          $response = new eZSOAPResponse( $functionName, $namespaceURI );
  89          $response->setValue( $value );
  90  
  91          $payload = $response->payload();
  92  
  93          header( "SOAPServer: eZ soap" );
  94          header( "Content-Type: text/xml; charset=\"UTF-8\"" );
  95          Header( "Content-Length: " . strlen( $payload ) );
  96  
  97          if ( ob_get_length() )
  98              ob_end_clean();
  99  
 100          print( $payload );
 101      }
 102  
 103      /*!
 104        Registers all functions of an object on the server.
 105  
 106        Returns false if the object could not be registered.
 107      */
 108      function registerObject( $objectName, $includeFile = null )
 109      {
 110          if ( file_exists( $includeFile ) )
 111              include_once( $includeFile );
 112  
 113          if ( class_exists( $objectName ) )
 114          {
 115              $methods = get_class_methods( $objectName );
 116              foreach ( $methods as $method)
 117              {
 118                  if ( strcasecmp ( $objectName, $method ) )
 119                      $this->registerFunction( $objectName."::".$method );
 120              }
 121              return true;
 122          }
 123          else
 124          {
 125              return false;
 126          }
 127      }
 128  
 129      /*!
 130        Processes the SOAP request and prints out the
 131        propper response.
 132      */
 133      function processRequest()
 134      {
 135          global $HTTP_SERVER_VARS;
 136  
 137          if ( $HTTP_SERVER_VARS["REQUEST_METHOD"] != "POST" )
 138          {
 139              print( "Error: this web page does only understand POST methods" );
 140              exit();
 141          }
 142  
 143          $xmlData = $this->stripHTTPHeader( $this->RawPostData );
 144  
 145          $xml = new eZXML();
 146  
 147          $dom = $xml->domTree( $xmlData );
 148  
 149          // Check for non-parsing XML, to avoid call to non-object error.
 150          if ( !is_object( $dom ) )
 151          {
 152              $this->showResponse( 'unknown_function_name', 'unknown_namespace_uri',
 153                                   new eZSOAPFault( 'Server Error',
 154                                                    'Bad XML' ) );
 155              return;
 156          }
 157  
 158          // add namespace fetching on body
 159          // get the SOAP body
 160          $body = $dom->elementsByName( "Body" );
 161  
 162          $children = $body[0]->children();
 163  
 164          if ( count( $children ) == 1 )
 165          {
 166              $requestNode = $children[0];
 167              // get target namespace for request
 168              $functionName = $requestNode->name();
 169              $namespaceURI = $requestNode->namespaceURI();
 170  
 171              $params = array();
 172              // check parameters
 173              foreach ( $requestNode->children() as $parameterNode )
 174              {
 175                  $params[] = eZSOAPResponse::decodeDataTypes( $parameterNode );
 176              }
 177  
 178              list( $objectName, $objectFunctionName ) = preg_split('/::/', $functionName, 2, PREG_SPLIT_NO_EMPTY);
 179              if ( !$objectFunctionName and in_array( $functionName, $this->FunctionList ) &&
 180                   function_exists( $functionName ) )
 181              {
 182                  $this->showResponse( $functionName, $namespaceURI,
 183                                       call_user_func_array( $functionName, $params ) );
 184              }
 185              else if ( $objectName and $objectFunctionName )
 186              {
 187                  if ( !class_exists( $objectName ) )
 188                  {
 189                      $this->showResponse( $functionName, $namespaceURI,
 190                                           new eZSOAPFault( 'Server Error',
 191                                                            'Object not found' ) );
 192                  }
 193                  else
 194                  {
 195                      $object = new $objectName();
 196                      if ( !method_exists( $object, $objectFunctionName ) )
 197                      {
 198                          $this->showResponse( $functionName, $namespaceURI,
 199                                       new eZSOAPFault( 'Server Error',
 200                                                        'Objectmethod not found' ) );
 201                      }
 202                      else
 203                      {
 204                          $this->showResponse( $functionName, $namespaceURI,
 205                                       call_user_func_array( array( $object, $objectFunctionName ), $params ) );
 206                      }
 207                  }
 208              }
 209              else
 210              {
 211                  $this->showResponse( $functionName, $namespaceURI,
 212                                       new eZSOAPFault( 'Server Error',
 213                                                        'Method not found' ) );
 214              }
 215          }
 216          else
 217          {
 218              // error
 219              $this->showResponse( $functionName, $namespaceURI,
 220                                   new eZSOAPFault( 'Server Error',
 221                                                    '"Body" element in the request '.
 222                                                    'has wrong number of children' ) );
 223  
 224          }
 225      }
 226  
 227      /*!
 228        Registers a new function on the server.
 229  
 230        Returns false if the function could not be registered.
 231      */
 232      function registerFunction( $name, $params=array() )
 233      {
 234          $this->FunctionList[] = $name;
 235      }
 236  
 237  
 238      /*!
 239        \static
 240        \private
 241        Strips the header information from the HTTP raw response.
 242      */
 243      function stripHTTPHeader( $data )
 244      {
 245          $start = strpos( $data, "<?xml version=\"1.0\"?>" );
 246          return substr( $data, $start, strlen( $data ) - $start );
 247      }
 248  
 249      /// Contains a list over registered functions
 250      var $FunctionList;
 251      /// Contains the RAW HTTP post data information
 252      var $RawPostData;
 253  }
 254  
 255  ?>


Généré le : Sat Feb 24 10:30:04 2007 par Balluche grâce à PHPXref 0.7