PHP & Composer, how do I combine composer.json files - php

Can someone explain how I'm supposed to use composer with a php. I have a composer.json file in my doc root that downloads the core packages for my project, but then when I want to add another project like google+ php sdk found here https://github.com/googleplus/gplus-quickstart-php/
what do I do with that composer.json file? do i combine them manually? Do I just download that composer.json into a different dir?
my current composer.json file looks like this
{
"name": "fuel/fuel",
"type": "metapackage",
"description": "The FuelPHP framework",
"keywords": ["framework"],
"homepage": "http://fuelphp.com",
"license": "MIT",
"authors": [
{
"name": "FuelPHP Development Team",
"email": "team#fuelphp.com"
}
],
"support": {
"irc": "irc://irc.freenode.org/fuelphp",
"forum": "http://fuelphp.com/forums"
},
"require": {
"php": ">=5.3.3",
"monolog/monolog": "1.5.*",
"fuelphp/upload": "2.0",
"omissis/php-cloudfiles": "dev-master",
"mustache/mustache": "*"
},
"suggest": {
"mustache/mustache": "Allow Mustache templating with the Parser package",
"smarty/smarty": "Allow Smarty templating with the Parser package",
"twig/twig": "Allow Twig templating with the Parser package",
"mthaml/mthaml": "Allow Haml templating with Twig supports with the Parser package"
},
"config": {
"vendor-dir": "fuel/vendor"
},
"minimum-stability": "dev"
}
The g+ composer.json file looks like
{
"name": "googleplus/quickstart",
"description": "This quick-start app is built in PHP and lets you get started with the Google+ platform in a few minutes.",
"license": "Apache-2.0",
"repositories": [
{
"type": "package",
"package": {
"name": "google/google-api-php-client",
"version": "0.6.2",
"dist": {
"url": "http://google-api-php-client.googlecode.com/files/google-api-php-client-0.6.2.tar.gz",
"type": "tar"
},
"autoload": {
"classmap": [
"src/"
]
}
}
}
],
"require": {
"silex/silex": "1.0.*#dev",
"twig/twig": ">=1.8,<2.0-dev",
"google/google-api-php-client": "0.6.2"
}
}

Simply add this into the require block of your original composer file:
"googleplus/quickstart": "*",

I have little experience with Composer, but I can tell you that when you require a lib, you add that lib to your main composer.json file. Upon installation or update, the new lib will be downloaded and its composer.json file will be read by Composer; its dependencies will be automatically downloaded, and so on.
So we could say you're not supposed to download your requirements manually, you have to use Composer for that, it will take care of it for you.

Related

Composer Install Package Dependencies

I have created a custom package which is set up in a GIT repo. Composer is successfully pulling the files into a directory in the vendor directory, but I need to pull in the nested dependencies, which I cannot find the answer on how to make this happy.
This the Composer file for the main site pulling the package:
{
"name": "development/project",
"type" : "project",
"repositories": [
{
"type":"composer",
"url":"https://wpackagist.org"
},
{
"type": "package",
"package": {
"name": "development/package",
"version": "0.0.1",
"source": {
"type": "git",
"url": "https://developer#bitbucket.org/development/package.git",
"reference" : "v0.0.1"
}
}
},
],
"require": {
"php": ">=5.4",
"composer/installers": "~1.0",
},
"require-dev": {
"development/package": "~0.0"
}
}
And here is the Composer file local to the package itself:
{
"name": "development/package",
"type" : "project",
"require": {
"php": ">=5.4",
"composer/installers": "~1.0"
},
"require": {
"ellislab/codeigniter": "~3.0"
},
}
So what I would like to have happen is that when I run Composer on the main site it pulls in the 'development/package' (which it is currently doing), but also pull in the package dependencies 'ellislab/codeigniter'. Thanks for any help on this.
You have invalid composer json in your local package, it should be like this (no double require node):
{
"name": "development/package",
"type" : "project",
"require": {
"php": ">=5.4",
"composer/installers": "~1.0",
"ellislab/codeigniter": "~3.0"
}
}
Composer automatically pulls all packages defined in require node of root package, and in require node of each dependent packages, including your ellislab/codeigniter in your development/package.

Trying to get Composer to bring a folder 'src/' from it's package over with it to a my project

