Download the PHP package mnsami/composer-custom-directory-installer without Composer
On this page you can find all versions of the php package mnsami/composer-custom-directory-installer. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download mnsami/composer-custom-directory-installer
More information about mnsami/composer-custom-directory-installer
Files in mnsami/composer-custom-directory-installer
Package composer-custom-directory-installer
Short Description A composer plugin, to help install packages of different types in custom paths.
License MIT
Informations about the package composer-custom-directory-installer
composer-custom-directory-installer
A Composer plugin to install packages in custom directories outside the default vendor folder.
This is not another composer-installer library for supporting non-composer package types such as application. By default it handles library-type packages, but you can extend it to any Composer package type via extra.installer-types in your root composer.json.
Table of Contents
- Why this plugin?
- Requirements
- Installation
- How to use
- Path Variables
- Path Variable Flags
- Matching Strategies
- Exact package name
- Package type prefix
- Wildcard vendor glob
- Custom
installer-name - Supporting Custom Package Types
- Complete example
- Real-world use cases
- WordPress with WPackagist
- Docker / keeping vendor outside the web root
- Monorepos with sibling library directories
- PascalCase or namespaced paths
- Migrating from oomphinc/composer-installers-extender
- Security
- Upgrading from v1.x
- Note
https://getcomposer.org/doc/04-schema.md#type
The type of the package. It defaults to library.
Package types are used for custom installation logic. If you have a package that needs some special logic, you can define a custom type. This could be a symfony-bundle, a wordpress-plugin or a typo3-module. These types will all be specific to certain projects, and they will need to provide an installer capable of installing packages of that type.
Why this plugin?
Composer has a built-in installer-paths key, but it only works if the package itself declares a dependency on composer/installers — something most packages on Packagist don't do. If you add an installer-paths rule for a package that doesn't opt in, Composer silently ignores it and installs the package to vendor/ anyway.
This plugin removes that constraint. It intercepts installation at the root-project level, so any package can be redirected to a custom path without requiring any changes to the package itself.
In short: if you've ever added installer-paths and nothing happened, this plugin is the fix.
Requirements
- PHP >= 8.1
- Composer 2.x
Installation
Add the plugin to the require section of your composer.json:
Important — Composer 2.2+ plugin trust:
Composer 2.2 and later require you to explicitly allow third-party plugins. Add the following to your composer.json:
Without this, Composer will either prompt interactively or block the plugin entirely in non-interactive (CI) environments.
How to use
In the extra section of your root composer.json, define the custom directory for each package:
This tells Composer to install monolog/monolog into the ./monolog/ directory instead of vendor/monolog/monolog.
Path Variables
You can use the following variables in your installer-paths to build dynamic paths:
| Variable | Description | Example value |
|---|---|---|
{$vendor} |
The vendor portion of the package name | monolog |
{$name} |
The package name (or installer-name override) |
monolog |
{$type} |
The Composer package type | library |
Path Variable Flags
You can append transformation flags after a pipe (|) to modify how a variable is substituted:
Flags are applied left-to-right in the order given:
| Flag | Transformation | Example input | Example output |
|---|---|---|---|
F |
Capitalize first letter (ucfirst) |
my-package |
My-package |
P |
Strip hyphens/underscores and capitalize each following word | my-package |
myPackage |
U |
Uppercase all characters | my-package |
MY-PACKAGE |
Flags can be combined. FP together produces PascalCase (capitalize first + strip separators):
| Expression | Input | Output |
|---|---|---|
{$name\|F} |
my-package |
My-package |
{$name\|P} |
my-package |
myPackage |
{$name\|FP} |
my-package |
MyPackage |
{$name\|U} |
my-package |
MY-PACKAGE |
{$vendor\|U} |
acme |
ACME |
Example:
For a package acme/my-package (type library), this resolves to src/ACME/MyPackage/.
Matching Strategies
installer-paths supports three matching strategies. Precedence is evaluated globally across all entries: all entries are first scanned for an exact name match, then for a type match, then for a wildcard match. An exact match in a later-listed entry always wins over a wildcard match in an earlier-listed entry.
1. Exact package name (highest precedence)
Matches one specific package:
2. Package type prefix
Matches all packages of a given Composer type using the type: prefix:
3. Wildcard vendor glob (lowest precedence)
Matches all packages from a given vendor using *:
Custom installer-name
A package can override the {$name} variable by setting installer-name in its own extra section (inside the package's composer.json, not the root project):
When set, {$name} in the path template will resolve to my-custom-name instead of the package's actual name.
Supporting Custom Package Types
By default the plugin only handles the library package type. To install packages of other types (e.g. drupal-module, wordpress-plugin) into custom directories, declare those types in extra.installer-types:
The plugin will claim any package whose type appears in installer-types and apply the matching installer-paths rule. Without this list, packages of non-library types are left to Composer's default installer.
Complete example
Real-world use cases
WordPress with WPackagist
Most WordPress plugins available via WPackagist don't require composer/installers, so native installer-paths silently fails for them. This plugin makes it work:
Docker / keeping vendor outside the web root
Put one package (e.g. a CLI tool) in a path that's bind-mounted into a container, while everything else stays in vendor/:
Monorepos with sibling library directories
Route internal packages to their canonical location in the repo tree:
PascalCase or namespaced paths
Use path variable flags to match the naming convention your framework expects:
acme/my-module installs to src/Modules/MyModule/.
Migrating from oomphinc/composer-installers-extender
oomphinc/composer-installers-extender has not had a functional release since December 2021. This plugin is a maintained, drop-in alternative with a superset of its features (path variable flags, three-pass precedence, traversal guards).
Before:
After:
The extra.installer-types and extra.installer-paths keys are identical — only the require and allow-plugins entries change. If you required composer/installers solely for path routing (not for any package's own declared dependency), you can remove it too.
Security
Resolved install paths are validated against two attack vectors:
- Directory traversal — a resolved path containing
..throws anInvalidArgumentException. - Absolute path injection — a resolved path that is absolute (starting with
/or a Windows drive letter) throws anInvalidArgumentException. This can occur when a package'sinstaller-nameis set to an absolute path value.
Both checks apply after all {$variable} substitutions are complete.
Upgrading from v1.x
| v1.x | v2.x | |
|---|---|---|
| PHP | >= 5.3 | >= 8.1 |
| Composer | 1.x / 2.x | 2.x only |
| Require string | "1.*" |
"^2.1" |
type: matching |
No | Yes |
Wildcard vendor/* |
No | Yes |
{$type} variable |
No | Yes |
allow-plugins needed |
No | Yes (Composer 2.2+) |
installer-types support |
No | Yes |
Path variable flags (\|F, \|P, \|U) |
No | Yes |
Existing installer-paths configurations (exact package names) are fully backwards-compatible and require no changes.
Note
Composer type: project is not supported by this installer, as packages with type project only make sense to be used with application shells like symfony/framework-standard-edition.
All versions of composer-custom-directory-installer with dependencies
composer-plugin-api Version ^2.0