ipfs/php-client

ipfs客户端库

1.4.1 2018-12-24 22:55 UTC

This package is not auto-updated.

Last update: 2024-09-15 02:24:34 UTC


README

ipfs

不知道ipfs是什么?这是文件系统的未来 :) 更多信息请点击这里

Build Status Scrutinizer Code Quality Code Coverage

安装

一如既往,使用composer!

$ composer require ipfs/php-client

选择HTTP适配器

如果您计划使用ipfs守护进程的REST接口,应选择一个http实现。我们使用php-http进行抽象。

点击这里查看可用的实现列表!

如果您只想与本地ipfs守护进程通信,应使用IPFS\\Drivers\\Cli适配器。

注解

由于我们使用注解,因此您应注册AnnotationLoader

$loader = require __DIR__.'/../vendor/autoload.php';

use Doctrine\Common\Annotations\AnnotationRegistry;

AnnotationRegistry::registerLoader(array($loader, "loadClass"));

驱动程序

我们提供了不同的适配器来与守护进程通信。

CLI

如果您使用的ipfs二进制文件不在您的$PATH变量中,请提供相应的ENV变量。

$ export IPFS_BINARY=/my/location/to/ipfs

如果您不是使用~/.ipfs作为位置,请确保在ENV中设置了IPFS_PATH

要从命令行使用此驱动程序,只需提供选项即可。

$ bin/php-ipfs version --driver=IPFS\\Driver\\Cli

HTTP

如果您正在与远程守护进程通信,请提供相应的ENV变量。

$ export IPFS_API=http://somehost:5001/api/v0

要从命令行使用此驱动程序,只需提供选项(或省略它,因为它默认为该选项)。

$ bin/php-ipfs version --driver=IPFS\\Driver\\Http
$ bin/php-ipfs version

客户端

此驱动程序旨在用于编程使用。

$driver = $container[IPFS\Driver\Cli::class];
//$driver = $container[IPFS\Driver\Http::class];
$client = new IPFS\Client($driver);

$response = $client->execute((new \IPFS\Api\Basics())->version());

var_dump($response);

API

所有API端点都是从官方ipfs文档自动生成的,并且定期检查更改。

要自己重建API,只需运行composer rebuild-api

以下端点存在:

