2016-01-25 39 views
1

我是laravel 5中的新成员。此代码在纯php中可以使用。但我不知道如何将它转换为laravel 5.你能告诉我如何转移这个代码laravel 5如何将纯soap转换为laravel 5

client.php:

<?php class client { 
public function __construct() 
{ 
    $params = array('location' => 'http://localhost:8888/csoap/server.php', 
        'uri' => 'urn://localhost:8888/csoap/server.php'); 

    /* Initialize webservice */ 
    $this->instance = new SoapClient(NULL, $params); 
} 

public function getString($id) 
{ 
    return $this->instance->__soapCall('getOutputString', $id); 
} 
} 

$client = new client(); 
$id = array('id' => '1'); 

echo $client->getString($id); 
?> 

csoap/server.php:

<?php class server { 
public function getOutputString($id) 
{ 
    $str = 'Youre ID is ' . $id . '.'; 
    return $str; 
} 
} 

$params = array('uri' => 'http://localhost:8888/csoap/server.php'); 
$server = new SoapServer(NULL, $params); 
$server->setClass('server'); 
$server->handle(); 

?> 

这是我如何laravel 5.1

"require": { 
     "artisaninweb/laravel-soap": "0.2.*" 
    } 
0执行我的安装运行:作曲者安装或作曲者更新

在config/app.php中添加服务。

'providers' => [ 
... 
... 
Artisaninweb\SoapWrapper\ServiceProvider', 
] 

'aliases' => [ 
... 
... 
'SoapWrapper' => 'Artisaninweb\SoapWrapper\Facades\SoapWrapper' 
] 

这是我的客户肥皂:

use Artisaninweb\SoapWrapper\Facades\SoapWrapper; 

class DataSoap { 

public function demo() 
{ 
    // Add a new service to the wrapper 
    SoapWrapper::add(function ($service) { 
     $service 
      ->name('mydata') 
      ->wsdl('http://localhost:8888/csoap/Server.php') 
      ->trace(true) 
    }); 

    $data = [ 
     'str' => 'Hello World', 
    ]; 

    // Using the added service 
    SoapWrapper::service('mydata', function ($service) use ($data) { 
     var_dump($service->getFunctions()); 
     var_dump($service->call('getString', [$data])->getSringResult); 
    }); 
} 
} 

当我运行这段代码,我得到一个错误

Class 'Artisaninweb\SoapWrapper\ServiceProvider' not found 
+0

也许尝试使用包:https://github.com/artisaninweb/laravel-soap – haakym

+0

@haakym在哪里以及如何把这些class_alias('Artisaninweb \ SoapWrapper \ Facades \ SoapWrapper','SoapWrapper'); – Shen

+0

你正在使用流明或laravel? – haakym

回答

1

你应该改变:

Artisaninweb\SoapWrapper\ServiceProvider 

到:

Artisaninweb\SoapWrapper\ServiceProvider::class 

也:

SoapWrapper' => 'Artisaninweb\SoapWrapper\Facades\SoapWrapper 

到:

SoapWrapper' => Artisaninweb\SoapWrapper\Facades\SoapWrapper::class 
+0

也要注意更新config/app.php后用L5的:: class语法运行composer dump-autoload – Petraeus