decodelabs/hatch

Simple code generation tools

v0.1.0 2025-03-10 12:27 UTC

This package is auto-updated.

Last update: 2025-03-10 16:38:19 UTC


README

PHP from Packagist Latest Version Total Downloads GitHub Workflow Status PHPStan License

Simple code generation tools

Hatch provides a set of simple tools for generating PHP code.

Get news and updates on the DecodeLabs blog.

Installation

Install via Composer:

composer require decodelabs/hatch

Usage

Static arrays

Export arrays of data for reuse as config files or static loadable datastructures.

use DecodeLabs\Hatch;

$code = Hatch::exportStaticArray([
    'foo' => 'bar',
    'baz' => 'qux',
    'quux' => [
        'corge' => 'grault',
        'garply' => 12,
        'fred' => [
            'plugh' => 'xyzzy',
            'thud' => [1, 2, 3]
        ]
    ]
]);

echo $code;

This will output:

[
    'foo' => 'bar',
    'baz' => 'qux',
    'quux' => [
        'corge' => 'grault',
        'garply' => 12,
        'fred' => [
            'plugh' => 'xyzzy',
            'thud' => [1, 2, 3]
        ]
    ]
]

Licensing

Hatch is licensed under the MIT License. See LICENSE for the full license text.