Composer phar package not found - php

I am trying to create a new composer library package.
I created the composer.json file using the
composer.phar create-project xlix vendor/xlix/xlix 0.3
command.
In the filesystem the file composer.json exists under vendor/xlix/xlix and for testing purposes I copied it to vendor/xlix.
The composer.json file content is the following:
{
"name": "xlix/xlix",
"type": "library",
"description": "XLIX package",
"keywords": ["core"],
"homepage": "http://myhomepage",
"license": "GPL",
"authors": [
{
"name": "Florian Kasper",
"email": "florian.kasper#mymail"
}
],
"require": {
"php": ">=5.2.4"
},
"autoload": {
"psr-0" : {
"Xlix\\Bundle" : "lib/"
}
},
"extra": {
"branch-alias": {
"dev-master": "1.0"
}
}
}
Then I tried the following commands:
git:(master) ✗ php composer.phar require xlix/xlix
git:(master) ✗ php composer.phat require vendor/xlix
...
git:(master) ✗ php composer.phar install vendor/xlix
git:(master) ✗ php composer.phar install xlix/xlix
...
Every time the same output:
Please provide a version constraint for the xlix/xlix requirement: *
composer.json has been updated
Loading composer repositories with package information
Updating dependencies
Your requirements could not be resolved to an installable set of packages.
Problem 1
- The requested package xlix/xlix 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.
In my ROOTDIR/composer.json file the package is registered in the require section.
"jms/security-extra-bundle": "1.2.*",
"jms/di-extra-bundle": "1.1.*",
"kriswallsmith/assetic": "1.1.*#dev",
"xlix/xlix": ">=0.*"
Now I am on the edge of despair an don't know what to do anymore.
Question:
Are there any mistakes I've made or is there anything i missed?

Packages live on the internet, not on your filesystem.
Composer searches by default for a package called xlix/xlix on packagist and that does not exists. You can add more package repositories by using the repositories configuration, more about that in the documentation.
So, in order to require your package with composer you need to upload your xlix directory somewhere.
I don't see what you are trying to do in the lxix directory? You are in the lxix package, why do you want to require it in the same package? It looks like you don't understand what those commands do and how composer works. Maybe a good read in their own documentation -- or some other tutorials about Composer (like the one on nettuts+) -- will help you to get a better understanding of composer.

Related

How to run scripts after a user installs my package via Composer?

I use the command composer require otra/otra:dev-develop --no-update --no-cache && composer update --no-autoloader to install my own framework.
I have put this section in my composer.json from my framework :
"scripts": {
"pre-install-cmd": "#composer config bin-dir bin/"
}
But Composer does not run it. Is this normal, does Composer consider this as a dependency and not the root package so it does not allow my script to run?
If this is the case, how can I have the same behaviour?
I want to :
have my binary in the bin folder, not vendor/bin without having to ask the user to do a symlink manually (or another solution)
copy a web folder from my framework to the root of the project.
Edit : with create-project command
If I type composer create-project otra/otra:dev-develop crashtest --remove-vcs, I get this composer.json :
{
"name": "otra/otra",
"type": "library",
"description": "The OTRA PHP framework",
"keywords": ["framework"],
"homepage": "https://github.com/lperamo/otra",
"license": "X11",
"authors": [
{
"name": "Lionel Péramo",
"email": "contact#lionel-peramo.com",
"homepage": "https://wexample.com"
}
],
"bin" : ["otra.php"],
"config": {
"bin-dir" : "bin/",
"sort-packages": true
},
"require": {
"ext-mbstring": "*",
"php": ">=7.4.0",
"symfony/yaml": "^4.0"
},
"require-dev": {
"ext-pdo": "*",
"ext-pdo_mysql": "*"
},
"scripts": {
"pre-install-cmd": "#composer config bin-dir bin/"
}
}
which is exactly the same as my framework so I cannot update it via Composer. I could with git if I do not use --remove-vcs but it is not the goal.
The output of the composer command is :
Installing otra/otra (dev-develop ab37237565155dab11812a7b2982d30ee240f051)
Installing otra/otra (dev-develop ab37237): Cloning ab37237565 from cache
Created project in crashtest
Loading composer repositories with package information
Installing dependencies (including require-dev) from lock file
Only scripts defined in the project's proper composer.json file are executed.
Scripts from required and installed packages are never executed because it would be terrible safety risk.
This is summarily explained in the docs:
Only scripts defined in the root package's composer.json are executed. If a dependency of the root package specifies its own scripts, Composer does not execute those additional scripts.
If your package users need to perform additional steps to use your package or library, explain those steps in your package documentation, and or provide scripts that they can execute manually and will perform those steps for them.
If your package is a "framework", as opposed to a library, what you could do is take advantage of composers create-project command.
That would require you to setup are repository with the default structure for a project, which would in turn depend on your package.
That's the way it's done with Symfony's Skeleton, for example.
With this kind of setup, you can create custom installation scripts and activate them with the post-create-project-cmd, and do some some extra setup steps, even interactive one, with something like this. (docs)
Be mindful that this script would only run when the package is installed using create-project, and never when using require.
Nobody mentioned, this can be achieved by creating a composer plugin and defining event handler for event post-package-install

