2

我们正在使用这个 plivo 包:https ://github.com/plivo/plivo-php并且当前版本抛出错误,因为它在类文件的顶部找不到他们需要的自动加载文件.

<?php
namespace Plivo;
require 'vendor/autoload.php';
use Guzzle\Http\Client;
class PlivoError extends \Exception {}

根据我的经验,自动加载文件应该只包含在实际调用类和函数的页面中。

这是他们的错误,还是有某种方法可以在我们自己的项目中解决这个问题,并将持续存在composer updates

4

2 回答 2

1

它现在已在我对该库的拉取请求中得到修复。

事实上,在包本身中引用任何自动加载的作曲家是错误的。Composer 将安装一个全局可用的自动加载器,它能够加载任何composer.json描述中包含的每个类。

于 2015-11-20T23:49:51.857 回答
1

所以我创建了一个新目录来测试它:

[~/Code/plivo/php]$ mkdir composer_testing
[~/Code/plivo/php]$ cd composer_testing/

并初始化一个composer.json没有依赖关系的新文件:

[~/Code/plivo/php/composer_testing]$ composer init


Welcome to the Composer config generator 



This command will guide you through creating your composer.json config.

Package name (<vendor>/<name>) [charlie/composer_testing]: 
Description []: 
Author [Charlie Chrisman <charlie@plivo.com>]: 
Minimum Stability []: 
Package Type []: 
License []: 

Define your dependencies.

Would you like to define your dependencies (require) interactively [yes]? n
Would you like to define your dev dependencies (require-dev) interactively [yes]? n

{
    "name": "charlie/composer_testing",
    "authors": [
        {
            "name": "Charlie Chrisman",
            "email": "charlie@plivo.com"
        }
    ],
    "require": {}
}

Do you confirm generation [yes]? 

然后需要 plivo-php 库(有require 'vendor/autoload.php';行)

[~/Code/plivo/php/composer_testing]$ composer require plivo/plivo-php
Using version ^1.0 for plivo/plivo-php
./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)
- Installing symfony/event-dispatcher (v2.7.6)
Loading from cache

- Installing guzzlehttp/guzzle (v3.8.1)
Loading from cache

- Installing plivo/plivo-php (v1.0.0)
Loading from cache

symfony/event-dispatcher suggests installing symfony/dependency-injection ()
symfony/event-dispatcher suggests installing symfony/http-kernel ()
Writing lock file
Generating autoload files
[~/Code/plivo/php/composer_testing]$

这是更新的 composer.json 文件:

{
    "name": "charlie/composer_testing",
    "authors": [
        {
            "name": "Charlie Chrisman",
            "email": "charlie@plivo.com"
        }
    ],
    "require": {
        "plivo/plivo-php": "^1.0"
    }
}

然后编写了一个简单的 php 文件来生成文本到语音的 XML:

<?php

require __DIR__ . '/vendor/autoload.php';

$r = new Plivo\Response();

$message = "Testing Plivo";
$params = array(
    'language' => "en-US",
    'voice' => 'WOMAN'
);

$r->addSpeak($message, $params);
Header('Content-type: text/xml');
echo($r->toXML());

?>

并正确输出预期的 XML

<Response>
    <Speak language="en-US" voice="WOMAN">Testing Plivo</Speak>
</Response>

为什么它对我有用而不对你有用?

于 2015-11-21T01:39:03.440 回答