0

我已经在 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"
]);


?>
4

1 回答 1

0

您的 composer.json 文件的项目不正确。这个来自 Keen Library。你需要这样的东西:

{
    "require": {
        "keen-io/keen-io": "~2.5"
    }
}

然后执行 php composer.phar update 并包含你的 vendor/autoload.php 文件。

- - - - - - - - - - - - - 编辑 - - - - - - - - - - - - -

在此处输入图像描述

有用。如果您将 script.php 复制到任何文件夹,则必须更改 require_once 路径,它也会为您工作(我已经运行它)。

于 2016-03-29T14:24:52.650 回答