PHPackages                             alexskrypnyk/customizer - 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. alexskrypnyk/customizer

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

alexskrypnyk/customizer
=======================

Interactive customization for template projects

0.5.0(1y ago)1475[5 issues](https://github.com/AlexSkrypnyk/customizer/issues)1GPL-2.0-or-laterPHPPHP &gt;=8.2CI passing

Since May 21Pushed 1mo ago2 watchersCompare

[ Source](https://github.com/AlexSkrypnyk/customizer)[ Packagist](https://packagist.org/packages/alexskrypnyk/customizer)[ Docs](https://github.com/alexskrypnyk/customizer)[ GitHub Sponsors](https://github.com/alexskrypnyk)[ Patreon](https://www.patreon.com/alexskrypnyk)[ RSS](/packages/alexskrypnyk-customizer/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (6)Dependencies (9)Versions (11)Used By (1)

  ![Customizer logo](logo.png)

Interactive customization for template projects
===============================================

[](#interactive-customization-for-template-projects)

[![GitHub Issues](https://camo.githubusercontent.com/7b5142291c27dcaa927baa4f8e4d1677fcd9e429a4700ef7a468b01531d50a8c/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6973737565732f416c6578536b7279706e796b2f637573746f6d697a65722e737667)](https://github.com/AlexSkrypnyk/customizer/issues)[![GitHub Pull Requests](https://camo.githubusercontent.com/8ff32680453ceb78fffa8883120153116a133d1f796c4d002440de77fedd175f/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6973737565732d70722f416c6578536b7279706e796b2f637573746f6d697a65722e737667)](https://github.com/AlexSkrypnyk/customizer/pulls)[![Test PHP](https://github.com/AlexSkrypnyk/customizer/actions/workflows/test-php.yml/badge.svg)](https://github.com/AlexSkrypnyk/customizer/actions/workflows/test-php.yml)[![codecov](https://camo.githubusercontent.com/641f841aaa5c3ad6e496719e144e2240351ede1f4bce2b79b667eefc6040204b/68747470733a2f2f636f6465636f762e696f2f67682f416c6578536b7279706e796b2f637573746f6d697a65722f67726170682f62616467652e7376673f746f6b656e3d37574542314958425954)](https://codecov.io/gh/AlexSkrypnyk/customizer)[![GitHub release (latest by date)](https://camo.githubusercontent.com/fefdf2a95af9655c350f131f7ad1add2bcf202bd0f7fa5c761e24648c34b99ac/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f762f72656c656173652f416c6578536b7279706e796b2f637573746f6d697a6572)](https://camo.githubusercontent.com/fefdf2a95af9655c350f131f7ad1add2bcf202bd0f7fa5c761e24648c34b99ac/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f762f72656c656173652f416c6578536b7279706e796b2f637573746f6d697a6572)[![LICENSE](https://camo.githubusercontent.com/bca956ad2705d6bcce0e614d874a1372332633ea872cf23a54f3fed4190af2e0/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f416c6578536b7279706e796b2f637573746f6d697a6572)](https://camo.githubusercontent.com/bca956ad2705d6bcce0e614d874a1372332633ea872cf23a54f3fed4190af2e0/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f416c6578536b7279706e796b2f637573746f6d697a6572)[![Renovate](https://camo.githubusercontent.com/35389190ce58a3690fe850342c1c3fd4f54e4c10ba8996741c8558ee24bf50dc/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f72656e6f766174652d656e61626c65642d677265656e3f6c6f676f3d72656e6f76617465626f74)](https://camo.githubusercontent.com/35389190ce58a3690fe850342c1c3fd4f54e4c10ba8996741c8558ee24bf50dc/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f72656e6f766174652d656e61626c65642d677265656e3f6c6f676f3d72656e6f76617465626f74)

---

The Customizer allows template project authors to ask users questions during the `composer create-project` command and then update the newly created project based on the received answers.

TL;DR
-----

[](#tldr)

Run the command below to create a new project from the [template project example](https://github.com/AlexSkrypnyk/template-project-example)and see the Customizer in action:

```
composer create-project alexskrypnyk/template-project-example my-project
```

Features
--------

[](#features)

- Simple installation into template project
- Runs customization on `composer create-project`
- Runs customization on `composer create-project --no-install` via `composer customize` command
- Configuration file for questions and processing logic
- Test harness for the template project to test questions and processing logic
- No additional dependencies for minimal footprint

Installation
------------

[](#installation)

1. Add to the template project as a Composer dependency:

    ```
    "require-dev": {
        "alexskrypnyk/customizer": "^0.5"
    },
    "config": {
        "allow-plugins": {
            "alexskrypnyk/customizer": true
        }
    }
    ```

    These entries will be removed by the Customizer after your project's users run the `composer create-project` command.
2. Copy [`customize.php`](customize.php) file with questions and processing logic in any location within your template project and adjust it as needed.

See the [Configuration](#configuration) section below for more information.

Usage example
-------------

[](#usage-example)

When your users run the `composer create-project` command, the Customizer will ask them questions and process the answers to customize their instance of the template project.

Run the command below to create a new project from the [template project example](https://github.com/AlexSkrypnyk/template-project-example)and see the Customizer in action:

```
composer create-project alexskrypnyk/template-project-example my-project
```

In this example, the [demonstration questions](https://github.com/AlexSkrypnyk/template-project-example/blob/main/customize.php)will ask you to provide a **package name**, **description**, and **license type**. The answers are then processed by updating the `composer.json` file and replacing the package name in other project files.

### `--no-install`

[](#--no-install)

Your users may run the `composer create-project --no-install` command if they want to adjust the project before installing dependencies, for example. Customizer will not run in this case as it is not being installed yet and it's dependencies entries will stay in the `composer.json` file.

The user will have to run `composer customize` manually to run the Customizer. It could be useful to let your users know about this command in your project's `README` file.

Configuration
-------------

[](#configuration)

You can configure how the Customizer processes your user’s template project by providing an arbitrary class (with any namespace) in a `customize.php` file. This includes defining questions and processing logic.

The class has to implement `public static` methods :

- [`questions()`](#questions) - defines questions; required
- [`process()`](#process) - defines processing logic based on received answers; required
- [`cleanup()`](#cleanup) - defines processing logic for the `composer.json` file; optional
- [`messages()`](#messages) - defines custom messages seen by the user; optional

### `questions()`

[](#questions)

Defines **questions**, their **discovery** and **validation** callbacks. Questions will be asked in the order they are defined. Questions can use answers from previous questions received so far.

The **discovery** callback is optional and runs before the question is asked. It can be used to discover the default answer based on the current state of the project. The discovered value is passed to the question callback. It can be an anonymous function or a method of the configuration class named `discover`.

The **validation** callback should return the validated answer or throw an exception with a message to be shown to the user. This uses inbuilt SymfonyStyle's [`ask()`](https://symfony.com/doc/current/components/console/helpers/questionhelper.html#asking-the-user-for-information)method for asking questions.

[`customize.php`](customize.php) has an example of the `questions()` method.

Note that while the Customizer examples use SymfonyStyle's [`ask()`](https://symfony.com/doc/current/components/console/helpers/questionhelper.html#asking-the-user-for-information)method, you can build your own question asking logic using any other TUI interaction methods. For example, you can use [Laravel Prompts](https://github.com/laravel/prompts).

### `process()`

[](#process)

Defines processing logic for all answers. This method will be called after all answers are received and the user confirms the intended changes. It has access to all answers and Customizer's class public properties and methods.

All file manipulations should be done within this method.

[`customize.php`](customize.php) has an example of the `process()` method.

### `cleanup()`

[](#cleanup)

Defines the `cleanup()` method after all files were processed but before all dependencies are updated.

The Customizer will remove itself from the project and will update the `composer.json` as required. This method allows to alter that process as needed and, if necessary, cancel the original self-cleanup.

[`customize.php`](customize.php) has an example of the `cleanup()` method.

### `messages()`

[](#messages)

Defines overrides for the Customizer's messages shown to the user.

[`customize.php`](customize.php) has an example of the `messages()` method.

### Example configuration

[](#example-configuration)

Click to expand an example configuration `customize.php` file```
