-
-
Save gennadiylitvinyuk/8974351 to your computer and use it in GitHub Desktop.
This file contains 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 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 extends AbstractActionController | |
{ | |
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(); | |
$canonicalUrl = $this->url()->fromRoute($this->route, array(), array('force_canonical' => true)); | |
switch ($request->getMethod()) { | |
case 'GET': | |
$this->wsdlGenerator->setUri($canonicalUrl); | |
$wsdl = $this->wsdlGenerator->generate(); | |
$response->getHeaders()->addHeaderLine('Content-Type', 'application/wsdl+xml'); | |
$response->setContent($wsdl->toXml()); | |
break; | |
case 'POST': | |
$this->soap->setWSDL($canonicalUrl); | |
$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
Hi,
I'm still new to zf2 & mvc itself :)
Could you give an e.g of the how the the post would be invoked via the soap controller or even tested through a url.
Cheers