Getting "Could not find a version of package .." in composer inspite of having tags in Github branch of package

I am learning on how to upload a package on packagist.org. I created a github repository for testing with composer.json file -
https://github.com/perials/check
and a composer package using this github repository - https://packagist.org/packages/perials/check
When I try to install this package using composer require perials/check I get below error
[InvalidArgumentException]
Could not find a version of package perials/check matching your minimum-stability (stable). Require it with an explicit version constraint allowing its desired stability.
From what I read in other related questions on SO this error occurs if there are no stable releases of github branch. But thing is that I already have some releases.
I also tried composer require perials/check:dev-master and composer require perials/check:7.1.0 but then I get below error
[InvalidArgumentException]
Could not find package perials/check.
Did you mean this?
perials/check
It was an issue with Singapore mirror for the packagist metadata. Now it should be resolved. https://github.com/composer/composer/issues/8347#issuecomment-537176755
If still not solve your issue please add "minimum-stability": "dev" in your composer.json
{
"name": "perials/check",
"description": "Package for testing packagist",
"license": "MIT",
"authors": [
{
"name": "Perials",
"email": "info#perials.com"
}
],
"autoload": {
"psr-4": {"Abc\\": "src/xyz"}
},
"require": {},
"minimum-stability": "dev"
}
I am also learning how to create packages and have the same problem, but in my case I created a v1.0.0 tag for my package and that solves the problem.
You can accept no stable version packages. See composer in docs (https://getcomposer.org/doc/04-schema.md#package-links).
Paste piece here for convinience:
You can apply them to a constraint, or apply them to an empty constraint if you want to allow unstable packages of a dependency for example.
composer.json:
{
"require": {
"monolog/monolog": "1.0.*#beta",
"acme/foo": "#dev"
}
}
In your case you would do:
{
"require": {
"perials/check": "7.1.0#dev"
}
}
and then run rm composer.lock; composer install.

composer issue with Merchant SDK for Express Checkout API on Paypal

I want to integrate a method from which a guest also can do payments on my site. So, i am implementing this SDK of paypal. It is required to install the compser and run it for dependencies. So, i ran this command to install composer.phar file inside samples folder
curl -sS https://getcomposer.org/installer | php -- --install-dir=/var/www/html/app/paypaltest/samples
then to install composer i ran this command:
php composer.phar install
But it is showing error as
Loading composer repositories with package information
Installing dependencies (including require-dev)
Your requirements could not be resolved to an installable set of packages.
Problem 1
- The requested package paypal/merchant-sdk-php 1.0.0 could not be found.
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 <http://getcomposer.org/doc/articles/troubleshooting.md> for further common problems.
Not sure why i am getting error of version 1.0.0 when i explicitly defining the version number i.e v3.8.107
This is the composer.json file which i am using. Can anyone help me know what is the issue and why can't i install the composer correctly. Am i missing any thing?
{
"name": "paypal/merchant-sdk-php",
"description": "PayPal Merchant SDK for PHP",
"keywords": ["paypal", "php", "sdk"],
"homepage": "https://developer.paypal.com",
"license": "Apache2",
"authors": [
{
"name": "PayPal",
"homepage": "https://github.com/paypal/merchant-sdk-php/contributors"
}
],
"require": {
"paypal/merchant-sdk-php":"v3.8.107"
},
"autoload": {
"psr-0": {
"PayPal\\Service": "lib/",
"PayPal\\CoreComponentTypes": "lib/",
"PayPal\\EBLBaseComponents": "lib/",
"PayPal\\EnhancedDataTypes": "lib/",
"PayPal\\PayPalAPI": "lib/"
}
}
}
Try just the following in your composer.json:
{
"require": {
"paypal/merchant-sdk-php": "v3.8.107"
}
}

How to add FirePHP using composer to Zend Framework 2

I'm trying to add FirePHP to my Zend Framework 2 project using composer, but I get errors.
My OS is a Windows 7.
I tried following ways to make it working:
I added following code to composer.json file:
"repositories": [{
"type": "vcs",
"url": "https://github.com/RobLoach/firephp-core"
}],
"require": {
"firephp/firephp-core": "dev-master" // Tried also: "firephp/firephp-core": "*"
}
Here is a error I got:
[RuntimeException]
Failed to clone http://github.com/RobLoach/firephp-core.git, git was not found, check that it is installed and in your PATH env.
I tried add to composer.json following code, which I found in firephp pull request. :
"require": {
"firephp/firephp-core": "*"
}
But it gives me same error I have posted above.
Composer is totally new for me. I couldn't find any helpful tutorial for it, so I'm not sure how does it work yet, but I'm doing my best to get familiar with it.
I hope someone can tell me what I'm doing wrong.
Thanks.
EDIT:
I got it working thanks to #Seldaek help, but it removed my Zend library folder.
Here is log from cmd:
E:\xampp\htdocs\ZendSkeleton>php composer.phar update
Loading composer repositories with package information
Updating dependencies (including require-dev)
- Installing firephp/firephp-core (dev-master f60753a)
Cloning f60753a8dd7817e4da6bc73e0e717387a9a0866a
- Removing zendframework/zendframework (2.0.5)
Writing lock file
Generating autoload files
Is there any way to stop removing Zend folder?
Here is my full composer.json file:
{
"name": "zendframework/skeleton-application",
"description": "Skeleton Application for ZF2",
"license": "BSD-3-Clause",
"keywords": [
"framework",
"zf2"
],
"homepage": "http://framework.zend.com/",
"require": {
"php": ">=5.3.3",
"zendframework/zendframework": "2.*"
},
"require": {
"firephp/firephp-core": "dev-master"
},
"config": {
"bin-dir": "E:/xampp/htdocs/ZendSkeleton/"
}
}
The problem is the package only has a dev-master version available, and those are by default installed with git. If you don't have git available in your PATH you can run composer with --prefer-dist which will force it to install from zip archives instead of via git. Something like composer update --prefer-dist should work out.
The better fix though would be to make sure that the git executable is accessible in your PATH environment variable. If you have no idea what I'm asking, maybe another option is to run composer from the "Git Bash" shell instead of cmd.exe.

Composer does not fetch dependencies from local repository

I am trying to add a local project A as dependency to project B. Using git daemon I am able to fetch project A as dependency, but the dependencies defined with require in the composer.json in project A are not recognized. What am I missing?
project A:
{
"name": "project/a",
"require": {
"monolog/monolog": "dev-master"
}
}
project B:
"repositories": [
{
"type": "vcs",
"url": "git://localhost/home/user/project-a"
}
],
"require": {
"project/a": "dev-master"
}
result (in project B):
vendor/
project/a
expected:
vendor/
project/a
monolog/monolog
The most likely explanation is that you forgot to commit the changes to your composer.json in /home/user/project-a.
To debug this you can use composer show project-a dev-master -v. The -v will output more verbose info while it loads the repository, and then you will see details about the version you are installing, if it does not contain the monolog require, then I would say my guess above was correct. If it does contain it, we got a serious bug in composer and you should report it on github.
I encountered a similar issue and my issue was that I was running composer update instead of composer install and one of the libraries that I required defined some of its dependencies as zipballs from GitHub.

Categories