php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #65004 SoapServer::handle() should return instead of print
Submitted: 2013-06-10 12:42 UTC Modified: -
Votes:7
Avg. Score:4.4 ± 0.7
Reproduced:6 of 6 (100.0%)
Same Version:4 (66.7%)
Same OS:5 (83.3%)
From: kjarli at gmail dot com Assigned:
Status: Open Package: SOAP related
PHP Version: 5.3.26 OS: *
Private report: No CVE-ID: None
 [2013-06-10 12:42 UTC] kjarli at gmail dot com
Description:
------------
Case: I'm using a framework with MVC, symfony2. I'm using SOAP for 1 part of the 
system to receive notifications by an external party. Using SoapServer::handle() 
requires me to hack/cheat on the MVC pattern. 

Say I want to use the normal route in any framework, thus assign my 
SoapServer::handle() to a variable in the output, that's impossible because it's 
send to the browser straight away. This breaks several things:

- The framework using Output Buffering 
- PHPUnit using Output Buffering.

Soap feels like php 4.0 and it's time to update it. My feature request: Have 
SoapServer::handle() return the string instead or make a new method that does 
this.

Test script:
---------------
$classmap = array(...);
$server = new \SoapServer(
    __DIR__ . '/../Resources/config/Notification.wsdl',
    array('classmap' => $this->classmap)
);


$server->setObject($this->get('mysoap.methods'));
$response = new Response();
$response->headers->set('Content-Type', 'text/xml; charset=ISO-8859-1');

// Sadly handle() prints the output rather than returning it -.-
ob_start();
$server->handle();
$content = ob_get_length() > 0
    ? ob_get_clean()
    : '<?xml version="1.0" encoding="UTF-8"?><root><error>No soap response generated</error></root>';
$response->setContent($content);


Expected result:
----------------
.

Actual result:
--------------
Would be so much easier if I could just do:

[...]

$response = new Response();
$response->headers->set('Content-Type', 'text/xml; charset=ISO-8859-1');
$response->setContent($server->handle());

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2013-09-04 07:04 UTC] guillaume dot lintot at laposte dot net
You can do it this way

<?php
   class \SoapServer2 extends \SoapServer{
      public function handle($soap_request = null){
         ob_start();
         parent::handle($soap_request);
         $output = ob_get_contents();
         ob_end_clean();
         return $output;
      }
   }

   $server = new \SoapServer2(
      __DIR__ . '/../Resources/config/Notification.wsdl',
      array('classmap' => $this->classmap));
   // ...
 [2013-09-04 07:20 UTC] kjarli at gmail dot com
Yes, it's possible somewhat like that, but it still requires me to use ob_* 
functions. ob_* functions bug unit-tests and pretty much everything else, they 
are very annoying to use and they conflict with a framework output buffer.

It only makes sense if it would return instead of print so that I can do with the 
content what ever I want.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Dec 22 04:01:29 2024 UTC