I built a little library to test how I can use Composer to build libraries and bring then across into my projects when ever. I can inject the library fine but it doesn't seem to bring across my folder 'src/' which hold classes. I want Composer to bring this folder along with the rest of the library so I can use it. I have tried working around with the composer.json file using psr-4, classmap etc but must be doing it wrong.
My files and folder structure are below.
Library composer.json file:
{
"name": "icbfdblibs/ipmanager",
"description": "IPManager library",
"license": "BSD-3-Clause",
"keywords": [
"framework",
"zf2"
],
"homepage": "http://framework.zend.com/",
"require": {
"php": ">=5.3.3",
"zendframework/zendframework": "~2.4"
},
"autoload": {
"psr-4": {
"IPManager\\": "src/"
}
},
"classmap": [
"src/"
]
}
How the folder structure for the library is:
MainFolder
|
---ipmanager
|
---src
|
---IPManager
|
---IPManager.php
---build.xml
---composer.json
---etc.etc
The project I'm using to bring the above library across composer.json file:
{
"name": "zendframework/skeleton-application",
"description": "Skeleton Application for ZF2",
"license": "BSD-3-Clause",
"keywords": [
"framework",
"zf2"
],
"homepage": "http://framework.zend.com/",
"require": {
"php": ">=5.6.0",
"zendframework/zendframework": "~2.4",
"icbfdblibs/welcomelib": "1.0.7",
"icbfdblibs/ipmanager": "1.0.8"
},
"autoload": {
"psr-4": { "test\\test\\public\\": "" }
},
"minimum-stability": "stable",
"repositories": [
{
"type": "package",
"package": {
"name": "icbfdblibs/ipmanager",
"version": "1.0.8",
"dist": {
"url": "/home/{username}/dev/git/{name}libs/ipmanager/application.zpk",
"type": "zip"
}
}
}
]
}
I get the library with the above configuration but not the src file which I want.
Any help or guidance would be really appreciated.
Thank you.

Composer not installing dependencies of Package

I have two projects. One is my application and the second one is an external module that I want to use in future apps.
I have created my external module on GitHub and included in the composer.json of my application.
My external module gets downloaded / cloned but the required dependencies are not installed by composer.
Here's composer.json of my application:
{
"name": "application",
"description": "Skeleton Application for ZF2",
"license": "BSD-3-Clause",
"keywords": [
"framework",
"zf2"
],
"homepage": "http://framework.zend.com/",
"require": {
"php": ">=5.5",
"zendframework/zendframework": "2.*",
"zf-commons/zfc-user": "1.4.4",
"doctrine/doctrine-orm-module": "~0.9.2",
"zf-commons/zfc-user-doctrine-orm": "1.0.*",
"zendframework/zend-developer-tools": "^0.0.2",
"username/GlideUser": "dev-master"
},
"repositories": [
{
"type": "vcs",
"url": "https://github.com/username/GlideUser.git"
}
]
}
Here's composer.json of my external module:
{
"name": "username/glide-user",
"description": "Module For Zend Framework 2",
"type": "library",
"license": "BSD-3-Clause",
"homepage": "https://github.com/username/GlideUser",
"keywords": [
"zf2",
"zfc-user",
"bjyauthorize"
],
"authors": [
{
"name": "Haris Mehmood",
"email": "abc#outlook.com",
"homepage": "abc.com",
"role": "Developer"
}
],
"minimum-stability": "dev",
"prefer-stable": true,
"require": {
"php": ">=5.3.3",
"bjyoungblood/bjy-authorize": "1.4.0"
},
"autoload": {
"psr-0": {
"GlideUser\\": "src/"
}
}
}
When I run composer install or composer update I expect bjyauthorize package to gets installed, but composer ignore the dependency and install everything else.
What is it that I am doing wrong here.
Try updating the following line in your application composer.json from:
"username/GlideUser": "dev-master"
to:
"username/glide-user": "dev-master"
This way, what is being required matches the name of the external module, which is the name defined inside the external module's composer.json.
Although it does not look directly applicable to the dependencies of the external module not installing, it could be the cause.

How to run library with composer?

