Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ryandadeng/laravel-file-generator
A Laravel File Generator to automate creation of interface, trait and class files.
https://github.com/ryandadeng/laravel-file-generator
file-generator laravel laravel-file-generator laravel-structure-generator
Last synced: 14 days ago
JSON representation
A Laravel File Generator to automate creation of interface, trait and class files.
- Host: GitHub
- URL: https://github.com/ryandadeng/laravel-file-generator
- Owner: RyanDaDeng
- License: other
- Created: 2018-12-07T09:30:14.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2018-12-12T12:13:04.000Z (about 6 years ago)
- Last Synced: 2024-11-24T11:25:55.145Z (about 1 month ago)
- Topics: file-generator, laravel, laravel-file-generator, laravel-structure-generator
- Language: PHP
- Homepage:
- Size: 2.82 MB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- Changelog: changelog.md
- Contributing: contributing.md
- License: license.md
Awesome Lists containing this project
README
# Laravel File Generator
[![Latest Version on Packagist][ico-version]][link-packagist]
[![Total Downloads][ico-downloads]][link-downloads]A Laravel File Generator which allows you to:
1. quickly generate trait, class and interface
2. automate the creation of repeated php files
3. help you generate code base structure (modular,pattern etc.)The main logic is using Blade template engine to populate the files. Feel free to look into the source code.
## Preview Demo
![](https://github.com/RyanDaDeng/design-patterns/blob/master/preview.gif)## Generation Demo
![](https://github.com/RyanDaDeng/design-patterns/blob/master/generation.gif)## Next Release features
1. will support command line generator
2. will support schema validation
3. will cover tests
4. will support webpage realtime preview## Requirement
This package requires the following dependencies:
- Laravel 5.x
- php > 7 (if you need support for version below 7, please create issue ticket)## Installation
Via Composer
``` bash
$ composer require timehunter/laravel-file-generator "^1.8.0"
```If your Laravel framework version <= 5.4, please register the service provider in your config file: /config/app.php, otherwise please skip it.
``` php
'providers'=[
....,
TimeHunter\LaravelFileGenerator\LaravelFileGeneratorServiceProvider::class
]
```And also ( Laravel framework version <= 5.4)
``` php
'aliases'=[
....,
'LaravelFileGenerator' => TimeHunter\LaravelFileGenerator\Facades\LaravelFileGenerator::class
]
```## Usage
#### Step 1
Create a file template in which you tell the generator what information will be appended to your file. e.g. the following is an example of Interface file template which implements InterfaceSimpleTemplateInterface:
``` php
app_path() . '/Example',
'interface_name' => 'ExampleInterface',
'namespace' => 'App\Example',
'functions' => [
'public function get()',
'public function update()'
],
'annotations'=[]
];
}
}
```- getTemplateData() : return your interface details, please refer to Schema section
#### Step 2
Pass the template to the publish function from LaravelFileGenerator facade class``` php
LaravelFileGenerator::publish(
new ExampleSimpleInterfaceTemplate(),
new ExampleSimpleTraitTemplate(),
new ExampleSimpleInterfaceTemplate()
...
); // publish() supports multiple parameters
```
#### Step 3
Check your folders if the file is generated.
You can also review the class before publishing:``` php
return LaravelFileGenerator::preview(new ExampleSimpleInterfaceTemplate());
```The function returns a View, so you can include it in any controller to see the outcome.
## Interfaces
| Interface | Usage | Description |
|----------------------------------|----------------------|----------------|
| ClassSimpleTemplateInterface | array schema type | Class file |
| InterfaceSimpleTemplateInterface | array schema type | Interface file |
| TraitSimpleTemplateInterface | array schema type | Trait file |For array schema type, they have the same function which returns schema of template:
``` php
getTemplateData()
```#### Trait Schema
``` php
public function getTemplateData()
{
return [
'directory' => app_path() . '/Example',
'namespace' => 'App\Example',
'use' => [
'App\Http\Controllers\Controller'
],
'trait_name' => 'ExampleTrait',
'traits' => [
'ExampleTrait'
],
'annotations'=[],
'functions' => [
'public function get()',
'public function update()'
]
];
}
```#### Interface Schema
``` php
public function getTemplateData()
{
return [
'directory' => app_path() . '/Test',
'interface_name' => 'ExampleInterface',
'namespace' => 'App\Example',
'annotations'=[],
'functions' => [
'public function get()',
'public function update()'
]
];
}
```#### Class Schema
``` php
public function getTemplateData()
{
return [
'class_type' => 'abstract class',
'directory' => app_path() . '/Example',
'namespace' =>'App\Example',
'use' => [
'App\Http\Controllers\Controller',
],
'class_name' => 'ExampleClass',
'extends' => 'Controller',
'implements' => ['sss', 'sss'],
'traits' => [
'ExampleTrait'
],
'properties' => [
'protected $repo'
],
'functions' => [
'public function get()',
'public function update()'
],
'annotations'=[]
];
}
```## Security
If you discover any security related issues, please email [email protected] instead of using the issue tracker.
## License
MIT. Please see the [license file](license.md) for more information.
[ico-version]: https://img.shields.io/packagist/v/timehunter/laravel-file-generator.svg?style=flat-square
[ico-downloads]: https://img.shields.io/packagist/dt/timehunter/laravel-file-generator.svg?style=flat-square[link-packagist]: https://packagist.org/packages/timehunter/laravel-file-generator
[link-downloads]: https://packagist.org/packages/timehunter/laravel-file-generator
[link-author]: https://github.com/RyanDaDeng/laravel-file-generator