Ho installato una libreria wrapper PHP utilizzando Composer. Il caricatore automatico sembra funzionare correttamente, ma non riesco a chiamare una classe come diceImpossibile chiamare una classe installata utilizzando Composer
classe 'Diffbot' non trovata.
Ho provato numerosi trucchi, in particolare quelli menzionati nella documentazione di Composer, ma non riesco a farlo funzionare e penso di dover condividere il mio problema qui.
mio composer.json
contiene le seguenti righe
{
"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
sto provando a chiamare classe Diffbot sotto Diffbot.php
, contiene i seguenti spazi dei nomi:
namespace Swader\Diffbot;
use Swader\Diffbot\Api\Crawl;
use Swader\Diffbot\Api\Custom;
use Swader\Diffbot\Api\Search;
use Swader\Diffbot\Exceptions\DiffbotException;
use Swader\Diffbot\Api\Product;
use Swader\Diffbot\Api\Image;
use Swader\Diffbot\Api\Analyze;
use Swader\Diffbot\Api\Article;
use Swader\Diffbot\Api\Discussion;
use GuzzleHttp\Client;
use Swader\Diffbot\Factory\Entity;
use Swader\Diffbot\Interfaces\Api;
use Swader\Diffbot\Interfaces\EntityFactory;
/**
* Class Diffbot
*
* The main class for API consumption
*
* @package Swader\Diffbot
*/
class Diffbot
{
/** @var string The API access token */
protected static $token = null;
Il file autoload_psr4.php
nella cartella composer/
:
// 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'),
);
Sto cercando di chiamare la classe Diffbot
da uno script php che risiede nella stessa directory della cartella vendor/
nel modo seguente:
require_once ('vendor/autoload.php');
error_reporting(E_ALL);
$diffbot = new Diffbot();
Modifica
ho risolto il mio problema. Ho appena aggiunto le seguenti righe. Ero confuso riguardo al namespace PHP.
require_once __DIR__.'/vendor/autoload.php';
$foo = new \Swader\Diffbot\Diffbot('foo');
Hai provato 'namespace \ Swader \ Diffbot;' invece di 'namespace Swader \ Diffbot;'? EDIT: nm ho visto la tua modifica .. – john