This error occurs due to 3 possible factors:
- Typo
- The package is not available
- You’re trying to use a package
dev
The first error is easy to understand, the problem is the second, it is not very clear what is "package" or where we should make it available, at first I thought that Composer consulted github and/or bitbucket, but actually that’s not how it works, you can use any repository, beyond the github, but you will have to provide the .git
as a package and this.
On the website of https://getcomposer.org if you notice there is a link called Browse Packages this is where the magic happens:
When accessing we are taken to https://packagist.org, then just sign in with your account by clicking use github (if it’s another repository like bitbucket you’ll have to create an account manually, click on Create One Now for this):
After this he will ask for the necessary permissions just accept, read and then accept.
Then in the top menu click on Submit, in the "Repository URL (Git/Svn/Hg) field", you must paste the .git
(supports other formats) of githube, to get the . git go to your repository and at the top will have the link, for example:
After this just paste into the page field Submit and then click Check:
If the error occurs:
The CSRF token is invalid. Please Try to resubmit the form.
It is because the page has expired, just click on the link Submit at the top and try again. Other repositories (of other people) with similar names may appear, it is the opportunity to think of a more creative name for yours, but it is totally optional, just click the Submit button to confirm.
It must look something like this:
You need to create a Release on github (if you’re using github), so go to Releases on your repository:
Then click the button Create a new release, fill the form and click on the button Publish release
However some repositories do not have Releases (this is the third problem I mentioned in the beginning) even though I am in Packagist, this because the project is still in development, then it is necessary to modify its composer.json
of your project and add this:
"minimum-stability": "dev",
"prefer-stable": true,
Should stay like this:
{
"name": "foo/bar",
"description": "Framwork foo",
"type": "project",
"authors": [
{
"name": "Foo bar",
"email": "[email protected]"
}
],
"require": {
"php": ">=5.3.0",
"[vendor]/[nome do repositorio]": "*"
},
"minimum-stability": "dev",
"prefer-stable": true
}
After this just test your repository on your project that is on your machine:
cd c:\wamp\projeto1
composer update
The result has to be something like this:
Loading composer repositories with package information
Updating dependencies (including require-dev)
- Installing brcontainer/composer-test-2 (v1.0.0)
Downloading: 100%
Installing by command line to your project
After preparing everything still note that it is possible to download the package without adding to your composer.json
of the project, thus:
composer require [vendor]/[nome do repositorio]
Or:
php composer.phar require [vendor]/[nome do repositorio]
However if the project does not have a Release it is necessary to execute the command like this:
composer require [vendor]/[nome do repositorio]:dev-master
Or:
php composer.phar require [vendor]/[nome do repositorio]:dev-master
Thanks I’ll try :)
– Guilherme Nascimento