Reputation:
I'm trying to get my head around using PHP's composer. In particular, I'm trying to load this project and its dependencies.
I am installing composer in the necessary folder (root of my application), so it creates a composer.phar
.
I make sure I have the correct JSON file for the project in that same directory:
{
"name": "tumblr/tumblr",
"description": "Official Tumblr PHP Client",
"keywords": ["tumblr", "api", "sdk", "gif"],
"homepage": "https://github.com/tumblr/tumblr.php",
"authors": [{
"name": "John Crepezzi",
"email": "[email protected]",
"homepage": "https://github.com/seejohnrun",
"role": "developer"
}],
"license": "Apache-2.0",
"type": "library",
"require": {
"eher/oauth": "1.0.*",
"guzzle/guzzle": ">=3.1.0,<4"
},
"require-dev": {
"phpunit/phpunit": "*"
},
"autoload": {
"psr-0": {
"Tumblr\\API": "lib"
}
}
}
I then write this in the appropriate directory with the terminal: php composer.phar install
.
However, this does not load the tumblr.php
. It loads other files, such as symphony
, sebastian
, guzzle
, etc.
Am I doing this incorrectly? Does this JSON not load the tumblr.php
, but its dependencies?
Upvotes: 0
Views: 1532
Reputation: 70933
If the JSON data you show is in your OWN project, you are doing it wrong. That JSON data is from the original Tumblr project, and you shouldn't copy it into your project, because as you found out, it will not really help you using the Tumblr client.
The correct way of using Composer:
composer init
to easily create the initial composer.json
file.tumblr/tumblr
as the dependency of your project.Alternatively, if you already have a composer.json
, you can call composer require tumblr/tumblr:~0.1
.
To use the library in your code, you have to include the file vendor/autoload.php
and can then create all the classes according to the documentation.
Upvotes: 0
Reputation: 522626
Composer generates a file vendor/autoload.php
. If you want to use any of the things you installed with Composer in your own code, you just need to require_once 'vendor/autoload.php'
and can then simply call whatever code in whatever Composer-installed library you want; the autoloader will take care of locating and including the necessary files without you having to worry about particular directories inside the vendor
folder.
The autoload
entry in the composer.json file is there so any library can specify particulars of how its files should be autoloaded. You do not typically have to use that yourself in your application for anything. You may use this entry to add autoloading for your own code "for free" if you wish. However, again, you do not need to add this to use any of the installed dependencies, those should all already be configured correctly for autoloading in their respective composer.json files.
Upvotes: 1