mileschou/codegener

The helper for generate code.

v1.2.0 2020-03-04 15:48 UTC

This package is auto-updated.

Last update: 2020-03-04 15:49:05 UTC


README

Build Status 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.