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.
Related
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);
I'm totally new to composer ;-)
I try to install mPDF 7.1 on my localhost (ubuntu 16.04) with composer.
1.) I installed composer 1.6.5.
2.) Downloaded mPDF 7.1 (https://github.com/mpdf/mpdf/releases) and unzipped folder to hdd.
3.) Open terminal in mpdf-7.1.0 folder and typed $ composer require mpdf/mpdf to start process
--> Error message is thrown:
Problem 1
- The requested package mpdf/mpdf No version set (parsed as 1.0.0) is satisfiable by mpdf/mpdf[No version set (parsed as 1.0.0)] but these conflict with your requirements or minimum-stability.
So I don't know what's the problem is and don't find any help searching the web. Can you help me?
Andreas
EDIT: I tried also:
$ composer require mpdf/mpdf:7.1.0 and
$ composer require mpdf/mpdf "^7.1.0"
throw same error message...
You don't need to download mPDF, that is what composer will do for you.
Do this:
Create an empty directory in which you will use mPDF
Run composer require mpdf/mpdf in the new directory
Composer will now install mPDF and create autoloading files
Require vendor/autoload.php in a PHP file
Done, you now can use mPDF in the file.
Make sure composer is installed globally. It works fine so.
Create an empty directory in which you will use any package, for example, mPDF
Run composer require mpdf/mpdf in the new directory
The command above does not work use sudo composer require mpdf/mpdf
If you want to specify any version of your package
Then specify thus composer require vendor/package:version
For example: composer require mpdf/mpdf:7.1.0
Composer will now install mPDF and create autoload.php in the vendor directory for autoloading files
mPDF installation is done. Now create a php file called mpdf.php for example, in same deirectory.
Require vendor/autoload.php in that PHP file.
Directory structure should be where you installed mPDF:
vendor
composer.json
composer.lock
mpdf.php
And the mpdf.php file is as follows:
<?php
require_once __DIR__ . '/vendor/autoload.php';
$mpdf = new \Mpdf\Mpdf();
$mpdf->WriteHTML('<h1>Hello world!</h1>');
$mpdf->Output();
I am trying to install Pimple in my project following https://github.com/silexphp/Pimple readme file.
Error message I receive is:
Fatal error: Class 'Pimple\Container' not found in E:\www\public\index.php on line 9
My composer.json file is:
{
...
"require-dev": {
"phpunit/phpunit": "5.1.*"
},
"require": {
"pimple/pimple": "~3.0"
}
}
When I do:
composer update
or
composer install
the message is: Nothing to install or update
In vendor/bin I can see only phpunit files. I can see however pimple in composer.lock
My PHP index.php file:
<?php
use Pimple\Container;
$co = new Container();
?>
Could you please help me make it work?
vendor/autoload.php was not included and this caused the error.
Try to delete Vendor content, and install dev again througth composer.
What are all the step by step process to install phrets in ubuntu?
I tried the following, but then unable to run phrets
First I got installed composer.
Then I ran composer require troydavisson/phrets
Now I have two files composer.json and composer.lock, and a folder named "vendor"
Inside vendor folder, I can see autoload.php file and some other folders
Now I tried the sample code from phrets git
But then am getting the following error,
PHP Fatal error: Class 'Monolog\Logger' not found in /var/www/testing/newphrets.php on line 7
Please advice what am missing here. Am planning to switch my project from old version to phrets 2.0.
Thanks
According to Troy's PHRETS 2.0 Logging video on YouTube and looking at PHRETS' composer.json, you can see that you need to do one of two things. Either,
(a) Add monolog to your project's composer.json,
{
"require": {
"troydavisson/phrets": "2.*",
"monolog/monolog": ">=1.10"
}
}
and run composer update in your project's root directory.
or,
(b) Since monolog is in PHRETS' composer.json file but in the require-dev section, run composer install --dev or composer update --dev to indicate you're currently in development and would like to use the development libraries.
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.