PHPackages                             brightnucleus/boilerplate - 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. brightnucleus/boilerplate

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

brightnucleus/boilerplate
=========================

Boilerplate package you can use to quickly create a new package from scratch.

v0.1.7(8y ago)319202MIT

Since Jun 8Compare

[ Source](https://github.com/brightnucleus/boilerplate)[ Packagist](https://packagist.org/packages/brightnucleus/boilerplate)[ RSS](/packages/brightnucleus-boilerplate/feed)WikiDiscussions Synced today

READMEChangelogDependencies (5)Versions (9)Used By (2)

Bright Nucleus Boilerplate
==========================

[](#bright-nucleus-boilerplate)

[![Latest Stable Version](https://camo.githubusercontent.com/542cd864ff966152f14a2ef6957f53ebea049eadfc3f98331b15afce646deed0/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6272696768746e75636c6575732f626f696c6572706c6174652e737667)](https://packagist.org/packages/brightnucleus/boilerplate)[![Total Downloads](https://camo.githubusercontent.com/d411ce47826ce6e3dbeaa1c4ca39ddb1bf98c7ba6b64592d6b263e25e5475b89/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6272696768746e75636c6575732f626f696c6572706c6174652e737667)](https://packagist.org/packages/brightnucleus/boilerplate)[![Latest Unstable Version](https://camo.githubusercontent.com/289ebd25d2489ef015c69945382e4a1050fdf8477da4c3ffa8a3f28cd3e3ecc2/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f767072652f6272696768746e75636c6575732f626f696c6572706c6174652e737667)](https://packagist.org/packages/brightnucleus/boilerplate)[![License](https://camo.githubusercontent.com/0f545c0ed66a9541b7345ddaf34c6f42dc6ca59d517f7c4787e5eda3dd83e1f4/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f6272696768746e75636c6575732f626f696c6572706c6174652e737667)](https://packagist.org/packages/brightnucleus/boilerplate)

Boilerplate package you can use to quickly create a new package from scratch.

Table Of Contents
-----------------

[](#table-of-contents)

- [Basic Usage](#basic-usage)
- [Customizing The Generated Boilerplate](#customizing-the-generated-boilerplate)
    - [Providing A Custom Config File](#providing-a-custom-config-file)
    - [Changing The Templates](#changing-the-templates)
    - [Changing The Placeholders](#changing-the-placeholders)
    - [Adding A Custom Setup Task](#adding-a-custom-setup-task)
- [Contributing](#contributing)
- [License](#license)

Basic Usage
-----------

[](#basic-usage)

To create a new package using composer, use the following command:

```
composer create-project brightnucleus/boilerplate
```

This will create a new folder called ``, clone the `brightnucleus/boilerplate` package into that folder, and run the setup scripts. These scripts will ask you several questions about the package you want to create.

Customizing The Generated Boilerplate
-------------------------------------

[](#customizing-the-generated-boilerplate)

If you want to use this package for your own purposes, you can either fork it and adapt the workflow and templates with some simple tweaks, or you can require it through Composer to extend it.

### Providing A Custom Config File

[](#providing-a-custom-config-file)

You can set the configuration file to be loaded through the `"extra"` key in the `composer.json` file:

```
  "extra": {
    "brightnucleus-boilerplate": {
      "config-file": "_config/defaults.php",
      "config-prefix": "BrightNucleus/Boilerplate"
    }
  },
```

If you want to modify the key that is used for this (`"brightnucleus-boilerplate"`), you can override the `Setup::getExtraKey()` method.

```
protected static function getExtraKey()
{
    return 'brightnucleus-boilerplate';
}
```

### Changing The Templates

[](#changing-the-templates)

The templates can be found in the `_templates` folder and can have an optional `.template` extension. Each template in that folder will be copied to the root folder, after it has been run through a Mustache renderer that replaces all the placeholders with the actual values you've provided during the script execution.

If there are subfolders within `_templates`, these subfolders and their content will also be mirrored within the root folder. So, you can build the entire file structure that will later land in your package root folder within this `_templates` folder.

Adding a new template is just a matter of adding a new file within that structure.

### Changing The Placeholders

[](#changing-the-placeholders)

The placeholders are defined within the `_config/defaults.php` file.

To add a new placeholder, you can just add a new element to the array referenced by `BrightNucleus/Boilerplate/Placeholders`.

Example:

```
$placeholders = [
    // [...]
    // The placeholder tag that Mustache will look for.
    'greeting'      => [
        // The name of the placeholder displayed when the user is asked for values.
        'name'        => 'Greeting',
        // The description of the placeholder displayed when the user is asked for values.
        'description' => 'The greeting you want to send within your HelloWorld app.',
        // The validation callable that will either return the validate value or throw an exception.
        'validation'  => function ($placeholder) { return Validation::validateTrimmed($placeholder); },
        // The default value to use if the user doesn't provide one.
        'default'     => 'Hello World',
    ],
];
```

This example will add a new placeholder `{{greeting}}` that you can use within your templates.

The validation value passed to `'validation'` needs to be a callable that gets the current value entered by the user, and needs to either return the validated form of that value, or throw an exception if the value does not meet the requirements. The `Validation` class provides some helper methods to do the actual validation.

The default value passed into `'default'` can be either a literal value to use, or a callable that gets the array of placeholders as an argument, and needs to return a value to use. Using this array, you can make one default value depend on the current value of another placeholder, provided that that placeholder has already been set before (ordering within the config file).

### Adding A Custom Setup Task

[](#adding-a-custom-setup-task)

The individual tasks are simple classes that implement the `BrightNucleus\Boilerplate\Scripts\SetupTask` interface:

```
interface SetupTask
{

    /**
     * Get the name of the current task.
     *
     * @since 0.1.0
     *
     * @return string Name of the task.
     */
    public function getName();

    /**
     * Complete the setup task.
     *
     * @since 0.1.0
     *
     * @return void
     */
    public function complete();
}
```

In most cases, it is probably preferable to extend `BrightNucleus\Boilerplate\Scripts\Task\AbstractTask` though, as this provides some convenience functionality.

Here's an example task that displays a "Boilerplate" logo in the console:

```
