Update:
I really posted this package so you can see the problem yourself.
Look here naomik / yamldump
I am trying to make a small CLI tool and pack it with the composer.
The following is an extremely simplified version of the program, but this is enough to demonstrate the problem I am facing.
The project has one dependency, and one "binary" file
composer.json
{ "name": "naomik/yamldump", "version": "0.2.0", "bin": [ "bin/yamldump" ], "require": { "symfony/yaml": "2.5.3" } }
bin / yamldump
#!/usr/bin/env php <?php // use Yaml namespace use Symfony\Component\Yaml as Yaml; // autoload require_once "vendor/autoload.php"; // read yaml $yaml = file_get_contents(sprintf("%s/%s", getcwd(), $argv[1])); // create parser $parser = new Yaml\Parser(); // parse the yaml var_dump($parser->parse($yaml));
So when I install it globally, I get this
$ composer global require naomik/yamldump=dev-master
Files are installed on
~/.composer/vendor/bin/yamldump -> ../naomik/yamldump/bin/yamldump~/.composer/vendor/naomik/yamldump/~/.composer/vendor/symfony/yaml/
This is a problem because I was not going to install symfony/yaml and symfony/yaml . My vendor/autoload.php package can no longer find the Yaml package in the right place.
I do not mind that symfony/yaml was installed globally, but it would be reasonable for me that composer global require install the package as follows:
~/.composer/vendor/bin/yamldump -> ../naomik/yamldump/bin/yamldump~/.composer/vendor/naomik/yamldump/~/.composer/vendor/naomik/yamldump/vendor/symfony/yaml/
In the end, what if I have Package A , which depends on symfony/yaml=2.5.3 and Package B , which requires symfony/yaml=2.6.x ?
If composer global require sets ~/.composer/vendor/* dependencies, each globally required package cannot support its own version of its dependency requirements ...
I know this is a kind of confusing problem, but I really don't know how to start fixing it.
goal
User must be able to
$ composer global require naomik/yamldump=dev-master $ yamldump sample.yml
Error
$ yamldump sample.yml Warning: require_once(vendor/autoload.php): failed to open stream: No such file or directory in /Users/naomik/.composer/vendor/naomik/yamldump/bin/yamldump on line 8 Fatal error: require_once(): Failed opening required 'vendor/autoload.php' (include_path='.:') in /Users/naomik/.composer/vendor/naomik/yamldump/bin/yamldump on line 8
Question
Here it is black and white:
How do I plan to write the string require "vendor/autoload.php" and does it work with both locally installed packages and globally installed packages?