PHPackages                             sbuerk/composer-files-provider - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. sbuerk/composer-files-provider

ActiveComposer-plugin[Utility &amp; Helpers](/categories/utility)

sbuerk/composer-files-provider
==============================

Provide files from a stack based on resolver patterns

1.0.11(3y ago)46.9k[2 issues](https://github.com/sbuerk/composer-files-provider/issues)GPL-2.0-or-laterPHPPHP ^7.2 || ^7.3 || ^7.4 || ^8.0 || ^8.1

Since Sep 4Pushed 3y ago1 watchersCompare

[ Source](https://github.com/sbuerk/composer-files-provider)[ Packagist](https://packagist.org/packages/sbuerk/composer-files-provider)[ Docs](https://github.com/sbuerk/composer-files-provider)[ RSS](/packages/sbuerk-composer-files-provider/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (8)Versions (29)Used By (0)

[![test main](https://github.com/sbuerk/composer-files-provider/actions/workflows/ci.yml/badge.svg)](https://github.com/sbuerk/composer-files-provider/actions/workflows/ci.yml)

Composer Files Provider
=======================

[](#composer-files-provider)

This plugin acts as composer plugin in order to provide files in a installation aware manner. This means, that it searches in a configured boilerplate folder structure in a defined order for files, based on installation placeholders. To see how this works see corresponding section.

The behaviour of this plugin can be influenced by configuration in the `extra`section of the root `composer.json`. See section `options` for available options.

The mission
===========

[](#the-mission)

We had the need in several projects to provide different files based on some environment specific values, in a waterfall manner. This means, that the first matching file (`source`) in a defined pattern order will be used and copied to a defined destination (`target`).

It startet with environment specific `.htaccess` files, but it extended to other part configuration files to adjust configuration. As we wanted these files in the corresponding git repository to be managed, it startet with kind of bash scripts, duplicated and adjusted for different file types and added as composer scripts.

As it was kind of painfully to maintain these bash scripts over the several repositories, and special the different flavours the need for a sharable and maintainable solution with project-based configuration was born. However, thinking about it there were quite some stones in the way - creating a package with bash scripts would be easy, but because of the nature of configurable `bin` installation folder this was not quite easy to ensure. And how to provide an easy configuration on project level ?

Then the 💡 popped up - why not using the project root composer.json as configuration place, and instead of providing bash scripts implementing it as a clean composer plugin. This also enables us to have it tested, linted and more people's may help or contribute to it.

So far, that was the story of the mission and how this package has been born. May it be of help for you.

Alternative
===========

[](#alternative)

We're not aware of other open extensions that try to achieve the same in a similar way. We may have not searched properly or has been to stupid to find one. Let us know if there is a similar composer plugin.

Supported Versions
==================

[](#supported-versions)

versioncomposer versionsphp versionsnote0.x1.x, 2.x7.2, 7.3, 7.4, 8.0, 8.1abandoned - starting development1.x1.x, 2.x7.2, 7.3, 7.4, 8.0, 8.1actively supportedInstallation
============

[](#installation)

Simply add this package as a dependency:

```
$ composer require sbuerk/composer-files-provider
```

The plugin starts working directly. That means, if you have already provided the needed configuration will be processed directly. See the Info Command section to get more info about the current configuration and what may be matched or not.

Options
=======

[](#options)

Example configuration:

```
{
  "extra": {
    "sbuerk/composer-files-provider": {
      "template-root": "files-provider/",
      "resolvers": {
        "custom": [
          "%t%/%h%/%u%/%p%/%s",
          "%t%/%h%/%p%/%s",
          "%t%/%u%/%s",
          "%t%/%p%/%s",
          "%t%/default/%s"
        ]
      },
      "files": [
        {
          "label": "env based logo file",
          "source": "images/logo.png",
          "target": "images/logo.png",
          "resolver": "custom"
        },
        {
          "label": ".htaccess",
          "source": "public/.htaccess",
          "target": "public/.htaccess"
        }
      ]
    }
  }
}
```

optionoptionaldescriptiontemplate-rootyesThis defines the template root folder, which will be used to replace the `%t%` placeholder. Defaults to: `file-templates`resolversyesHere you can configure custom resolver definition(s), or override the default one.filesnoIf something should be done, at least one file configuration is needed. You can define multiple file definitions, using the same or different resolver stacks.Config: template-root
---------------------

[](#config-template-root)

The `template-root` defines the template folder for the file's lookup. The `%t%` placeholder will be replaced with the configured `template-root` or the default: `file-templates`.

Note: The path will trimm of slashes on the right side. So if using in path patterns, you have to add `/` yourself as directory separator.

Example:

```
{
  "extra": {
    "sbuerk/composer-files-provider": {
      "template-root": "custom-template-base-folder/",
      "resolvers": {},
      "files": []
    }
  }
}
```

Config: resolvers
-----------------

[](#config-resolvers)

You can define custom resolver definitions under `resolvers` in the format:

```
{
  "extra": {
    "sbuerk/composer-files-provider": {
      "resolvers": {
        "": [
          "",
          "
