composer.json / cakephp - php

I want to use: https://github.com/mikealmond/MusicBrainz
Copied the lib in myapp->vendor Folder. Installed Guzzle with composer and updated composer.
use GuzzleHttp\Client;
use MusicBrainz\Filters\ArtistFilter;
use MusicBrainz\Filters\RecordingFilter;
use MusicBrainz\HttpAdapters\GuzzleHttpAdapter;
use MusicBrainz\MusicBrainz;
require __DIR__ . '/vendor/autoload.php';
The autoload does not work. I tried many things and don't know, what to write in the composer.json.
Error: Class 'MusicBrainz\MusicBrainz' not found
When i call:
$brainz = new MusicBrainz(new GuzzleHttpAdapter(new Client()));
I tried in composer.json
"require-dev": {
"vendor/MusicBrainz": "dev-master"
},
"repositories": [
{
"type": "vcs",
"url": "https://github.com/mikealmond/MusicBrainz.git"
}
],
Then composer update...
And i get:
Loading composer repositories with package information
Updating dependencies (including require-dev)
Your requirements could not be resolved to an installable set of packages.
Problem 1
- The requested package src/musicbrainz could not be found in any version, there may be a typo in the package name.
Potential causes:
- A typo in the package name
- The package is not available in a stable-enough version according to your minimum-stability setting
see <https://getcomposer.org/doc/04-schema.md#minimum-stability> for more details.
Read <https://getcomposer.org/doc/articles/troubleshooting.md> for further common problems.

Go to the linked repository page on Github. In the root folder, click on the file named composer.json. Search for a line with "name". The text right to it is the name of this package that you have to use in Composer.
Alternatively, go to https://packagist.org and type something close to the actual name into the search field, like musicb. Something will be found: https://packagist.org/search/?q=musicb
In any case, you will find the package name: mikealmond/musicbrainz.
Now go to the command line and type: composer require mikealmond/musicbrainz. Composer will do the rest, including the download of Guzzle because this is declared as a dependency.
After that step, the demo code will work - or at least will not fail because of missing classes.

Related

Install Laravel Nova on Gitlab CI

I'm trying to use a continuous Integration with Gitlab CI.
I installed a fresh Laravel 8, add manually "laravel/nova": "~3.0", in composer.json
As stated in docs, I do
composer config http-basic.nova.laravel.com ${NOVA_USERNAME} ${NOVA_PASSWORD}
and then
➜ composer update
Loading composer repositories with package information
Updating dependencies
Your requirements could not be resolved to an installable set of packages.
Problem 1
- Root composer.json requires laravel/nova, it could not be found in any version, there may be a typo in the package name.
Potential causes:
- A typo in the package name
- The package is not available in a stable-enough version according to your minimum-stability setting
see <https://getcomposer.org/doc/04-schema.md#minimum-stability> for more details.
- It's a private package and you forgot to add a custom repository to find it
Read <https://getcomposer.org/doc/articles/troubleshooting.md> for further common problems.
I echoed ${NOVA_USERNAME} ${NOVA_PASSWORD} and I have doubled check that both field are OK. NOVA_USERNAME contains the registered email, and NOVA_PASSWORD contains the API Token found here: https://nova.laravel.com/settings/password
Anybody knows where am I failing ?
I believe it is because you didn't add the Nova repository to your composer.json file. It is mentioned in the documentation link you provided.
"repositories": [
{
"type": "composer",
"url": "https://nova.laravel.com"
}
],

composer provide / require not finding implementation

