使用Composer时,通常必须包括
autoload.php
文件您还需要为Composer依赖项使用名称空间。
通常是
vendor
目录与位于同一级别
application
因此,定义一个常量来指向供应商目录非常方便。
define('VENDOR', substr(FCPATH, 0, strpos(APPPATH, 'application/')) . "vendor/");
你的图书馆可能需要看起来更像这样。
<?php
require VENDOR . 'autoload.php';
//I'm not certain this is the correct namespace but hopefully you get the idea
use Achse\GethJsonRpcPhpClient;
class Ethereum
{
protected $httpClient;
protected $client;
public function __construct()
{
$this->httpClient = new GuzzleClient(new GuzzleClientFactory(), 'localhost', 8545);
$this->client = new Client($httpClient);
}
//example using the class property $client
public getResult()
{
return $this->client->callMethod('eth_getBalance', ['0xf99ce9c17d0b4f5dfcf663b16c95b96fd47fc8ba', 'latest']);
}
}