尝试使用 zend-soap 时找不到

Got not found when trying to use zend-soap

我正在尝试使用 zendframework/zend-soap 库在 PHP 中编写一个 SOAP 服务器。这是我的目录结构:

|- app/
    |- mySoapService.php
|- composer.json
|- composer.lock
|- vendor/

这是composer.json的内容:

{
    "name": "my_soap_service",
    "description": "This package is implementing a SOAP service.",
    "type": "project",
    "require": {
        "zendframework/zend-soap": "^2.8"
    },
    "require-dev": {
    }
}

我在终端中输入了以下命令:

zeinab: ~/my_soap_server$ composer install
PHP Warning:  Module 'soap' already loaded in Unknown on line 0
PHP Warning:  Module 'soap' already loaded in Unknown on line 0
Loading composer repositories with package information
Updating dependencies (including require-dev)
Package operations: 10 installs, 0 updates, 0 removals
  - Installing psr/container (1.0.0): Loading from cache
  - Installing container-interop/container-interop (1.2.0): Loading from cache
  - Installing zendframework/zend-stdlib (3.2.1): Loading from cache
  - Installing zendframework/zend-validator (2.12.2): Downloading (100%)         
  - Installing zendframework/zend-escaper (2.6.1): Downloading (100%)         
  - Installing zendframework/zend-uri (2.7.1): Downloading (100%)         
  - Installing zendframework/zend-eventmanager (3.2.1): Loading from cache
  - Installing zendframework/zend-code (3.4.1): Downloading (100%)         
  - Installing zendframework/zend-server (2.8.1): Downloading (100%)         
  - Installing zendframework/zend-soap (2.8.0): Downloading (100%)         
zendframework/zend-validator suggests installing psr/http-message (psr/http-message, required when validating PSR-7 UploadedFileInterface instances via the Upload and UploadFile validators)
zendframework/zend-validator suggests installing zendframework/zend-db (Zend\Db component, required by the (No)RecordExists validator)
zendframework/zend-validator suggests installing zendframework/zend-filter (Zend\Filter component, required by the Digits validator)
zendframework/zend-validator suggests installing zendframework/zend-i18n (Zend\I18n component to allow translation of validation error messages)
zendframework/zend-validator suggests installing zendframework/zend-math (Zend\Math component, required by the Csrf validator)
zendframework/zend-validator suggests installing zendframework/zend-i18n-resources (Translations of validator messages)
zendframework/zend-validator suggests installing zendframework/zend-servicemanager (Zend\ServiceManager component to allow using the ValidatorPluginManager and validator chains)
zendframework/zend-validator suggests installing zendframework/zend-session (Zend\Session component, ^2.8; required by the Csrf validator)
zendframework/zend-code suggests installing doctrine/annotations (Doctrine\Common\Annotations >=1.0 for annotation features)
zendframework/zend-soap suggests installing zendframework/zend-http (Zend\Http component)
Package container-interop/container-interop is abandoned, you should avoid using it. Use psr/container instead.
Writing lock file
Generating autoload files

并且:

zeinab:~/my_soap_server$ composer require zendframework/zend-soap
PHP Warning:  Module 'soap' already loaded in Unknown on line 0
PHP Warning:  Module 'soap' already loaded in Unknown on line 0
Using version ^2.8 for zendframework/zend-soap
./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)
Nothing to install or update
Package container-interop/container-interop is abandoned, you should avoid using it. Use psr/container instead.
Writing lock file
Generating autoload files

这是mySoapService.php的内容:

class MyClass {
    /**
     * @param integer $inputParam
     * @return string
     */
    public function method1($inputParam) {
        return "This is your input: " . $inputParam . ".";
    }

    /**
     * @param integer $inputParam1
     * @param string  $inputParam2
     * @return float
     */
    public function method2($inputParam1, $inputParam2) {
        return "This is your inputs: " . $inputParam1 . " and " . $inputParam2 . ".";
    }

}

$server = new Zend\Soap\Server(null, $options);
// Bind Class to Soap Server
$server->setClass('MyClass');
// Bind already initialized object to Soap Server
$server->setObject(new MyClass());
$server->handle();

但是当我使用 php mySoapService.php 尝试 运行 它时,我得到这个错误:

zeinab:~/my_soap_server$ php app/mySoapServer.php 
PHP Warning:  Module 'soap' already loaded in Unknown on line 0
PHP Fatal error:  Uncaught Error: Class 'Zend\Soap\Server' not found in /home/zeinab/my_soap_server/app/mySoapServer.php:23
Stack trace:
#0 {main}
  thrown in /home/zeinab/my_soap_server/app/mySoapServer.php on line 23

我还尝试将 "zendframework/zend-soap": "^2.8" 放入 composer.jsonrequirerequire-dev 部分并重复该过程;发生了同样的结果。

你好像忘了添加作曲家的自动加载。这是告诉 PHP 在哪里可以找到您正在实例化的 类 所必需的。查看 Composer's documentation 了解更多信息。

在文件开头添加include __DIR__ . '/PATH/TO/VENDOR/FOLDER/autoload.php';