Trying to use composer's provide feature, I added a provide section to my implementation repository ffa-php-mock, in which I say it provides shadiakiki1986/ffa-php-implementation. In my repository consuming this implementation, ffa-php-cli, I replaced the composer require entry requiring ffa-php-mock with an entry requiring ffa-php-implementation. If I try to run a composer update, I get the following
> composer update
Loading composer repositories with package information
Updating dependencies (including require-dev)
Your requirements could not be resolved to an installable set of packages.
Problem 1
- The requested package shadiakiki1986/ffa-php-implementation could not be found in any version, there may be a typo in the package name.
Potential causes:
- A typo in the package name
- The package is not available in a stable-enough version according to your minimum-stability setting
see <https://getcomposer.org/doc/04-schema.md#minimum-stability> for more details.
Read <https://getcomposer.org/doc/articles/troubleshooting.md> for further common problems.
Can you give me any hints as to how to debug what the problem is?
Edit: simplified example
I tried the provide feature in a dummy project on something that already exists. jackalope/jackalope provides phpcr/phpcr-implementation, which in its turn is already required by DoctrinePHPCRBundle.
If I start a new empty project with composer init and specify that my project depends on phpcr/phpcr-implementation, I get the same error as above. I also tried putting phpcr/phpcr-implementation directly in the composer.json file and running a composer update, but to no avail.
> cat composer.json
{
"require": {
"phpcr/phpcr-implementation": "2.1.0"
}
}
I would think that this is perhaps a bug in composer, but it seems from this issue that it is already in use.
> composer --version
Composer version 1.3.0 2016-12-24 00:47:03
The closest composer github issue I can find is #2811, but that one says that the reporting isn't clear, not that provide doesn't work
So I ended up learning that the specific package with the implementation should still be included in the composer.json file. For packages using the library, that's ok as they get added to the require section. For the library that is directly requiring the implementation, that should be done in the require-dev so that the unit tests can work and so that other projects using the library are not required to use the same implementation

How to install Composer using Composer?

EDIT: solved, I have to use "dev-master" instead of "master" or "dev".
maybe this seems weird to you... but I'm trying to locally install composer using a global composer binary.
I'm trying to write something like:
composer require composer/composer
But this doesn't work, it tells me that needs the version. Then I've tried the following variations:
composer require composer/composer=*
composer require composer/composer=master
composer require composer/composer=dev
And... nothing, I obtain the following error message:
Your requirements could not be resolved to an installable set of packages.
Problem 1
- The requested package composer/composer could not be found in any version, there may be a typo in the package name.
Potential causes:
- A typo in the package name
- The package is not available in a stable-enough version according to your minimum-stability setting
see <https://groups.google.com/d/topic/composer-dev/_g3ASeIFlrc/discussion> for more details.
Read <https://getcomposer.org/doc/articles/troubleshooting.md> for further common problems.
Installation failed, reverting ./composer.json to its original content.
Anyone has any idea if it's possible to do it in a "clean" way? (Allowing the following points):
specifying a very concrete version
registering it in the composer.json and composer.lock files
placing the composer binary with other php binaries like behat ...
Ok, I've made a stupid mistake. I have to use "dev-master", not "dev" nor "master".
Sorry for this dumb question.
Don't understand why do you want this, but I think #EDIT : Saw why you need this. Ok.
"repositories": [
{
"type": "vcs",
"url": "https://github.com/composer/composer.git"
}
],
"require": {
"composer/composer": "dev-master#775f6cd5c633facf2e7b99611fdcaa900b58ddb7"
}
would work.
You can view here the commit hash corresponding to different releases : https://github.com/composer/composer/releases
Well, it seems to me that you are trying to install composer using composer itself. That of course is not possible.
To install composer you need to first download it from here.
Once you have done that you will be able to install packages using the 'require' command.

Composer cannot find the package for new require within Yii2 composer.json

Ok, I'm using Yii2 and I am trying to add a new requirement/library to the project. Said library can be found here: https://github.com/cyphix333/SBBCodeParser
It is a forked project with an added composer.json.
I tried adding it as a requirement in the projects main composer file, ie:
"require": {
//..........
"samclarke/sbb-code-parser": "*"
},
Then I ran:
composer update
It just complained that it couldn't find the package or any version of it.
Then I removed that line and tried:
require samclarke/sbb-code-parser
I have the files already in my Yii vendor folder located at: #app/vendor/samclarke/sbb-code-parser
I'm pretty new to composer and am not sure what I'm doing wrong or how composer actually is supposed to know where to get the files from based on the package name.
The package samclarke/sbb-code-parser can be found at Packagist.
https://packagist.org/packages/samclarke/sbb-code-parser
By default Composer tries to resolve a stableset of packages.
But this packages doesn't provide a stable version (version tag), yet - only the dev-master version exists. Composer can not resolve it.
In order to require it, you need to lower your minimum-stability for this package to development.
You might do this for one package explicitly:
"require": {
"samclarke/sbb-code-parser": "dev-master#dev"
},
Or for all packages by setting:
"minimum-stability": "dev"
The package cyphix333/SBBCodeParser is not on Packagist.
It's a private fork. If you want exactly this code. You might add a repositories section to your composer.json and add repo with url and type with vcs there. Then Composer can load the package from the VCS repository over at Github. This is described here: https://getcomposer.org/doc/05-repositories.md#loading-a-package-from-a-vcs-repository
That would work like this:
{
"repositories": [
{
"type": "vcs",
"url": "https://github.com/cyphix333/SBBCodeParser"
}
],
"require": {
"samclarke/sbb-code-parser": "dev-master"
}
}
But unfortunately, the fork is also not well maintained and doesn't contain a valid composer.json file.
[Composer\Repository\InvalidRepositoryException]
No valid composer.json was found in any branch or tag of https://github.com/cyphix333/SBBCodeParser, could not load a package from it.
This needs to be fixed first....

