我已经在 Linux 上安装了 composer,所以我将composer.json编辑为:
{
"name": "keen-io/keen-io",
"description": "A PHP library for reporting events to the Keen IO API",
"type": "library",
"license": "MIT",
"keywords": [
"keen io",
"analytics"
],
"support": {
"chat": "https://www.hipchat.com/gIdidQscL"
},
"require": {
"php": ">=5.3.3",
"ext-mcrypt": "*",
"guzzle/guzzle": "~3.7"
},
"require-dev": {
"phpunit/phpunit": "~3.7.0"
},
"homepage": "http://keen.io",
"autoload": {
"psr-4": {
"KeenIO\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"KeenIO\\Tests\\": "tests/Tests"
}
},
"authors": [
{
"name": "Tom Anderson",
"email": "tom.h.anderson@gmail.com"
},
{
"name": "Keith Kirk",
"email": "keith@kmfk.io",
"homepage": "http://kmfk.io"
},
{
"name": "Michaël Gallego",
"email": "mic.gallego@gmail.com",
"homepage": "http://michaelgallego.fr"
}
]
}
然后我输入这个命令$ composer update
来更新composer.json并生成./vendor/autoload.php
. 并且这个 JSON 的目的是连接到crazy.io以使用 PHP 客户端。
然后我编写了这个 php 脚本:
<?php
require_once __DIR__ . '/vendor/autoload.php';
use KeenIO\Client\KeenIOClient;
$client = KeenIOClient::factory([
'projectId' => $projectId,
'writeKey' => $writeKey,
'readKey' => $readKey
]);
?>
但是当我运行脚本时,错误是:
Fatal error: Class 'KeenIO\Client\KeenIOClient' not found in /opt/bitnami/apache2/htdocs/sandbox/keen.io/test-keen.php on line 9
-------------------------------------------------- ------------------------- ** scirpt.php:**
<?php
//* Composer Directory : /htdocs/sandbox/project/KeenClient-PHP/
//* Current Directory : ~/htdocs/sandbox/project/KeenClient- PHP/script.php
//* File_name : script.php
require_once __DIR__ .'/vendor/autoload.php';
use KeenIO\Client\KeenIOClient;
$client = KeenIOClient::factory([
'projectId' => "Project_ID",
'writeKey' => "Write_Key",
'readKey' => "Read_Key"
]);
?>