Composer dependency without packagist - php

I have a project that has a dependency to 'webiny/crypt' package (I'm the owner of webiny/crypt repo also https://github.com/Webiny/Crypt).
{
"require": {
"webiny/crypt": "dev-master"
},
"minimum-stability": "dev"
}
Inside composer.json in webiny/crypt repo, I need to define a dependency to this repo: https://github.com/ircmaxell/php-cryptlib
That repo is not available on packagist, but inside its github repo it has a composer.json file.
I tried several solutions, but none of them worked. Here are some examples of what I tried...this is the content of composer.json of webiny/crypt.
Example 1:
"minimum-stability": "dev",
"repositories": [
{
"type": "vcs",
"url": "https://github.com/ircmaxell/PHP-CryptLib"
}
],
"require": {
"php": ">=5.4.0",
"webiny/class-loader": "dev-master",
"webiny/config": "dev-master",
"webiny/std-lib": "dev-master",
"ircmaxell/PHP-CryptLib": "*"
}
Example 2:
"minimum-stability": "dev",
"repositories": [
{
"type": "vcs",
"url": "https://github.com/ircmaxell/PHP-CryptLib"
}
],
"require": {
"php": ">=5.4.0",
"webiny/class-loader": "dev-master",
"webiny/config": "dev-master",
"webiny/std-lib": "dev-master",
"CryptLib/CryptLib": "*"
}
Also I tried both examples with 'dev-master' version instead of '*' on the CryptLib repo.

From the composer docs # https://getcomposer.org/doc/05-repositories.md#repository
Repositories are only available to the root package and the
repositories defined in your dependencies will not be loaded. Read the
FAQ entry if you want to learn why.
I think your only option, unless you want to tell your users to add that repo too, is to fork https://github.com/ircmaxell/PHP-CryptLib and then publish it to packagist. Maybe drop the author an email regarding this first tho.
Sorry, probably not the answer you were looking for.

Related

but these conflict with your requirements or minimum-stability

I am creating my own slackbot. I decided to use project as a library to help me.
https://github.com/sagebind/slack-client/issues?utf8=%E2%9C%93&q=stability
Now I need to install it with composer.
So I used the command: composer require coderstephen/slack-client
...And I get the error:
Problem 1
- Installation request for coderstephen/slack-client ^0.3.0 -> satisfiable by coderstephen/slack-client[v0.3.0].
- coderstephen/slack-client v0.3.0 requires devristo/phpws dev-master -> satisfiable by devristo/phpws[dev-master] but these conflict with your requirements or minimum-stability.
Ok - So then I decided to change my stability level to "dev" in my composer.lock:
"aliases": [],
"minimum-stability": "dev",
"stability-flags": {
"devristo/phpws": 20
},
"prefer-stable": true,
"prefer-lowest": false,
"platform": {
"php": ">=5.5"
},
"platform-dev": []
Now I'm running out of ideas on what to do. The README says to do this step in composer.json but, no such settings exist:
Please note that the current version has unstable dependencies.
In order to install those dependencies, you can set "minimum-stability" in your composer.json, and recommend that you set "prefer-stable":
My composer.json:
{
"name": "coderstephen/slack-client",
"keywords": ["slack", "api", "realtime"],
"license": "MIT",
"description": "A better Slack client, with RTM API support",
"authors": [{
"name": "Stephen Coakley",
"email": "me#stephencoakley.com"
}],
"require": {
"php": ">=5.5",
"devristo/phpws": "dev-master",
"evenement/evenement": "2.0.*",
"guzzlehttp/guzzle": "~6.0",
"react/event-loop": "^0.4.1",
"react/promise": "^2.2"
},
"require-dev": {
"phpunit/phpunit": "~4.6",
"fzaninotto/faker": "~1.4",
"apigen/apigen": "^4.1"
},
"autoload": {
"psr-4": {
"Slack\\": "src"
}
},
"autoload-dev": {
"psr-4": {
"Slack\\Tests\\": "tests"
}
}
}
Does anyone know some solutions I could try?
Add minimum-stability and prefer-stable to your composer.json (not composer.lock):
{
"name": "coderstephen/slack-client",
"keywords": ["slack", "api", "realtime"],
"license": "MIT",
"description": "A better Slack client, with RTM API support",
"authors": [{
"name": "Stephen Coakley",
"email": "me#stephencoakley.com"
}],
"require": {
"php": ">=5.5",
"devristo/phpws": "dev-master",
"evenement/evenement": "2.0.*",
"guzzlehttp/guzzle": "~6.0",
"react/event-loop": "^0.4.1",
"react/promise": "^2.2"
},
"require-dev": {
"phpunit/phpunit": "~4.6",
"fzaninotto/faker": "~1.4",
"apigen/apigen": "^4.1"
},
"autoload": {
"psr-4": {
"Slack\\": "src"
}
},
"autoload-dev": {
"psr-4": {
"Slack\\Tests\\": "tests"
}
},
"minimum-stability": "dev",
"prefer-stable": true
}
For others having the same issue, these changes are best done using composer itself instead of manually modifying the composer.json file. Just run the following commands in the console:
$ composer config minimum-stability dev
$ composer config prefer-stable true
Now you can require and update the package:
$ composer require --no-update "vendor/package-name:version"
$ composer update
Available options (in order of stability) are dev, alpha, beta, RC, and stable
You should never manually edit the composer.lock file - it is an automatically generated file.
It looks like you've shown the composer.json file of the package you're trying to require rather than your own project's composer.json. The prefer-stable and minimum-stability properties should be added to your project root's composer.json file:
{
"name": "xFlare/slack-bot",
"description": "xFlare's Slack bot project",
"authors": [
{
"name": "xFlare"
}
],
"minimum-stability": "dev",
"prefer-stable": true,
"require": {
"php": ">=5.5",
"coderstephen/slack-client": "^0.3.0"
}
}
Usually, this issue has nothing to do directly with minimum-stability or prefer-stable option, but the case is just that you already use some library directly or indirectly, that is needed in another library you use but in a higher version.
My case: Got this error message for a Codeception library which needed a dependency of PHPUnit at least of version 6 and above (>= 6) , but it clashed with the lower version 4 of PHPUnit dependency, which I had installed/required directly already before prior it (as a package in my composer.json file). (my specific case could not use higher PHPUnit than version 6, since it was the last version which supported php version I used).
You might ask if it might affect your project, which already relies on the lower version of the library, perhaps there could be some breaking change, but I don't know if there could be some workaround for using one version for dependency and another version for own project.
Edit: I also had to issue a remove composer command for phpunit dependency, otherwise I was not able to increase my phpunit version directly.
You should add the minimum-stability in your composer.json not in the composer.lock. The option exists see https://getcomposer.org/doc/04-schema.md#minimum-stability
i had the error in a symfony4 project with own bundles.
my-foo-bundle dev-master requires ramsey/uuid-doctrine ^1.5 -> satisfiable by ramsey/uuid-doctrine[1.5.0, 1.6.0] but these conflict with your requirements or minimum-stability.
the solution, i search for "ramsey/uuid-doctrine" in my bundles and i found different requirements "ramsey/uuid-doctrine ^1.5" (in my-foo-bundle) and "ramsey/uuid-doctrine dev-master" (in my app-configuration). So i delete the requirement in the app/composer.json.
This worked for me.

Can't require local package with composer

I'm currently working on a Composer package and now I want to test how it would integrate in my current application without pushing it to a remote.
So I stumbled upon this blog post which explains how to do that. However, that didn't work. I'm getting the message
Your requirements could not be resolved to an installable set of packages.
Problem 1 - The requested package tzfrs/x-bundle could not be found in any version, there may be a typo in the package name.
My directory structure looks like this
dev
Project
composer.json
Package
composer.json
The composer.json of my package looks like this
{
"name": "tzfrs/x-bundle",
"license": "proprietary",
"require": {
"php": "^7.0",
"psr/log": "~1.0"
},
"require-dev": {
"phpunit/phpunit": "~5.5"
},
"autoload": {
"psr-4": { "tzfrs\\XBundle\\": "" },
"exclude-from-classmap": [
"/Tests/"
]
}
}
And the one of my project looks like this (I'm leaving the symfony stuff and other packages/stuff out)
{
"repositories": [
{
"type": "git",
"url": "../Package",
}
],
"minimum-stability" : "beta",
"require": {
"tzfrs/x-bundle": "*"
}
}
So when doing composer update tzfrs/x-bundle I should get my new project right? However, I'm getting the message I posted above. What am I doing wrong here?
I already did git init in my package folder and also comitted all my changes. So I have a repo which is not empty already.

How to work on a fork in GitHub

I would like to update a repo in GitHub to make it compatible with ZF3, I have forked the repository to my account and made some updates.
This is my fork: https://github.com/chateaux/zf-oauth2-doctrine
Now to include this in my code base I am using Composer:
{
"name": "My Project",
"description": "",
"license": "PRIVATE - ",
"keywords": [
""
],
"homepage": "",
"repositories": [
{
"type": "vcs",
"url": "https://github.com/chateaux/zf-oauth2-doctrine"
}
],
"require": {
"php": ">=5.4",
"zendframework/zendframework": "^2.4",
"doctrine/doctrine-orm-module": "~0.8",
"doctrine/orm": "^2.4",
"gedmo/doctrine-extensions": "^2.4",
"zf-commons/zfc-rbac":"^2.5",
"rwoverdijk/assetmanager": "^1.4",
"zfcampus/zf-apigility": "^1.0",
"zfr/zfr-cors": "^1.2",
"hounddog/doctrine-data-fixture-module": "^0.0.4",
"zfcampus/zf-oauth2-client": "dev-master",
"api-skeletons/zf-oauth2-doctrine": "dev-master",
"api-skeletons/zf-oauth2-doctrine-console": "^1.1",
"chateaux/toolbox" : "dev-master"
},
"require-dev": {
"zfcampus/zf-apigility-admin": "~1.0",
"zfcampus/zf-development-mode": "~2.0",
"zendframework/zend-developer-tools": "dev-master"
}
}
However when I run a composer update, it appears to be pulling from a cache so I am not getting my updated code base:
$ php composer.phar update
You are running composer with xdebug enabled. This has a major impact on runtime performance. See https://getcomposer.org/xdebug
Warning: This development build of composer is over 60 days old. It is recommended to update it by running "composer.phar self-update" to get the latest version.
Loading composer repositories with package information
Updating dependencies (including require-dev)
- Installing zfcampus/zf-oauth2-doctrine (1.0.3)
Loading from cache
What am I doing wrong?
You should add your custom fork of the repository to the repositories array in your composer.json file and add a type field git and then point to the branch you want to use with dev-[branchname] (for example patch-4 becomes dev-patch4):
{
"name": "My ZF2 application",
"repositories": [
{
"type": "git",
"url": "https://github.com/chateaux/zf-oauth2-doctrine.git"
},
],
"require": {
...
"zfcampus/zf-oauth2-doctrine": "dev-patch-4",
...
}
}
Make sure that patch-4 is an existing branch in your custom repository.
You can find more information on this solution on the first hit from Google.

Composer - multiple repositories from one project

when I want to install some library by composer, it's enough to write:
composer require vendor/library
and composer downloads it from github. It's not necessary to give url for every "vendor/library" to composer.json. Composer does it "internally". But when I'd like to add some library from e.g. bitbucket, I have to create this composer.json:
{
"require": {
"vendor/my-private-repo1": "dev-master",
"vendor/my-private-repo2": "dev-master"
},
"repositories": [
{
"type": "vcs",
"url": "git#bitbucket.org:vendor/my-private-repo1.git"
},
{
"type": "vcs",
"url": "git#bitbucket.org:vendor/my-private-repo2.git"
}
]
}
I have to specify an url of every library I want to install, even if they are from the same project. Is there any way to make it shorter? Can I do something like this:
{
"require": {
"vendor/my-private-repo1": "dev-master",
"vendor/my-private-repo2": "dev-master",
"vendor/my-private-repo3": "dev-master",
"vendor/my-private-repo4": "dev-master"
},
"repositories": [
{
"type": "vcs",
"url": "git#bitbucket.org:vendor/*"
}
]
}
I hope my question is understandable. Thank you.
You either need to specify each repository separately, or manage your composer packages with satis or toran proxy. You'll still need to define your repositories, but only once (in satis or toran).

Version Git Repo for Composer Use - Git/Composer

Scenario
I have a Plugin in PHP that I've written and want to keep it as a private repository. I want to set up the versioning in Git. I know there are tags for this, but don't know how the convention works for Composer.
Current composer.json for my package/plugin:
{
"name": "Test/Upload",
"description": "Useful functions for image uploading.",
"minimum-stability": "dev",
"require": {
"php": ">=5.3.0"
}
}
Current composer.json for my project to include the above package/plugin:
{
"name": "multistepform",
"require": {
"cakephp/cakephp": "2.6.*",
"cakephp/debug_kit": "2.2.*"
},
"config": {
"vendor-dir": "Vendor/"
}
}
Currently I have no tags in the package/plugin.
Qs
1) Does Composer require tags in a repository in order for it to use it?
2) How should one tag their private repository for use with Composer?
3) How to include this package in a different project (using the above context)?
Just to add to #tigrang's comment and list out the explicit steps:
add your git repo using "repositories" in your composer.json
tag your package with a version number (I suggest using Semantic versioning, Keep A Changelog and my git plugin git-semver)
VERSION=0.1.0 && git tag ${VERSION} && git push origin ${VERSION}
add your package under require
you can also use "dev-master" in your require if you don't want to add version tags and want to get the latest changes to package when running composer update. This requires setting:
minimum-stability: dev
Final composer.json:
{
"name": "multistepform",
"repositories": [
{
"type": "git",
"url": "https://github.com/Test/Upload.git"
}
],
"require": {
"cakephp/cakephp": "2.6.*",
"cakephp/debug_kit": "2.2.*",
"Test/Upload": "0.1.*"
},
"config": {
"vendor-dir": "Vendor/"
}
}

Categories