简体   繁体   English

Keen.io php客户端(未找到类)

[英]Keen.io php client (class not found )

I have installed composer on Linux ,So i have edited composer.json as this : 我已经在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"
        }
    ]
}

Then i have type this command $ composer update to update composer.json and generate ./vendor/autoload.php . 然后我键入此命令$ composer update来更新composer.json并生成./vendor/autoload.php and the purpose of this JSON is to connect to keen.io to use PHP client . 这个JSON的目的是连接到keen.io以使用PHP客户端。

Then i coded this php script : 然后我编码了这个php脚本:

<?php


    require_once __DIR__ . '/vendor/autoload.php';
​
    use KeenIO\Client\KeenIOClient;


$client = KeenIOClient::factory([
    'projectId' => $projectId,
    'writeKey'  => $writeKey,
    'readKey'   => $readKey
]);
​
?>

But when i run the script the error is : 但是当我运行脚本时,错误是:

Fatal error: Class 'KeenIO\Client\KeenIOClient' not found in /opt/bitnami/apache2/htdocs/sandbox/keen.io/test-keen.php on line 9

--------------------------------------------------------------------------- ** scirpt.php:** -------------------------------------------------- ------------------------- ** 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"
]);


?>

Your composer.json file's project is incorrect. 您的composer.json文件的项目不正确。 This one is from Keen Library. 这是基恩图书馆的作品。 You need something like this: 您需要这样的东西:

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

Then execute php composer.phar update and include your's vendor/autoload.php file. 然后执行php composer.phar更新,并包含您的vendor / autoload.php文件。

------------------------- EDIT ------------------------- -------------------------编辑------------------------ --

在此处输入图片说明

It works. 有用。 If you copy your script.php to any folder, you must change require_once path, and also it will work for you (I've run it). 如果将script.php复制到任何文件夹,则必须更改require_once路径,它也将为您工作(我已经运行了它)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM