Edit report at https://bugs.php.net/bug.php?id=65004&edit=1

 ID:                 65004
 Comment by:         kjarli at gmail dot com
 Reported by:        kjarli at gmail dot com
 Summary:            SoapServer::handle() should return instead of print
 Status:             Open
 Type:               Feature/Change Request
 Package:            SOAP related
 Operating System:   *
 PHP Version:        5.3.26
 Block user comment: N
 Private report:     N

 New Comment:

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.


Previous Comments:
------------------------------------------------------------------------
[2013-09-04 07:04:01] 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-06-10 12:42:29] 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());


------------------------------------------------------------------------



-- 
Edit this bug report at https://bugs.php.net/bug.php?id=65004&edit=1

Reply via email to