2014-05-02 60 views
0

我遇到了symfony2中原生php SoapServer的問題。 SoapServer在symfony2中使用「UserService」服務類,該類應該使用symfony2 EntityManager實例化,以便我可以訪問我的「UserRepository」。symfony2 SoapServer EntityManager注入服務

澄清:

SoapServer的:

$oSOAPServer = new \SoapServer('/path/to/wsdl'); 
$oSOAPServer->setClass("my\Namespace\UserService"); 
$oSOAPServer->handle(); 

服務:

use \Doctrine\ORM\EntityManager as EntityManager; 

class UserService 
{ 
    protected $em; 
    public function __construct(EntityManager $em) { 
     $this->em = $em; 
    } 
... 

問題是:SoapServer時總是返回內部服務器錯誤。 服務本身的作品直接在symfony2中調用。 當由SoapServer調用/實例化時,甚至可以注入EntityManager?

在此先感謝!

馬丁

回答

0

而不是使用SoapServer::setClass()你可以使用SoapServer::setObject()和傳遞您的服務:如果你How to Create a SOAP Web Service in a Symfony2 Controller

而且,:

$oSOAPServer = new \SoapServer('/path/to/wsdl'); 
$oSOAPServer->setObject($container->get('my_service')); 
$oSOAPServer->handle(); 

實現一個SOAP服務器的Symfony文檔中記錄只需要一個存儲庫,不要注入整個實體管理器。註冊您的repository as a service並注入您的服務。

+0

謝謝你,setObject()似乎是我在找的東西。 – user3595823