[ Index ]
 

Code source de SPIP Agora 1.4

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

title

Body

[fermer]

/Agora1-4/ecrire/include/ws/ -> soap.php (source)

   1  <?php
   2  /*****************************************************
   3  * This file is part of Agora, web based content management system.
   4  *
   5  * Agora is free software; you can redistribute it and/or modify
   6  * it under the terms of the GNU General Public License as published by
   7  * the Free Software Foundation; version 2 of the License.
   8  *
   9  * Agora is distributed in the hope that it will be useful,
  10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12  * GNU General Public License for more details (file "COPYING").
  13  *
  14  * Copyright © Arnaud Martin, Antoine Pitrou et Philippe Rivière.
  15  * List of authors detailed in "copyright_fr.html" file.
  16  * E-mail : agora@sig.premier-ministre.gouv.fr
  17  * Web site : http://www.agora.gouv.fr
  18  *****************************************************/
  19  /**
  20   * Serveur SOAP pour SPIP-Agora.
  21   * On expose les fonctionnalités des classes métiers.
  22   *
  23   * Les services exposés sont définis dans include/bd/<metier>_ws.php
  24   *
  25   * 
  26   * 
  27   * @version      $Id$
  28   * @author       Tristan Rivoallan <trivoallan@clever-age.com>
  29   */
  30  
  31  // !!
  32  set_include_path(get_include_path(). ':' . '/usr/share/pear');
  33  
  34  main();
  35  
  36  function main () {
  37      error_reporting(E_ALL ^ E_NOTICE);
  38  
  39      // Traitement du PATH_INFO
  40      $ressource = explode('/', $_SERVER['PATH_INFO']);
  41  
  42      if (count($ressource) < 3) {
  43          die('NOT IMPLEMENTED YET.');
  44      }
  45  
  46      // Ressource accédée
  47      $ressource_type = $ressource[1]; // Type
  48      $ressource_id = $ressource[2];   // Identifiant
  49  
  50      require_once("SOAP/Server.php");
  51  
  52      // Chemin vers le répertoire des classes métier
  53      $daos_path = dirname(__FILE__). '/../bd';
  54  
  55      // Instanciation du serveur SOAP
  56      $soap_srv = &new SOAP_Server;
  57  
  58      // Environnement
  59      $class_factory_path = sprintf('%s/inc_%s_factory.php', $daos_path, $ressource_type);
  60      $class_factory_func = sprintf('recuperer_instance_%s', $ressource_type);
  61      $class_ws_path = sprintf('%s/%s_ws.php', $daos_path, $ressource_type);
  62      $class_ws_name = sprintf('Agora_Webservice_%s', ucfirst($ressource_type));
  63      $class_namespace = sprintf('%s/ns', 'http://agora.gouv.fr');
  64  
  65      // Instanciation de la classe métier
  66      require_once $class_factory_path;
  67      $obj_metier = &$class_factory_func();
  68  
  69      // On ne recherche pas la ressource lorsque le client demande le contrat WSDL
  70      if (!eregi("\?wsdl$", $_SERVER['REQUEST_URI'])) {
  71          // Définition des services exposés
  72          $status = $obj_metier->load($ressource_id);
  73          if (PEAR::isError($status)) {
  74              require_once("SOAP/Fault.php");
  75              $faultcode = $status->getCode();
  76              $faultstring = htmlentities($status->getMessage());
  77              $faultactor = null;
  78              $detail = null;
  79              $fault = &new SOAP_Fault($faultstring, $faultcode, $faultactor, $detail);
  80  
  81              header('Content-type: text/xml');
  82              echo $fault->message();
  83              exit;
  84          }
  85      }
  86  
  87      require $class_ws_path;
  88      $obj_ws = &new $class_ws_name($obj_metier);
  89      $soap_srv->addObjectMap($obj_ws, $class_namespace);
  90  
  91      /* Démarrage du serveur SOAP
  92       * Si la requête est de type POST, on démarre le serveur SOAP.
  93       * Si la requête est de type GET et contient 'wsdl', on renvoie le contrat WSDL
  94       * du serveur SOAP.
  95       * Sinon on renvoie le document DISCO.
  96       */
  97      if (isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] == 'POST') {
  98          $soap_srv->service($GLOBALS['HTTP_RAW_POST_DATA']);
  99      }
 100      else {
 101          require_once("SOAP/Disco.php");
 102          $disco_srv = &new SOAP_Disco_Server($soap_srv, $ressource_type);
 103  
 104          header('Content-type: text/xml');
 105  
 106          if (eregi("\?wsdl$", $_SERVER['REQUEST_URI'])) {
 107              echo $disco_srv->getWSDL();
 108          }
 109          else {
 110              echo $disco_srv->getDisco();
 111          }
 112          exit;
 113      }
 114  }
 115  ?>


Généré le : Sat Feb 24 14:40:03 2007 par Balluche grâce à PHPXref 0.7