I am trying to coinbase PHP API, I have downloaded PHP library from GitHub and created an index.php file to start working, below is index codes
<?php
require_once('src/Client.php');
require_once('src/Configuration.php');
require_once('src/Authentication/ApiKeyAuthentication.php');
use Coinbase\Wallet\Client;
use Coinbase\Wallet\Configuration;
$apiKey="";
$apiSecret="";
$configuration = Configuration::apiKey($apiKey, $apiSecret);
$client = Client::create($configuration);
?>
And this is generating below error
Fatal error: Interface 'Coinbase\Wallet\Authentication\Authentication' not found in /home/exhakduz/api/coinbase-php-master/src/Authentication/ApiKeyAuthentication.php on line 8
I can't find any solution
Use composer instead, and require the composer autoloader within your index.php. The docs suggest to install the library with composer as well.
Install the library using Composer. Please read the Composer
Documentation if you are unfamiliar with Composer or dependency
managers in general.
Composer setup / installation
Note: All commands below need to be run from the same directory where your index.php is located.
First off you'll need to download and install composer. The current version available is 1.8.6. Download this phar to the same location as your index.php script. Also create a composer.json file with {} as the contents, composer will save your dependencies to this file.
Make sure composer.phar has execute permissions (if on linux run chmod +x ./composer.phar)
Run ./composer.phar require coinbase/coinbase. This should install the dependencies within a vendor directory.
Finally, you can require the autoloader composer generates when installing dependencies, and the missing Interface error you are seeing will be resolved.
The composer.json file should contain the following (bare minimum):
{
"require": {
"coinbase/coinbase": "^2.8"
}
}
Example using autoloader
<?php
require_once('vendor/autoload.php');
use Coinbase\Wallet\Client;
use Coinbase\Wallet\Configuration;
$apiKey="";
$apiSecret="";
$configuration = Configuration::apiKey($apiKey, $apiSecret);
$client = Client::create($configuration);
Related
I want to include a php package, a css parser: https://github.com/sabberworm/PHP-CSS-Parser In installation guide it says to "Add php-css-parser to your composer.json":
{
"require": {
"sabberworm/php-css-parser": "*"
}
}
(I don't even know what composer.json is) Since I need only in one script, is there a way to include it only in a file? Like:
<?php
include //something here
//Do stuff with css parser
?>
Thank you
Your best approach would be to familiarize yourself with composer, what it's for and how it works.
You could copy the code from the module manually and include it in your project, but why bother?
You should simply need to run composer require sabberworm/php-css-parser from your project's root directory. Composer will automatically create the composer.json file which defines your project information and its dependencies, and the composer.lock file which stores information about the version of each dependency you've installed so you can deploy specific versions to other places.
If you don't have composer installed, check out the download instructions.
Once you've installed it, you need to include the composer autoloader and you will be ready to include your custom package:
<?php
// Include composer's autoloader
include 'vendor/autoload.php';
// Now you can use any composer installed package:
$parser = new Sabberworm\CSS\Parser($sText);
Forgive my ignorance but i've been struggling to get Guzzle to install in my project's folder.
I have installed Composer via it's .exe installer.
I have a composer.json file which contains the following:
{
"require": {
"guzzlehttp/guzzle": "~5.1"
} }
I can run 'composer update' in which it installs Guzzle.
However, it installs "Vendor" folder which has folders
'Guzzlehttp'-> 'guzzle' then is has 'build','src',tests' etc.
I want to use the Client object but the documentation says add:
'use GuzzleHttp\Client;' to the top of the PHP file but I don't actually have that file structure. Inside my guzzlehttp is just 'guzzle' or 'streams'folders.
Am I write in thinking Guzzle has not installed propperly? Or is there a different way to do it in Guzzle 5?
Many thanks for any help
You should include Composer's autoloader file which takes care of loading any Composer-installed library, the autoloader file is located in the vendor directory.
Use the following in your code :
// include Composer's autoloader
require "vendor/autoload.php";
// this should work just fine now
$resp = GuzzleHttp\get("http://stackoverflow.com");
I'm trying to make a little CLI tool and package it up with composer.
Below is an extremely simplified version of the program, but it's enough to demonstrate the problem I'm encountering.
The project has one dependency, and one "binary" file
composer.json
{
"name": "alice/yamldump",
"version": "0.2.0",
"bin": [
"bin/yamldump"
],
"require": {
"symfony/yaml": "2.5.3"
}
}
bin/yamldump
#!/usr/bin/env php
<?php
// use Yaml namespace
use Symfony\Component\Yaml as Yaml;
// autoload
require_once "vendor/autoload.php";
// read yaml
$yaml = file_get_contents(sprintf("%s/%s", getcwd(), $argv[1]));
// create parser
$parser = new Yaml\Parser();
// parse the yaml
var_dump($parser->parse($yaml));
So when I install it globally, I get this
$ composer global require alice/yamldump=dev-master
Files are installed to
~/.composer/vendor/bin/yamldump -> ../alice/yamldump/bin/yamldump
~/.composer/vendor/alice/yamldump/
~/.composer/vendor/symfony/yaml/
This is a problem, because I did not intend to globally install symfony/yaml and my package's vendor/autoload.php can no longer find the Yaml package in the proper location.
I don't mind that symfony/yaml was installed globally, but it would make sense to me that composer global require would install the package like this:
~/.composer/vendor/bin/yamldump -> ../alice/yamldump/bin/yamldump
~/.composer/vendor/alice/yamldump/
~/.composer/vendor/alice/yamldump/vendor/symfony/yaml/
After all, what if I have Package A that depends on symfony/yaml=2.5.3 and Package B that requires symfony/yaml=2.6.x?
If the composer global require installs dependencies to ~/.composer/vendor/*, each globally required package can't maintain it's own version requirement of its dependency...
I know this is sort of a convoluted problem, but I really don't know how to begin fixing it.
The goal
A user should be able to
$ composer global require alice/yamldump=dev-master
$ yamldump sample.yml
The error
$ yamldump sample.yml
Warning: require_once(vendor/autoload.php): failed to open stream: No such file or directory in /Users/alice/.composer/vendor/alice/yamldump/bin/yamldump on line 8
Fatal error: require_once(): Failed opening required 'vendor/autoload.php' (include_path='.:') in /Users/alice/.composer/vendor/alice/yamldump/bin/yamldump on line 8
The question
Here it is in black & white:
How am I intended to write the require "vendor/autoload.php" line and have it work for both locally installed packages and globally installed packages?
Targeting vendor/autoload.php is generally not a good idea and only works if you run the script from the correct directory. The following should serve you better:
require_once __DIR__.'/../vendor/autoload.php';
However, this still might be an issue if your application is installed as a dependency. In that case, you might need something more substantial:
if (
(!$classLoader = includeIfExists(__DIR__.'/../vendor/autoload.php')) &&
(!$classLoader = includeIfExists(__DIR__.'/../../../autoload.php'))
) {
echo 'You must set up the project dependencies, run the following commands:'.PHP_EOL.
'curl -sS https://getcomposer.org/installer | php'.PHP_EOL.
'php composer.phar install'.PHP_EOL;
exit(1);
}
This first looks for the autoloader in the location you would expect it to be if you are working directly on your application. If that does not exist, it looks where the autoloader would be if your application is installed as a dependency.
I have tried to install php via composer and without composer in Parse. Guide for install php through paser.I followed the steps and procedure but its not working please let me know how to solve this problem.
The part you may be struggling with is installing the composer using this command:
php composer.phar install
Then 'ls' to see is you have a vendor directory.
Let me know how it works out.
You can use the autoload.php file included in the source code to include the SDK files easily. You can also use this tutorial to help you get started with the Parse PHP SDK without using Compose.
You need to do something like:
// include Parse SDK autoloader
require_once( 'autoload.php' );
// Add the "use" declarations where you'll be using the classes
use Parse\ParseClient;
use Parse\ParseObject;
// Init parse: app_id, rest_key, master_key
ParseClient::initialize('xxx', 'yyy', 'zzz');
Install Composer. Download Composer
Create new Project.
Create composer.json file with dependencies like
{
"require" : {
"parse/php-sdk":"1.1.*"
}
}
In the project folder open cmd and run the command composer install after that follow the parse quick start guide.
It works in my case.
I followed the composer instructions and installed composer successfully. I want to use tumblr's brand new php api client.
My folder structure:
vendor/
composer.json
composer.lock
myfile.php
composer.json:
{
"require": {
"tumblr/tumblr": "0.0.2"
}
}
myfile.php:
require 'vendor/autoload.php';
$client = new Tumblr\API\Client(CONSUMER_KEY, CONSUMER_SECRET);
Installing using php composer.phar install works great as well. But when executing myfile.php the class could not be found.
Fatal error: Class 'Tumblr\API\Client' not found in [..]/htdocs/tumblr/myfile.php on line 9
A new version of tumblr.php has been released which fixes the issue. Thanks to #igorw.