I'm trying to install this github repo to my project (running on codeigniter). The steps I'm doing is very simple:
{
"name": "project",
"description": "",
"license": "MIT",
"require": {
"php" : ">=5.3.0",
"blockchain/blockchain" : "1.*",
"ext-curl": "*"
},
"require-dev": {
}
} // composer.json
and run php composer.phar update. So the package installs but I can't use it in my project - I don't think its autoloaded. /vendor/autoload.php is required in my index.php. When I try it with different package for test purposes (kriswallsmith/buzz) - it works. So what I'm doing wrong?
Also I checked my vendor/composer/installed.json and I see this:
[
{
"name": "blockchain/blockchain",
"version": "v1.0",
"version_normalized": "1.0.0.0",
"source": {
"type": "git",
"url": "https://github.com/blockchain/api-v1-client-php.git",
"reference": "c219b9b00778cf6c025628bd34fd6543922fe81b"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/blockchain/api-v1-client-php/zipball/c219b9b00778cf6c025628bd34fd6543$
"reference": "c219b9b00778cf6c025628bd34fd6543922fe81b",
"shasum": ""
},
"require": {
"ext-curl": "*",
"php": ">=5.3.0"
},
"time": "2015-02-03 18:34:11",
"type": "library",
"installation-source": "dist",
"autoload": {
"psr-4": {
"Blockchain\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"description": "Blockchain API client library",
"homepage": "https://github.com/blockchain/api-v1-client-php",
"keywords": [
"bitcoin",
"blockchain"
]
}
]
and my function where I'm trying to use this lib:
private function __check_btc_balance()
{
error_reporting(E_ALL);
$Blockchain = new \Blockchain\Blockchain(PAYMENTS_BTC_API_CODE);
}
Have you followed the installation steps?
Basically there are some differences from common composer packages. Over here it says download the source code and run composer install from it's own folder
Then include the autoloader file from the folder of the downloaded files so you will have somewhere a folder Blockchain/vendor/autoload.php to include
Download the source or clone the repository. This php library works
with the Composer package manager. Navigate to the root of the
repository and run
$ composer install
This will create the /vendor folder in the repository root. In the php
source, simply:
// Include the autoload.php from its vendor directory require
'vendor/autoload.php'
// Create the base Blockchain class instance
I've seen ...
"autoload": {
"psr-4": {
"Blockchain\\": "src/"
}
},
I always keep all my code in src\Vendor\Project\Filename.php and composer autoloader works with this. Try to add this lines of code:
"autoload": {
"psr-0": {
"": "src/"
}
},

How to install your own bundle with Composer in Symfony 2.1?

I've just moved to Symfony 2.1, and I can't understand, how can I install my own bundles with Composer?
It was very easy in 2.0.x in deps:
[MyOwnBundle]
git=git#git.weboshin.ru:weboshin_cms_bundle.git
target=/bundles/My/OwnBundle
After that I just triggered bin/vendors update and that was it!
But now there's no deps file, and I supposed to do everything with Composer. Please give me any hints.
I've found the answer.
// my_project/compose.json:
{
"repositories": [
{
"type": "vcs",
"url": "own_repository_url"
}
],
// ...
"require": {
// ...
"own/bundle": "dev-master"
}
},
 
// own_repository/own_bundle/compose.json:
{
"name": "own/bundle"
}
Add a composer.json file to your bundle. For example I have this for one of my bundles:
{
"name": "cg/kint-bundle",
"type": "symfony-bundle",
"description": "This bundle lets you use the Kint function in your Twig templates. Kint is a print_r() replacement which produces a structured, collapsible and escaped output",
"keywords": ["kint", "debug", "symfony", "bundle", "twig"],
"homepage": "http://github.com/barelon/CgKintBundle",
"license": "MIT",
"authors": [
{
"name": "Carlos Granados",
"homepage": "http://github.com/barelon"
},
{
"name": "Symfony Community",
"homepage": "http://github.com/barelon/CgKintBundle"
}
],
"require": {
"php": ">=5.3.2",
"symfony/framework-bundle": ">=2.0.0",
"raveren/kint": "dev-master"
},
"minimum-stability": "dev",
"autoload": {
"psr-0": {
"Cg\\KintBundle": ""
}
},
"target-dir": "Cg/KintBundle"
}
Then add your bundle to packagist.org. It is very simple, basically you just have to provide your git address and it will do the rest.
Once your bundle is available in packagist, then just add it as a dependency in the composer.json file for your symfony project. In my case I have:
"require": {
....
"cg/kint-bundle": "*"
},
Then just run "composer update" in your symfony directory and that´s all! You don´t even need to update the autoload file, composer will do it for you. The only thing left would be to load the bundle in appkernel.php

Categories