mileschou/codegener

The helper for generate code.

v2.1.0 2023-04-13 08:20 UTC

This package is auto-updated.

Last update: 2024-04-13 10:28:15 UTC


README

tests codecov Codacy Badge Latest Stable Version Total Downloads License Beerpay

The helper for generate code.

Concept

Sometimes, we need to generate many code, like Scaffold, compiled code, even document.

This package can help to write code easily.

Usage

Writer class need Laravel Filesystem, it's testable, and need instance implemented PSR-3 Logger interface.

public function __construct(Filesystem $filesystem, LoggerInterface $logger)

Use write() method to put code instantly. Codegener will overwrite when $overwrite is true.

public function write(string $path, $content, bool $overwrite = false): void

Use writeMass if need generate many code.

public function writeMass(iterable $contents, bool $overwrite = false): void

Traits

Following traits is helper for process env and path.

Example

Following is an example code.

$writer->setBasePath('/path/to/your/project');

$code = [
    'some-foo' => 'foo',
    'some-bar' => 'bar',
];

$writer->writeMass($code);

Codegener will generate two files.

$ cat /path/to/your/project/some-foo
foo
$ cat /path/to/your/project/some-bar
bar

Example Projects

License

The MIT License (MIT). Please see License File for more information.