nunzion / composer-devlinks
Enables developers to autoload classes from projects outside the vendor directory. These links can replace projects inside the vendor directory and need not to be committed.
Requires
- php: >=5.3.0
This package is auto-updated.
Last update: 2024-12-09 02:54:50 UTC
README
Composer Devlinks automatically alters the file vendor/autoload.php
after it is generated by Composer and injects references to custom autoloaders which are defined in
a file named composer.links.dev.json
.
These autoloaders can map classes to different sources, so that
effectively referenced packages can be replaced through local ones.
Installation
To add Composer Devlinks to a project,
simply add a developer dependency on nunzion/composer-devlinks
to your project's composer.json
file and add a script element to include the linked autoloaders:
{
"require-dev": {
"nunzion/composer-devlinks": "*"
},
"scripts": {
"post-autoload-dump": "Nunzion\\Composer\\DevLinks\\Commands::includeLinkedAutoloaders"
}
}
Even if composer-devlinks
is missing in non-dev installations,
composer will not throw any errors when trying to run the script.
Usage
If you want to include your autoloader, you can create
a file named composer.links.dev.json
in the same directory as the composer.json
file:
{
"links": [
"../my-package/vendor/autoload.php"
]
}
All links were relative to composer.json
, absolute paths can be specified too.
If the link does not end with .php
, /vendor/autoload.php
will be appended automatically.
If the linked autoloader or the file composer.links.dev.json
cannot be found,
no errors will be thrown.
Example
Lets assume you are developing an application called "me/myapp" which depends on your composer package "me/mylibrary". While programming "me/myapp" you want to improve and extend "me/mylibrary" continuously.
Without Composer Devlinks you have to edit "me/mylibrary" in the vendor directory
of your "me/myapp" installation. Apparently this is not a good idea - as soon
as there is an update to "me/mylibrary" and you run composer update
your changes
will eventually be lost.
With Composer Devlinks you can clone both "me/mylibrary" and "me/myapp" into
different directories, e.g. test/me-mylibrary
and test/me-myapp
.
Then you can edit the file composer.json
in test/me-myapp
as explained above.
This change to composer.json
can be committed into your git repository.
In the next step, you can create the file composer.links.dev.json
in the directory test/me-myapp
to define
a developer link to test/me-mylibrary
with the following content:
{
"links": [
"../me-mylibrary"
]
}
Finally run composer install --dev
or composer update
for both projects
to generate the autoloaders.
Now whenever a class of "me/mylibrary" is loaded in test/me-myapp
,
it will be loaded from test/me-mylibrary
.
The file composer.links.dev.json
should not be committed as these developer
links should be defined only during development.
Author
Henning Dieterichs - henning.dieterichs@hediet.de
License
Composer Devlinks is licensed under the MIT License.