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.
Related
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.
When I want to require my project, the following errors shows up:
The requested package mvc-php/framework could not be found in any version, there may be a typo in the package name.
The "mvc-php/framework" is a git folder.
{
"name": "mvc-php/app",
"repositories": [
{
"type": "path",
"url": "/Users/youri/Documents/Github/framework"
}
],
"require": {
"php": ">=7.0",
"mvc-php/framework": "master"
},
"autoload": {
"psr-4": {
"App\\": "app/"
}
}
}
Project i want to require:
{
"name": "mvc-php/framework",
"description": "PHP MVC framework",
"autoload": {
"psr-4": {
"Mvc\\" : "src/"
}
},
"require": {
"php": ">=7.0"
}
}
Instead of just the branch name, you must require branchName#dev
https://getcomposer.org/doc/articles/versions.md#branches
{
"name": "mvc-php/app",
"repositories": [
{
"type": "path",
"url": "/Users/youri/Documents/Github/framework"
}
],
"require": {
"php": ">=7.0",
"mvc-php/framework": "master#dev"
},
"autoload": {
"psr-4": {
"App\\": "app/"
}
}
}
The requested package X/Y could not be found in any version.
The requested package needs to be a git folder with the committed and existing composer.json file. Then to reference specific branch, you need to add the dev- prefix, so dev-master, not master.
Example
Here is the minimal working example:
File: composer.json
{
"require": {
"local/my_package": "dev-master"
},
"repositories": [
{
"packagist.org": false
},
{
"type": "path",
"url": "my_package/"
}
]
}
File: my_package/composer.json
{
"name": "local/my_package",
"require-dev": {
"symfony/console": "*"
}
}
Note: Above file is under local Git repository. To create one, run: git init && git commit -am 'Files'.
Troubleshooting
To troubleshoot the issue, run:
composer install -vvv
Also consider running: composer diagnose to identify common Composer errors.
As this is the first response when searching the error text on Google, I will also put my fix here, despite not being 100% relevant to the OP.
When you are requiring the repo, you need to make sure that your requires statement matches the name of the project in the composer.json of the project.
So if the name had been "name": "mvc-php/app-framework", in the framework project, then the require would need to be:
"require": {
"mvc-php/app-framework": "dev-master"
},
This is more applicable when you are adding a git repo. Especially when forking, as sometimes the git url might be different from the composer.json name.
Additionally (and this is the part relevant to OP), you now need to do dev-branch_name instead of branch_name#dev when requiring. I don't know when this changed, or if the old method is unusable. But this is what the current composer docs now say.
If you want Composer to check out a branch instead of a tag, you need to point it to the branch using the special dev-* prefix
Composer Documentation - Versions and Constraints - Branches
Another Gotcha to be Aware Of:
I changed the name of a package I developed and was just testing a branch on it. I had followed all the correct naming conventions mentioned above but was still getting the given error.
It turns out that for the name change to be picked up, you have to update the package name in composer.json on the main branch of the package repo (Master for me) even if you are not using that branch within your project.
It is important to note that if you do not add your own mirror source to the global variable, an error will occur where the sub-scene is not found.
You can add this in composer.json:
"repositories":[
{
"type":"composer",
"url":"https://packag"
}
],
My problem is that a privately made repo's composer.json seems to be broken when trying to use it as a package elsewhere.
I have a private repo with code needed for other projects. The repo's composer.json looks like this:
{
"name": "somevendor/global",
"require": {
"nesbot/carbon": "^1.21"
},
"autoload": {
"psr-4": {
"" : "src/"
},
"files": [
"somedir/somefile.php"
]
}
}
The src is in the base directory of the repo, and contains PSR-4 namespaced classes. I have namespace folders within that, e.g. a Foo directory with classes in the Foo namespace:
-- src
-- Foo
// some Foo\... classes
// some global namespace classes
-- somedir
somefile.php // A file with helper functions
In the project folder, I'm accessing the somevendor/global repo via a composer.json file:
{
"require": {
"somevendor/global-folder": "dev-master"
},
"repositories": [
{
"type": "package",
"package": {
"name": "somevendor/global",
"version": "dev-master",
"type": "package",
"source": {
"url": "git#bitbucket.org/somevendor/global.git",
"type": "git",
"reference": "master"
}
}
}
]
}
Running composer install in the project folder seems to work at first. I have installed SSH keys properly so it can access the private repo on Bitbucket and grab the files:
$ composer install
Loading composer repositories with package information
Updating dependencies (including require-dev)
- Installing somevendor/global (dev-master master)
Cloning master
Writing lock file
Generating autoload files
And then in the project's PHP code I require vendor/autoload.php, but none of the classes are being autoloaded, including the Carbon package specified in the first repo's composer.json file:
Fatal error: Uncaught Error: Class 'Foo\Foo' not found in...
I've clearly made a mistake here, have I structured the first repo wrongly?
I "solved" this by taking out all of the "require" entries from the remote repo's composer.json file and moving them to the local website's composer.json file.
This is what the files looked like:
The remote private repo's composer.json:
{
"name": "somevendor/global",
"license": "proprietary",
"autoload": {
"psr-4": {
"" : "src/"
},
"files": [
"functions/functions.php"
]
}
}
The local website's composer.json:
{
"require": {
"nesbot/carbon": "^1.21",
"somevendor/global": "dev-master"
},
"repositories": [
{
"type": "vcs",
"url": "git#bitbucket.org:somevendor/global.git"
}
]
}
It kept throwing Composer\Repository\InvalidRepositoryException because I forgot to put the name into the remote repo's composer.json file, so don't forget that bit!
Also remember to set up your git ssh keys if you've set them up. I used this Bitbucket tutorial to do this.
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/"
}
}
I have recently forked robmorgan/phinx project and modified the composer.json file in my project to use the forked version:
{
"name": "...",
"description": "...",
"repositories": [
{
"type": "package",
"package": {
"name": "lube8uy/phinx",
"version": "master",
"source": {
"url": "https://github.com/lube8uy/phinx.git",
"type": "git",
"reference": "master"
}
}
}
],
"require": {
"php": ">=5.3.0",
"lube8uy/phinx": "dev-master"
}
}
First question: additional vendors
Now, when I load the composer.json file in my project I get this forked version correctly.
What I don't know is how to load the dependencies from the phinx project itself:
https://github.com/lube8uy/phinx/blob/master/composer.json
If I use the original packagist source everything works fine and I got all the dependencies, but now that I use my own repository I can't get them.
Second question: updates
How can I receive the modifications I made to my github source?
I made some modifications, pushed them to the correct branch, then I run composer update but nothing was updated... what am I doing wrong?
Thank you very much
For your first question:
Try to require it as a VCS repository (Version Control System, see composer doc on vcs repositories), like the following:
{
"name": "...",
"description": "...",
"repositories": [
{
"type": "vcs",
"url": "https://github.com/lube8uy/phinx"
}
],
"require": {
"php": ">=5.3.0",
"robmorgan/phinx": "dev-master"
}
}
It now requires the package robmorgan/phinx which is found at https://github.com/lube8uy/phinx which is the desired fork. It still has the original name robmorgan/phinx but is found at a different location.
It still has the same name because of the package name in its composer.json. If you want to change the name to lube8ye/phinx, change it in the composer.json in the fork.
For your second question:
The changes made in a package you require via composer should be updated automatically when you execute php composer.phar update in your project. If this does not work, try to force composer to require a specific commit by adding the commit hash after dev-master in your require section like so:
"require": {
"robmorgan/phinx": "dev-master#1234abcd"
}
Whereat 1234abcd is the hash of the desired commit.
Also: Try clearing composer's cache by deleting the folders content to avoid loading a cached version (see composer doc on COMPOSER_CACHE_DIR)