Keen.io php 客户端(class 未找到)
Keen.io php client (class not found )
我在 Linux 上安装了作曲家,所以我编辑了 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 的目的是连接到 keen.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"
]);
?>
您的 composer.json 文件的项目不正确。这本来自基恩图书馆。你需要这样的东西:
{
"require": {
"keen-io/keen-io": "~2.5"
}
}
然后执行 php composer.phar 更新并包含您的 vendor/autoload.php 文件。
------------------------编辑-------------------- ------
有效。如果您将 script.php 复制到任何文件夹,则必须更改 require_once 路径,它也适用于您(我已经 运行 了)。
我在 Linux 上安装了作曲家,所以我编辑了 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 的目的是连接到 keen.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"
]);
?>
您的 composer.json 文件的项目不正确。这本来自基恩图书馆。你需要这样的东西:
{
"require": {
"keen-io/keen-io": "~2.5"
}
}
然后执行 php composer.phar 更新并包含您的 vendor/autoload.php 文件。
------------------------编辑-------------------- ------
有效。如果您将 script.php 复制到任何文件夹,则必须更改 require_once 路径,它也适用于您(我已经 运行 了)。