无法调用使用编写器安装的类



我使用Composer安装了一个PHP包装器库。自动加载器似乎工作良好,但我不能调用类,因为它说

类'Diffbot'未找到。

我尝试了许多技巧,特别是那些在Composer文档中提到的,但我不能让它工作,我想我必须在这里分享我的问题。

我的composer.json包含以下行

{
    "require": {
        "swader/diffbot-php-client": "^0.4.4"
    }
}
Directory structure
Vendor
---composer
---guzzlehttp
---react
---swader
---autoload.php
'swader' folder
---diffbot-php-client
    ---src
        ---Abstracts
        ---Api
        ---Entity
        ---Exceptions
        ---Factory
        ---Interfaces
        ---Traits
        ---Diffbot.php

我试图在Diffbot.php下调用Diffbot类,它包含以下名称空间:

namespace SwaderDiffbot;
use SwaderDiffbotApiCrawl;
use SwaderDiffbotApiCustom;
use SwaderDiffbotApiSearch;
use SwaderDiffbotExceptionsDiffbotException;
use SwaderDiffbotApiProduct;
use SwaderDiffbotApiImage;
use SwaderDiffbotApiAnalyze;
use SwaderDiffbotApiArticle;
use SwaderDiffbotApiDiscussion;
use GuzzleHttpClient;
use SwaderDiffbotFactoryEntity;
use SwaderDiffbotInterfacesApi;
use SwaderDiffbotInterfacesEntityFactory;
/**
 * Class Diffbot
 *
 * The main class for API consumption
 *
 * @package SwaderDiffbot
 */
class Diffbot
{
    /** @var string The API access token */
    protected static $token = null;

composer/文件夹下的autoload_psr4.php文件:

// autoload_psr4.php @generated by Composer
$vendorDir = dirname(dirname(__FILE__));
$baseDir = dirname($vendorDir);
return array(
    'Swader\Diffbot\' => array($vendorDir . '/swader/diffbot-php-client/src'),
    'React\Promise\' => array($vendorDir . '/react/promise/src'),
    'GuzzleHttp\Stream\' => array($vendorDir . '/guzzlehttp/streams/src'),
    'GuzzleHttp\Ring\' => array($vendorDir . '/guzzlehttp/ringphp/src'),
    'GuzzleHttp\' => array($vendorDir . '/guzzlehttp/guzzle/src'),
);

我试图调用Diffbot类的php脚本驻留在同一目录下的vendor/文件夹在以下方式:

require_once ('vendor/autoload.php');
error_reporting(E_ALL); 
$diffbot = new Diffbot();
<标题>编辑我解决了我的问题。我只是添加了以下几行。我对PHP命名空间感到困惑。
require_once __DIR__.'/vendor/autoload.php';
$foo = new SwaderDiffbotDiffbot('foo');

Try

require_once __DIR__.'/vendor/autoload.php';
use SwaderDiffbotDiffbot;
$diffbot = new Diffbot();

相关内容

  • 没有找到相关文章

最新更新