Skip to content

Commit

Permalink
Changed to the config file name to customize.php.
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexSkrypnyk committed May 28, 2024
1 parent be0f1c0 commit 45e1cb7
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 28 deletions.
4 changes: 2 additions & 2 deletions CustomizeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class CustomizeCommand extends BaseCommand {
/**
* Defines the file name for an optional external configuration file.
*/
const CONFIG_FILE = '.customizer.php';
const CONFIG_FILE = 'customize.php';

/**
* IO.
Expand Down Expand Up @@ -710,7 +710,7 @@ public static function messages(CustomizeCommand $c): array {
* class will **fully override** the questions defined here. This means that
* the configuration class must provide a full set of questions.
*
* See `.customizer.php` for an example of how to define questions.
* See `customize.php` for an example of how to define questions.
*
* @return array<string,array<string,string|callable>>
* An associative array of questions with question title as a key and the
Expand Down
28 changes: 13 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ logic without managing the Customizer's code itself.
}
}
```
2. Create `.customizer.php` file with questions and processing logic relevant
2. Create `customize.php` file with questions and processing logic relevant
to your template project and place it in anywhere in your project.

These entries will be removed by the Customizer after your project's users run
Expand Down Expand Up @@ -114,7 +114,7 @@ Make sure to adjust the path in the `classmap` and update
These entries will be removed by the Customizer after your project's users run
the `composer create-project` command.

4. Create `.customizer.php` file with questions and processing logic relevant
4. Create `customize.php` file with questions and processing logic relevant
to your template project and place it in anywhere in your project.

See the [Configuration](#configuration) section below for more information.
Expand All @@ -135,7 +135,7 @@ and see the Customizer in action:
composer create-project alexskrypnyk/template-project-example my-project
```

The demonstration questions provided in the [`.customizer.php`](https://github.com/AlexSkrypnyk/template-project-example/blob/main/.customizer.php)
The demonstration questions provided in the [`customize.php`](https://github.com/AlexSkrypnyk/template-project-example/blob/main/customize.php)
file will ask you to provide a package name, description, and license.
The answers are then processed by updating the `composer.json` file and
replacing the package name in the project files.
Expand All @@ -144,7 +144,7 @@ replacing the package name in the project files.

The template project authors can configure the Customizer, including defining
questions and processing logic, by providing a an arbitrary class (with any
namespace) in a `.customizer.php` file.
namespace) in a `customize.php` file.

The class has to implement `public static` methods to perform the configuration.

Expand All @@ -161,7 +161,7 @@ If a question does not have a process callback explicitly specified, a static
method prefixed with `process` and a camel-cased question title will be called.
If the method does not exist, there will be no processing.

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

```php
<?php
Expand All @@ -170,9 +170,7 @@ declare(strict_types=1);

use AlexSkrypnyk\Customizer\CustomizeCommand;

class CustomizerConfig {

public static function questions(CustomizeCommand $c): array {
public static function questions(CustomizeCommand $c): array {
// This an example of questions that can be asked to customize the project.
// You can adjust this method to ask questions that are relevant to your
// project.
Expand Down Expand Up @@ -243,12 +241,12 @@ class CustomizerConfig {
### `cleanup()`

Using the `cleanup()` method, the template project authors can additionally
process the `composer.json` file content before all dependencies are updated.
process the `composer.json` file content before all dependencies are updated.
This runs after all answers are received and the user confirms
the intended changes.

Use `$composerjson = [];` to prevent dependencies updates by the Customizer.
This essentially means that you are managing that process outside of this
Use `$composerjson = [];` to prevent dependencies updates by the Customizer.
This essentially means that you are managing that process outside of this
method.

```php
Expand Down Expand Up @@ -287,13 +285,13 @@ public static function messages(CustomizeCommand $c): array {

In case when a template repository authors want to make the Customizer to be
_truly_ drop-in single-file solution (installation [option 2](#as-a-standalone-class)
without `.customizer.php` file), they can define the questions and processing
logic in the `CustomizeCommand.php` file itself. In this case, `.customizer.php`
without `customize.php` file), they can define the questions and processing
logic in the `CustomizeCommand.php` file itself. In this case, `customize.php`
will not be required (but is still supported).

Note that if the `.customizer.php` file is present in the project, the questions
Note that if the `customize.php` file is present in the project, the questions
defined in the `CustomizeCommand.php` file will be ignored in favour of the
questions provided in the `.customizer.php` file.
questions provided in the `customize.php` file.

## Helpers

Expand Down
12 changes: 8 additions & 4 deletions .customizer.php → customize.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,18 @@
/**
* Customizer configuration.
*
* Example configuration for the Customizer command.
*
* phpcs:disable Drupal.Classes.ClassFileName.NoMatch
*
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
class CustomizerConfig {
class Customize {

/**
* Messages used by the command.
*
* @param CustomizeCommand $c
* @param \AlexSkrypnyk\Customizer\CustomizeCommand $c
* The Customizer instance.
*
* @return array<string,string|array<string>>
Expand Down Expand Up @@ -70,7 +74,7 @@ public static function messages(CustomizeCommand $c): array {
* ];
* @endcode
*
* @param CustomizeCommand $c
* @param \AlexSkrypnyk\Customizer\CustomizeCommand $c
* The CustomizeCommand object. Can be used to access the command properties
* and methods to prepare questions. Note that the questions callbacks
* already receive the command object as an argument, so this argument is
Expand Down Expand Up @@ -167,7 +171,7 @@ public static function questions(CustomizeCommand $c): array {
* The answer to the question.
* @param array<string,string> $answers
* All answers received so far.
* @param CustomizeCommand $c
* @param \AlexSkrypnyk\Customizer\CustomizeCommand $c
* The Customizer instance.
*
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
Expand Down
2 changes: 1 addition & 1 deletion phpcs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

<file>CustomizeCommand.php</file>
<file>Plugin.php</file>
<file>.customizer.php</file>
<file>customize.php</file>
<file>tests/phpunit</file>

<!-- Allow long array lines in tests. -->
Expand Down
2 changes: 1 addition & 1 deletion phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ parameters:
paths:
- CustomizeCommand.php
- Plugin.php
- .customizer.php
- customize.php
- tests/phpunit

excludePaths:
Expand Down
2 changes: 1 addition & 1 deletion rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
$rectorConfig->paths([
__DIR__ . '/CustomizeCommand.php',
__DIR__ . '/Plugin.php',
__DIR__ . '/.customizer.php',
__DIR__ . '/customize.php',
__DIR__ . '/tests/phpunit',
]);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,18 @@
/**
* Customizer configuration.
*
* Example of a customizer configuration file to test the plugin.
*
* phpcs:disable Drupal.Classes.ClassFileName.NoMatch
*
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
class CustomizerConfig {
class Customize {

/**
* Messages used by the command.
*
* @param CustomizeCommand $c
* @param \AlexSkrypnyk\Customizer\CustomizeCommand $c
* The command instance.
*
* @return array<string,string|array<string>>
Expand Down Expand Up @@ -70,7 +74,7 @@ public static function messages(CustomizeCommand $c): array {
* ];
* @endcode
*
* @param CustomizeCommand $c
* @param \AlexSkrypnyk\Customizer\CustomizeCommand $c
* The CustomizeCommand object. Can be used to access the command properties
* and methods to prepare questions. Note that the questions callbacks
* already receive the command object as an argument, so this argument is
Expand Down Expand Up @@ -167,7 +171,7 @@ public static function questions(CustomizeCommand $c): array {
* The answer to the question.
* @param array<string,string> $answers
* All answers received so far.
* @param CustomizeCommand $c
* @param \AlexSkrypnyk\Customizer\CustomizeCommand $c
* The command instance.
*
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
Expand Down

0 comments on commit 45e1cb7

Please sign in to comment.