Reputation: 371
Forgive a trivial Composer question:
Assume a php package is defined on GitHub and synched to Packagist in the usual way.
Its .json
All straightforward.
Running ‘composer install’ installs all the dependencies into e.g. vendor/my/dependents. But what about installing the root package itself? I guess I could perhaps put just the .json in the root, with the root package itself as a dependency, or just go to GitHub and take the source as a .zip from there. What is best practice? I must be missing something very obvious…
MORE...
I (think I) follow normal Composer setup, so perhaps replier @Nico Haase could elaborate.
To clarify: assume I develop a simple package – say twenty php class files some of which are invoked from a php global stub application example that is intended for embedding in a developer’s own code. I publish the class files in /src on a GitHub repo, together with composer.json ‘requiring’ other packages that my package depends on. The stub application is stored in /Examples, and the .json, README in the repo root. My package is then defined to Packagist for synching from GitHub.
‘Composer install’ downloads all the ‘required’ dependencies into their /vendor/project-name/package-name/src subdirectories.
Perfect.
Except that I also expected my class files to be downloaded into <root>/src – but they weren’t.
Since, to Nico's point, ‘composer require my/package’ would try to add my/package to the .json as an additional require, I would have thought it would be bounced with a ‘cannot also “require” the root package.
I am obviously up the proverbial gum tree, but where please?
MORE (2)...
Thanks Nico.
This .json is for one of several packages I have installed on GitHub and synched to Packagist . It is the simplest: only four php class files, a couple of stub global php files to invoke them and a php config file ‘required’ by one of the class files. All works fine if I manually copy the class files into /src. The stub files and config file that would be modified by the developer go into <root>, but that is the developer’s job.
{
"name": "decomplexity/sendoauth2",
"type": "library",
"description": "Wrapper for PHPMailer SMTP",
"license": "MIT",
"keywords": ["PHPMailer","OAuth2"],
"homepage": "https://github.com/decomplexity/SendOauth2",
"authors": [
{
"name": "Max Stewart",
"email": "[email protected]",
"homepage": "https://www.decomplexity.com"
}
],
"support": {
"email": "[email protected]"
},
"repositories": [
{
"type": "vcs",
"url": "https://github.com/decomplexity/SendOauth2"
}
],
"require": {
"php": ">=5.6.0",
"phpmailer/phpmailer": ">=6.8.0",
"thenetworg/oauth2-azure": ">=2.1.1",
"league/oauth2-client": ">=2.6.1",
"league/oauth2-google": ">=4.0.0"
},
"autoload": {
"psr-4": {
"decomplexity\\SendOauth2\\": "src/"
}
}
}
I could, of course, simply create a dummy package with its own .json, with this .json then specifying my new package (decomplexity/sendoauth2 in the example above) as a dependency. Alternatively, and equivalently, I could issue a php composer require decomplexity/sendoauth2; this will create a new .json on the fly with required dependency.
Upvotes: 0
Views: 1263
Reputation: 371
To finally answer my own question following Nico's advice and after testing: Composer MUST be treated as a strict dependencies-only installer even though it should have sufficient information to install the root package (the package 'named' at the head of the .json given it). The package one wants to install must be thought of as a dependent of another imaginary nameless package that does not need to exist in Packagist or anywhere else, vide my final paragraph above.
Composer Rule, OK!
Upvotes: 0