mileschou / codegener
The helper for generate code.
Installs: 1 376
Dependents: 1
Suggesters: 0
Security: 0
Stars: 3
Watchers: 2
Forks: 0
Open Issues: 0
Requires
- php: ^8.0
- illuminate/filesystem: ^8 | ^9 | ^10 | ^11
- psr/log: ^1.1 | ^2.0 | 3.0
Requires (Dev)
- illuminate/container: ^8 | ^9 | ^10 | ^11
- mikey179/vfsstream: ^1.6.7
- phpunit/phpunit: ^9.6
- squizlabs/php_codesniffer: ^3.7
README
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.