所以我创建了一个新目录来测试它:
[~/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>
为什么它对我有用而不对你有用?