项目作者: digitalkaoz

项目描述 :
php client library for ipfs
高级语言: PHP
项目地址: git://github.com/digitalkaoz/php-ipfs-api.git
创建时间: 2017-01-18T20:19:43Z
项目社区:https://github.com/digitalkaoz/php-ipfs-api

开源协议:MIT License

下载


PHP Adapter for IPFS

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!

  1. $ 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

  1. $loader = require __DIR__.'/../vendor/autoload.php';
  2. use Doctrine\Common\Annotations\AnnotationRegistry;
  3. 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:

  1. $ 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:

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

HTTP

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

  1. $ 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):

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

Client

this Driver is intended for programmatically usage:

  1. $driver = $container[IPFS\Driver\Cli::class];
  2. //$driver = $container[IPFS\Driver\Http::class];
  3. $client = new IPFS\Client($driver);
  4. $response = $client->execute((new \IPFS\Api\Basics())->version());
  5. 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:

  1. Available commands:
  2. add Add a file or directory to ipfs.
  3. cat Show IPFS object data.
  4. commands List all available commands.
  5. dns Resolve DNS links.
  6. get Download IPFS objects.
  7. help Displays help for a command
  8. id Show ipfs node id info.
  9. list Lists commands
  10. ls List directory contents for Unix filesystem objects.
  11. mount Mounts IPFS to the filesystem (read-only).
  12. ping Send echo request packets to IPFS hosts.
  13. rebuild rebuild api classes by parsing the official api doc
  14. resolve Resolve the value of names to IPFS.
  15. shutdown Shut down the ipfs daemon.
  16. update
  17. version Show ipfs version information.
  18. bitswap
  19. bitswap:ledger Show the current ledger for a peer.
  20. bitswap:reprovide Trigger reprovider.
  21. bitswap:stat Show some diagnostic information on the bitswap agent.
  22. bitswap:unwant Remove a given block from your wantlist.
  23. bitswap:wantlist Show blocks currently on the wantlist.
  24. block
  25. block:get Get a raw IPFS block.
  26. block:put Store input as an IPFS block.
  27. block:rm Remove IPFS block(s).
  28. block:stat Print information of a raw IPFS block.
  29. bootstrap
  30. bootstrap:add:default Add default peers to the bootstrap list.
  31. bootstrap:list Show peers in the bootstrap list.
  32. bootstrap:rm:all Remove all peers from the bootstrap list.
  33. config
  34. config:edit Open the config file for editing in $EDITOR.
  35. config:profile:apply Apply profile to config.
  36. config:replace Replace the config with .
  37. config:show Output config file contents.
  38. dag
  39. dag:get Get a dag node from ipfs.
  40. dag:put Add a dag node to ipfs.
  41. dag:resolve Resolve ipld block.
  42. dht
  43. dht:findpeer Query the DHT for all of the multiaddresses associated with a Peer ID.
  44. dht:findprovs Find peers in the DHT that can provide a specific value, given a key.
  45. dht:get Given a key, query the DHT for its best value.
  46. dht:provide Announce to the network that you are providing given values.
  47. dht:put Write a key/value pair to the DHT.
  48. dht:query Find the closest Peer IDs to a given Peer ID by querying the DHT.
  49. diag
  50. diag:cmds:clear Clear inactive requests from the log.
  51. diag:cmds:set-time Set how long to keep inactive requests in the log.
  52. diag:sys Print system diagnostic information.
  53. file
  54. file:ls List directory contents for Unix filesystem objects.
  55. files
  56. files:chcid Change the cid version or hash function of the root node of a given path.
  57. files:cp Copy files into mfs.
  58. files:flush Flush a given paths data to disk.
  59. files:ls List directories in the local mutable namespace.
  60. files:mkdir Make directories.
  61. files:mv Move files.
  62. files:read Read a file in a given mfs.
  63. files:rm Remove a file.
  64. files:stat Display file status.
  65. files:write Write to a mutable file in a given filesystem.
  66. filestore
  67. filestore:dups List blocks that are both in the filestore and standard block storage.
  68. filestore:ls List objects in filestore.
  69. filestore:verify Verify objects in filestore.
  70. key
  71. key:gen Create a new keypair.
  72. key:list List all local keypairs.
  73. key:rename Rename a keypair.
  74. key:rm Remove a keypair.
  75. log
  76. log:level Change the logging level.
  77. log:ls List the logging subsystems.
  78. log:tail Read the event log.
  79. name
  80. name:publish Publish IPNS names.
  81. name:pubsub:cancel Cancel a name subscription.
  82. name:pubsub:state Query the state of IPNS pubsub.
  83. name:pubsub:subs Show current name subscriptions.
  84. name:resolve Resolve IPNS names.
  85. object
  86. object:data Output the raw bytes of an IPFS object.
  87. object:diff Display the diff between two ipfs objects.
  88. object:get Get and serialize the DAG node named by .
  89. object:links Output the links pointed to by the specified object.
  90. object:new Create a new object from an ipfs template.
  91. object:patch:add-link Add a link to a given object.
  92. object:patch:append-data Append data to the data segment of a dag node.
  93. object:patch:rm-link Remove a link from an object.
  94. object:patch:set-data Set the data field of an IPFS object.
  95. object:put Store input as a DAG object, print its key.
  96. object:stat Get stats for the DAG node named by .
  97. p2p
  98. p2p:listener:close Close active p2p listener.
  99. p2p:listener:ls List active p2p listeners.
  100. p2p:listener:open Forward p2p connections to a network multiaddr.
  101. p2p:stream:close Close active p2p stream.
  102. p2p:stream:dial Dial to a p2p listener.
  103. p2p:stream:ls List active p2p streams.
  104. pin
  105. pin:add Pin objects to local storage.
  106. pin:ls List objects pinned to local storage.
  107. pin:rm Remove pinned objects from local storage.
  108. pin:update Update a recursive pin.
  109. pin:verify Verify that recursive pins are complete.
  110. pubsub
  111. pubsub:ls List subscribed topics by name.
  112. pubsub:peers List peers we are currently pubsubbing with.
  113. pubsub:pub Publish a message to a given pubsub topic.
  114. pubsub:sub Subscribe to messages on a given topic.
  115. refs
  116. refs:local List all local references.
  117. repo
  118. repo:fsck Remove repo lockfiles.
  119. repo:gc Perform a garbage collection sweep on the repo.
  120. repo:stat Get stats for the currently used repo.
  121. repo:verify Verify all blocks in repo are not corrupted.
  122. repo:version Show the repo version.
  123. stats
  124. stats:bitswap Show some diagnostic information on the bitswap agent.
  125. stats:bw Print ipfs bandwidth information.
  126. stats:repo Get stats for the currently used repo.
  127. swarm
  128. swarm:addrs:listen List interface listening addresses.
  129. swarm:addrs:local List local addresses.
  130. swarm:connect Open connection to a given address.
  131. swarm:disconnect Close connection to a given address.
  132. swarm:filters:add Add an address filter.
  133. swarm:filters:rm Remove an address filter.
  134. swarm:peers List peers with open connections.
  135. tar
  136. tar:add Import a tar file into ipfs.
  137. tar:cat Export a tar file from IPFS.

Usage

simply use the commandline interface

  1. $ bin/php-ipfs
  2. $ bin/php-ipfs add ./composer.lock --wrap-with-directory --driver=IPFS\\Driver\\Cli
  3. $ 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!

  1. $ composer build

Tests

this library is well covered with phpspec

  1. $ composer test