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.
Related
I've got a big Symfony project and started to outsource code to standalone bundles. This works like charm.
But I've realized that the composer.json contains "weird" infos on root level, after performing a composer update:
This is why what I'm asking for:
"customer/base-bundle": {
"version": "dev-develop"
},
"customer/a-bundle": {
"version": "dev-develop"
},
"customer/b-bundle": {
"version": "dev-develop"
},
"customer/c-bundle": {
"version": "dev-develop"
},
"symfony/polyfill-intl-idn": {
"version": "v1.11.0"
},
This is the regular config in composer.json:
"repositories": {
"base-bundle": {
"type": "vcs",
"url": "git#git.example.com:customer-shared/base-bundle.git"
},
"a-bundle": {
"type": "vcs",
"url": "git#git.example.com:customer-shared/a-bundle.git"
},
"b-bundle": {
"type": "vcs",
"url": "git#git.example.com:customer-shared/b-bundle.git"
},
"c-bundle": {
"type": "vcs",
"url": "git#git.pixelpark.com:customer-shared/c-bundle.git"
}
},
"require": {
// ...
"customer/base-bundle": "dev-develop",
"customer/a-bundle": "dev-develop",
"customer/b-bundle": "dev-develop",
"customer/c-bundle": "dev-develop"
}
The repositories and require section is fine. I just don't know why it adds the "dev-develop" packages (and the symfony/polyfill-intl-idn package) separately to composer.json's root.
Is this Symfony/Flex behaviour or Composer default? And for what is this extra information used?
Thanks in advance!
It figured out that there is a bug, when you rename composer.json this way: composer-dev.json
Symfony Flex has a str_replace for their symfony.lock file.
However renaming a custom composer.json this way: dev-composer.json works.
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.
I have GitHub repo tygrolew-gmail/przykladowy-komponent-php-tygrolewa-gmaila-0001
with example PHP component. This component does not have itself composer.json file.
My objective is getting this component to my project using project's composer.json.
I follow the Julien's answer to Contributing to open source bundles from vendor directory?
I wrote composer.json that describes component as "package"
{
"repositories": [
{
"type": "package",
"package": {
"name": "tygrolew-gmail/przykladowy-komponent-php-tygrolewa-gmaila-0001",
"version": "dev-master",
"source": {
"url": "https://github.com/tygrolew-gmail/przykladowy-komponent-php-tygrolewa-gmaila-0001.git",
"type": "git",
"reference": "master"
},
"autoload": {
"psr-4": {
"TygrolewGmail\\Zawartosc\\Tworcy\\" : "src/Zawartosc/Tworcy/"
},
"files": [
"/src/Zawartosc/Funkcje/_d.php"
]
}
}
}
],
"require": {
"tygrolew-gmail/przykladowy-komponent-php-tygrolewa-gmaila-0001": "dev-master"
},
"autoload": {
"psr-4": {
"": "src/"
}
}
}
It is installing the last commit from master branch.
$ php composer.phar install
Loading composer repositories with package information
Installing dependencies (including require-dev)
- Installing tygrolew-gmail/przykladowy-komponent-php-tygrolewa-gmaila-0001 (dev-master master)
Cloning master
Writing lock file
Generating autoload files
My repo history gitk all branches history
fc70af [branch:master, no tag]
|
|
| 9941b7 [branch:trial, tag:"v0.0.2"]
| /
|/
c2849e [branch:master, tag:"v0.1"]
|
|
6f8ff7 [branch:master, tag:"v0.0.1"]
My composer.json file is downloading the last commit from master branch. But i want to install some previous versions of component or trial versions.
How to install
The last commit from trial branch.
Commit with specific tag (either from master or trial branch), for example "v0.1"
The Git repos have
branches,
tags
and commits.
composer.json has fields:
"version" inside "repositories"/"package"
"reference" inside "repositories"/"package"/"source"
version value after the package name in the "require"
What is their meaning and how do they relate to GitHub's branches, tags and commits?
Edit
Flosculus answer worked, but I m still a bit confuzed. Correct me, if I do wrong, but I guess "repositories"/"package"/"version" has no connection with GitHub. However it must been used during Composer's "require".
On the other hand, "repositories"/"package"/"source"/"reference" could be anything that Git can checkout, it can be branch, tag, or commit's hash. I tried defining three items in repositories array.
"repositories": [
{
"type": "package",
"package": {
"name": "tygrolew-gmail/przykladowy-komponent-php-tygrolewa-gmaila-0001",
"version": "dev-trial",
"source": {
"url": "https://github.com/tygrolew-gmail/przykladowy-komponent-php-tygrolewa-gmaila-0001.git",
"type": "git",
"reference": "trial"
},
"autoload": {
"psr-4": {
"TygrolewGmail\\Zawartosc\\Tworcy\\" : "src/Zawartosc/Tworcy/"
},
"files": [
"/src/Zawartosc/Funkcje/_d.php"
]
}
}
},
{
"type": "package",
"package": {
"name": "tygrolew-gmail/przykladowy-komponent-php-tygrolewa-gmaila-0001",
"version": "0.1",
"source": {
"url": "https://github.com/tygrolew-gmail/przykladowy-komponent-php-tygrolewa-gmaila-0001.git",
"type": "git",
"reference": "v0.1"
},
"autoload": {
"psr-4": {
"TygrolewGmail\\Zawartosc\\Tworcy\\" : "src/Zawartosc/Tworcy/"
},
"files": [
"/src/Zawartosc/Funkcje/_d.php"
]
}
}
},
{
"type": "package",
"package": {
"name": "tygrolew-gmail/przykladowy-komponent-php-tygrolewa-gmaila-0001",
"version": "1.2.3",
"source": {
"url": "https://github.com/tygrolew-gmail/przykladowy-komponent-php-tygrolewa-gmaila-0001.git",
"type": "git",
"reference": "fc70af"
},
"autoload": {
"psr-4": {
"TygrolewGmail\\Zawartosc\\Tworcy\\" : "src/Zawartosc/Tworcy/"
},
"files": [
"/src/Zawartosc/Funkcje/_d.php"
]
}
}
}
],
First defines version "dev-trial" as checkout trial branch which gives the last commit of that branch
Second defines version "0.1" as checkout tag "v0.1"
Third defines version "1.2.3" (non-existing in the GitHub) as checkout commit "fc70af"
To get them I use respectively three requires
"require": {
"tygrolew-gmail/przykladowy-komponent-php-tygrolewa-gmaila-0001": "dev-trial"
},
2.
"require": {
"tygrolew-gmail/przykladowy-komponent-php-tygrolewa-gmaila-0001": "0.1"
},
3.
"require": {
"tygrolew-gmail/przykladowy-komponent-php-tygrolewa-gmaila-0001": "1.2.3"
},
When using the VCS type for repositories, Composer will scan each branch and tag for Composer files. From there, based on the branch and tag names, it can assemble a list of packages.
These packages (like the one you created to reference that repository) exist on packagist.org, which is the default lookup for Composer. The Authors of the repositories put them on Github.
In this case however, the repository is not on Packagist, and it has no composer file on any of it's versions. So what you have done, is created a generic repository. You can do the same thing with local directories, and zip files (local or remotely). However your one is a Git repository.
See modified json:
{
"repositories": [
{
"type": "package",
"package": {
"name": "tygrolew-gmail/przykladowy-komponent-php-tygrolewa-gmaila-0001",
"version": "dev-master",
"source": {
"url": "https://github.com/tygrolew-gmail/przykladowy-komponent-php-tygrolewa-gmaila-0001.git",
"type": "git",
"reference": "v0.0.1"
},
"autoload": {
"psr-4": {
"TygrolewGmail\\Zawartosc\\Tworcy\\" : "src/Zawartosc/Tworcy/"
},
"files": [
"/src/Zawartosc/Funkcje/_d.php"
]
}
}
}
],
"require": {
"tygrolew-gmail/przykladowy-komponent-php-tygrolewa-gmaila-0001": "dev-master"
},
"autoload": {
"psr-4": {
"": "src/"
}
}
}
When Packagist or Composer (Packagist also has a copy of Composer), scans a VCS repository, it flattens out all of the versions into multiple packages with the same name, but different versions. In your case "references". The modified json above uses "reference": "v0.0.1" to indicate a specific tag/branch.
https://github.com/composer/satis/issues/29
This is an issue requesting support for VCS repositories without composer files. However it doesn't work. When you modify the repository like so:
{
"type": "vcs",
"url": "https://github.com/tygrolew-gmail/przykladowy-komponent-php-tygrolewa-gmaila-0001.git"
}
This should work if the repo had the composer.json file. In fact when you run composer update with this, you can see it searching each branch and tag. But without the relevant composer file, all you will get is this:
[Composer\Repository\InvalidRepositoryException]
No valid composer.json was found in any branch or tag of
https://github.com/tygrolew-gmail/przykladowy-komponent-p
hp-tygrolewa-gmaila-0001.git, could not load a package from it.
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/"
}
},
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.