omair445/php-ipfs

PHP IPFS Client Library

1.4.2 2021-08-17 06:39 UTC

This package is auto-updated.

Last update: 2024-04-17 12:44:46 UTC


README

ipfs

Dont know what ipfs is? the future of filesystems :) read here for more information!

Build Status Scrutinizer Code Quality Code Coverage

Installation

as always, use composer!

$ composer require ipfs/php-client

choosing the HTTP Adapter

If you plan to use the REST Interface of the ipfs-daemon you should choose a http-implementation. We use php-http for abstraction.

See here for a list of available implementations!

if you only want to speak with a local ipfs-daemon you should use the IPFS\\Drivers\\Cli adapter.

Annotations

as we use Annotations you should register the AnnotationLoader

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

use Doctrine\Common\Annotations\AnnotationRegistry;

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

Drivers

we ship with different adapters for communicating with the daemon.

CLI

if you are using an ipfs binary that is not available in you $PATH variable, provide an ENV var for it:

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

make sure you set IPFS_PATH in you ENV if you are not using ~/.ipfs as location.

to use this Driver from the commandline simply provide the option:

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

HTTP

if you are talking to a remote daemon provide an ENV var for it:

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

to use this Driver from the commandline simply provide the option (or leave it away since its the default):

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

Client

this Driver is intended for programmatically usage:

$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);

Apis

All Api-Endpoints are autogenerated from the official ipfs docs and are regulary checked for changes.

To rebuild the Apis yourself, simply run composer rebuild-api

The following endpoints exists:

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.

Usage

simply use the commandline interface

$ 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

to build a phar file simply run

we assume you have https://box-project.github.io/box2/ installed!

$ composer build

Tests

this library is well covered with phpspec

$ composer test