Available commands:
  add                       Add a file or directory to ipfs.
  cat                       Show IPFS object data.
  commands                  List all available commands.
  dns                       Resolve DNS links.
  get                       Download IPFS objects.
  help                      Displays help for a command
  id                        Show ipfs node id info.
  list                      Lists commands
  ls                        List directory contents for Unix filesystem objects.
  mount                     Mounts IPFS to the filesystem (read-only).
  ping                      Send echo request packets to IPFS hosts.
  rebuild                   rebuild api classes by parsing the official api doc
  resolve                   Resolve the value of names to IPFS.
  shutdown                  Shut down the ipfs daemon.
  update
  version                   Show ipfs version information.
 bitswap
  bitswap:ledger            Show the current ledger for a peer.
  bitswap:reprovide         Trigger reprovider.
  bitswap:stat              Show some diagnostic information on the bitswap agent.
  bitswap:unwant            Remove a given block from your wantlist.
  bitswap:wantlist          Show blocks currently on the wantlist.
 block
  block:get                 Get a raw IPFS block.
  block:put                 Store input as an IPFS block.
  block:rm                  Remove IPFS block(s).
  block:stat                Print information of a raw IPFS block.
 bootstrap
  bootstrap:add:default     Add default peers to the bootstrap list.
  bootstrap:list            Show peers in the bootstrap list.
  bootstrap:rm:all          Remove all peers from the bootstrap list.
 config
  config:edit               Open the config file for editing in $EDITOR.
  config:profile:apply      Apply profile to config.
  config:replace            Replace the config with .
  config:show               Output config file contents.
 dag
  dag:get                   Get a dag node from ipfs.
  dag:put                   Add a dag node to ipfs.
  dag:resolve               Resolve ipld block.
 dht
  dht:findpeer              Query the DHT for all of the multiaddresses associated with a Peer ID.
  dht:findprovs             Find peers in the DHT that can provide a specific value, given a key.
  dht:get                   Given a key, query the DHT for its best value.
  dht:provide               Announce to the network that you are providing given values.
  dht:put                   Write a key/value pair to the DHT.
  dht:query                 Find the closest Peer IDs to a given Peer ID by querying the DHT.
 diag
  diag:cmds:clear           Clear inactive requests from the log.
  diag:cmds:set-time        Set how long to keep inactive requests in the log.
  diag:sys                  Print system diagnostic information.
 file
  file:ls                   List directory contents for Unix filesystem objects.
 files
  files:chcid               Change the cid version or hash function of the root node of a given path.
  files:cp                  Copy files into mfs.
  files:flush               Flush a given path’s data to disk.
  files:ls                  List directories in the local mutable namespace.
  files:mkdir               Make directories.
  files:mv                  Move files.
  files:read                Read a file in a given mfs.
  files:rm                  Remove a file.
  files:stat                Display file status.
  files:write               Write to a mutable file in a given filesystem.
 filestore
  filestore:dups            List blocks that are both in the filestore and standard block storage.
  filestore:ls              List objects in filestore.
  filestore:verify          Verify objects in filestore.
 key
  key:gen                   Create a new keypair.
  key:list                  List all local keypairs.
  key:rename                Rename a keypair.
  key:rm                    Remove a keypair.
 log
  log:level                 Change the logging level.
  log:ls                    List the logging subsystems.
  log:tail                  Read the event log.
 name
  name:publish              Publish IPNS names.
  name:pubsub:cancel        Cancel a name subscription.
  name:pubsub:state         Query the state of IPNS pubsub.
  name:pubsub:subs          Show current name subscriptions.
  name:resolve              Resolve IPNS names.
 object
  object:data               Output the raw bytes of an IPFS object.
  object:diff               Display the diff between two ipfs objects.
  object:get                Get and serialize the DAG node named by .
  object:links              Output the links pointed to by the specified object.
  object:new                Create a new object from an ipfs template.
  object:patch:add-link     Add a link to a given object.
  object:patch:append-data  Append data to the data segment of a dag node.
  object:patch:rm-link      Remove a link from an object.
  object:patch:set-data     Set the data field of an IPFS object.
  object:put                Store input as a DAG object, print its key.
  object:stat               Get stats for the DAG node named by .
 p2p
  p2p:listener:close        Close active p2p listener.
  p2p:listener:ls           List active p2p listeners.
  p2p:listener:open         Forward p2p connections to a network multiaddr.
  p2p:stream:close          Close active p2p stream.
  p2p:stream:dial           Dial to a p2p listener.
  p2p:stream:ls             List active p2p streams.
 pin
  pin:add                   Pin objects to local storage.
  pin:ls                    List objects pinned to local storage.
  pin:rm                    Remove pinned objects from local storage.
  pin:update                Update a recursive pin.
  pin:verify                Verify that recursive pins are complete.
 pubsub
  pubsub:ls                 List subscribed topics by name.
  pubsub:peers              List peers we are currently pubsubbing with.
  pubsub:pub                Publish a message to a given pubsub topic.
  pubsub:sub                Subscribe to messages on a given topic.
 refs
  refs:local                List all local references.
 repo
  repo:fsck                 Remove repo lockfiles.
  repo:gc                   Perform a garbage collection sweep on the repo.
  repo:stat                 Get stats for the currently used repo.
  repo:verify               Verify all blocks in repo are not corrupted.
  repo:version              Show the repo version.
 stats
  stats:bitswap             Show some diagnostic information on the bitswap agent.
  stats:bw                  Print ipfs bandwidth information.
  stats:repo                Get stats for the currently used repo.
 swarm
  swarm:addrs:listen        List interface listening addresses.
  swarm:addrs:local         List local addresses.
  swarm:connect             Open connection to a given address.
  swarm:disconnect          Close connection to a given address.
  swarm:filters:add         Add an address filter.
  swarm:filters:rm          Remove an address filter.
  swarm:peers               List peers with open connections.
 tar
  tar:add                   Import a tar file into ipfs.
  tar:cat                   Export a tar file from IPFS.

用法

只需使用命令行界面。

$ bin/php-ipfs
$ bin/php-ipfs add ./composer.lock --wrap-with-directory --driver=IPFS\\Driver\\Cli
$ bin/php-ipfs add ./composer.lock --wrap-with-directory

PHAR

要构建一个phar文件,只需运行:

我们假设您已安装https://box-project.github.io/box2/

$ composer build

测试

此库已通过phpspec进行了良好的覆盖。

$ composer test