PHPackages                             absszero/phead - 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. absszero/phead

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

absszero/phead
==============

A PHP code generator to generate code via your LAYOUT file.

0.2.1(1y ago)112[1 PRs](https://github.com/absszero/phead/pulls)MITPHPPHP ^7.4 || ^8.0CI passing

Since Jan 6Pushed 5mo ago1 watchersCompare

[ Source](https://github.com/absszero/phead)[ Packagist](https://packagist.org/packages/absszero/phead)[ RSS](/packages/absszero-phead/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (3)Dependencies (5)Versions (6)Used By (0)

phead
=====

[](#phead)

A PHP code generator to generate code via your LAYOUT file.

[![Build Status](https://github.com/absszero/phead/workflows/build/badge.svg)](https://github.com/absszero/phead/actions)

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

[](#installation)

1. Install the package:

    ```
    composer global require absszero/phead
    ```
2. Set up Composer bin path:

    ### Linux / macOS

    [](#linux--macos)

    ```
    # Bash shell
    echo 'export PATH="$PATH:~/.composer/vendor/bin"' >> ~/.bashrc
    source ~/.bashrc

    # Z shell
    echo 'export PATH="$PATH:~/.composer/vendor/bin"' >> ~/.zshrc
    source ~/.zshrc

    # Fish shell
    fish_add_path ~/.composer/vendor/bin
    ```

    ### Windows

    [](#windows)

    1. Right click on Start up -&gt; System -&gt; Advance system settings -&gt; Environment variables -&gt; System variables\[below box\] -&gt; Select Path and click Edit.
    2. Click New and add this value `%USERPROFILE%\AppData\Roaming\Composer\vendor\bin`.

Usage
-----

[](#usage)

### From Sample

[](#from-sample)

```
# Get a sample layout file.
$ phead --sample my-layout.yaml

my-layout.yaml is generated.

# Generate code via your layout file.
$ phead my-layout.yaml

Generating files...
Hello/MyController.php
Hello/MyModel.php
```

### Dry run

[](#dry-run)

```
$ phead my-layout.yaml --dry

Generating files... (dry run)
Hello/MyController.php (skip)
Hello/MyModel.php (skip)
```

### Overwrite files

[](#overwrite-files)

Existing files will not be regenerated, you can overwrite with `--force`.

```
$ phead my-layout.yaml --force

Generating files... (force)
Hello/MyController.php (overwrite)
Hello/MyModel.php (overwrite)
```

### Only those files

[](#only-those-files)

Only those file keys will be generated.

```
$ phead my-layout.yaml --only=model1,model2

Generating files...
Hello/MyModel1.php
Hello/MyModel2.php
```

Layout
------

[](#layout)

Layout file has two main parts:

- `$globals`: The global variables.
- `$files`: The files for auto generation.

```
$globals:
  dir: Hello
  # Define a variable via environment variable
  user: '{{ $env.USER }}'

$files:
  # The file key
  model:

    # The file variables.
    # 'namespace', 'class' variables will be auto generated via 'to' path
    vars:
      foo: bar
      # Overwrite default namespace
      namespace: App\Hello

    # 'from', 'to' are required
    # 'from' can also be a stub file path,
    # EX. from: /my/stub/file.stub
    from: |
