-
-
Save PopocaOrtiz/6bd842b9c8769d40af44 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
return array( | |
'router' => array('routes' => array( | |
'soap' => array( | |
'type' => 'Literal', | |
'options' => array( | |
'route' => '/soap', | |
'defaults' => array( | |
'controller' => 'Soap\Controller\SoapController', | |
'action' => 'soap', | |
), | |
), | |
), | |
)), | |
'service_manager' => array( | |
'factories' => array( | |
'Soap\Controller\SoapController' => 'SomeFactoryYouWillNeedToWrite', | |
), | |
), | |
); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Soap\Controller; | |
use Zend\Mvc\Controller\AbstractActionController; | |
use Zend\Soap\AutoDiscover as SoapWsdlGenerator; | |
use Zend\Soap\Server as SoapServer; | |
class SoapController | |
{ | |
protected $route; | |
protected $soap; | |
protected $wsdlGenarator | |
public function __construct($route, SoapServer $soapServer, SoapWsdlGenerator $wsdlGenerator) | |
{ | |
$this->route = $route; | |
$this->soap = $soapServer; | |
$this->wsdlGenerator = $wsdlGenerator; | |
} | |
public function soapAction() | |
{ | |
$request = $this->getRequest(); | |
$response = $this->getResponse(); | |
switch ($request->getMethod()) { | |
case 'GET': | |
$this->wsdlGenerator->setUri($this->url($this->route)); | |
$wsdl = $this->wsdlGenerator->generate(); | |
$response->getHeaders()->addHeaderLine('Content-Type', 'application/wsdl+xml'); | |
$response->setContent($wsdl->toXml()); | |
break; | |
case 'POST': | |
$this->soap->setReturnResponse(true); | |
$soapResponse = $this->soap->handle(); | |
if ($soapResponse instanceof SoapFault) { | |
$soapResponse = (string) $soapResponse; | |
} | |
$response->getHeaders()->addHeaderLine('Content-Type', 'application/xml'); | |
$response->setContent($soapResponse); | |
break; | |
default: | |
$response->setStatusCode(405); | |
$response->getHeaders()->addHeaderLine('Allow', 'GET,POST'); | |
break; | |
} | |
return $response; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment