https://github.com/ju1ius/luigi
Need to generate PHP code? Luigi does the plumbing!
https://github.com/ju1ius/luigi
code-builder code-generation codegen compiler-tool
Last synced: 5 months ago
JSON representation
Need to generate PHP code? Luigi does the plumbing!
- Host: GitHub
- URL: https://github.com/ju1ius/luigi
- Owner: ju1ius
- License: mit
- Created: 2023-02-05T22:06:44.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2023-02-05T23:53:35.000Z (almost 3 years ago)
- Last Synced: 2025-08-24T16:34:57.580Z (5 months ago)
- Topics: code-builder, code-generation, codegen, compiler-tool
- Language: PHP
- Homepage:
- Size: 12.7 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# ju1ius/luigi
[](https://codecov.io/gh/ju1ius/luigi)
Need to generate PHP code? Luigi does the plumbing!
## Installation
```sh
composer require ju1ius/luigi
```
## Basic usage
```php
use ju1ius\Luigi\CodeBuilder;
$code = CodeBuilder::create();
// The `raw` method adds verbatim code
$code->raw("return [\n");
// The `indent` method increases the indent level
$code->indent();
// The `write` does the same as `raw` but respects the indent level
$code->write("42,\n");
// The `writeln` method does the same as `write`, but adds a newline character after each argument.
$code->writeln('33,', '66,');
// The `dedent` method decreases the indent level
$code->dedent();
$code->writeln('];');
// CodeBuilder implements the `Stringable` interface
echo $code;
```
This is the expected output:
```php
return [
42,
33,
66,
];
```