How to move composer dependency from require-dev to require?

I have two projects on my git repo server. The first one is a library I wrote, let's call it foo/lib-bar. The second is an application which uses that library foo/app-bar. Currently the library is in development version, so the composer.json file of the library looks like this:
{
"name": "foo/lib-bar",
"description": "Bar library",
"version": "1.0.0-dev",
"type": "library",
"require": {
"php": ">=5.4",
"ext-posix": "*"
}
}
The application uses this library, so it contains the necessary requirement:
{
"name": "foo/app-bar",
"description": "Bar application",
"version": "0.5.0-dev",
"type": "application",
"repositories": [
{
"type": "vcs",
"url": "ssh://user#git.example.com/lib-foo"
}
],
"require-dev": {
"foo/lib-bar": ">=1.0.0-dev",
},
"require": {
"php": ">=5.5.3"
}
}
And everything is smooth up to this point: both composer install and composer update run as expected, install the dependency and I can see it in vendor/
Now, the docs says that
require#
Lists packages required by this package. The package will not be installed unless those requirements can be met.
And for the steps which lead to the issue in question:
So ok, my library is ready to be deployed and come out of the development phase. It also happens to be required in production version of my application. I remove the dev suffix from the composer.json file of my library, commit and push the file, and am ready to update the application.
With the application's composer.json I move the library dependency from require-dev section to require and remove the dev suffix (everything is copy-pasted, so there is no typo - I've checked and rechecked again):
"require-dev": {},
"require": {
"php": ">=5.5.3",
"foo/lib-bar": ">=1.0.0"
}
Now I run composer update and I get:
$ composer update
Loading composer repositories with package information
Updating dependencies (including require-dev)
Your requirements could not be resolved to an installable set of packages.
Problem 1
- Installation request for foo/lib-bar >=1.0.0 -> satisfiable by foo/lib-bar[dev-master].
- Removal request for foo/lib-bar == 9999999-dev
I assumed it did not find the new version, so I deleted the old library manually:
$ rm composer.lock
$ rm -rf vendor/foo/
and tried to install it from scratch
$ composer install
but this time it gives me:
Your requirements could not be resolved to an installable set of packages.
Problem 1
- The requested package foo/lib-bar could not be found in any version, there may be a typo in the package name.
So it seems like require-dev does work, but require doesn't. Any suggestions on what may have gone wrong here?
require-dev is not the place to develop dependencies. It is meant for software that is used only in development, like PHPUnit, Mockery etc., or for dependencies that are useful by themselves, but in this case only used for development, like the client library for the service a software package is about (to make some real requests in a test scenario).
So your library shouldn't have been "require-dev" from the beginning.
Another thing is: Composer will deduct the version if use appropriate branches and tags, i.e. a branch named "1.0.x" in your repository will be detected as being the development branch for all 1.0 versions, and any requirements for such versions could possibly be satisfied by this branch - provided you allow for development versions either by setting "minimum-stability": "dev" (which would allow development versions for ALL software - rather unintended), or when you require version "1.0.0#dev" for your software.
The one thing that might currently break your composer setup is that you mention a version in the librarys composer.json explicitly, and this is a development version. Have you removed that version indicator? You should remove it, because life is easier if Composer can detect the versions from the tags in a repository, not by having them explicitly mentioned in composer.json.
Finally please make sure that when using Git you tag the commit with appropriate version. The required version should correspond to the git tagged version.

Categories