Skip to content

Commit 4d84df8

Browse files
committed
Merge branch '1.1'
2 parents e8461b5 + ad5ecdf commit 4d84df8

18 files changed

+271
-95
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Changelog
22

3-
All notable changes to `laravel-openinghours` will be documented in this file.
3+
All notable changes to `laravel-generators` will be documented in this file.
44

55
Updates should follow the [Keep a CHANGELOG](http://keepachangelog.com/) principles.
66

README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
[![Latest Version on Packagist][ico-version]][link-packagist]
44
[![Software License][ico-license]](LICENSE.md)
5+
[![StyleCI][ico-style-ci]][link-style-ci]
56
[![Build Status][ico-travis]][link-travis]
67
[![Coverage Status][ico-scrutinizer]][link-scrutinizer]
78
[![Quality Score][ico-code-quality]][link-code-quality]
@@ -18,7 +19,7 @@ $ composer require webfactor/laravel-generators
1819
## Usage
1920

2021
``` bash
21-
php artisan make:crud entity
22+
php artisan make:entity {entity_name}
2223
```
2324

2425
Use *singular* for entity. This will automatically create (while respecting naming conventions):
@@ -57,12 +58,14 @@ The MIT License (MIT). Please see [License File](LICENSE.md) for more informatio
5758

5859
[ico-version]: https://img.shields.io/packagist/v/webfactor/laravel-generators.svg?style=flat-square
5960
[ico-license]: https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square
61+
[ico-style-ci]: https://styleci.io/repos/125574603/shield
6062
[ico-travis]: https://img.shields.io/travis/webfactor/laravel-generators/master.svg?style=flat-square
6163
[ico-scrutinizer]: https://img.shields.io/scrutinizer/coverage/g/webfactor/laravel-generators.svg?style=flat-square
6264
[ico-code-quality]: https://img.shields.io/scrutinizer/g/webfactor/laravel-generators.svg?style=flat-square
6365
[ico-downloads]: https://img.shields.io/packagist/dt/webfactor/laravel-generators.svg?style=flat-square
6466

6567
[link-packagist]: https://packagist.org/packages/webfactor/laravel-generators
68+
[link-style-ci]: https://styleci.io/repos/125574603
6669
[link-travis]: https://travis-ci.org/webfactor/laravel-generators
6770
[link-scrutinizer]: https://scrutinizer-ci.com/g/webfactor/laravel-generators/code-structure
6871
[link-code-quality]: https://scrutinizer-ci.com/g/webfactor/laravel-generators

config/generators.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
3+
return [
4+
/*
5+
* Services that should be applied by make:entity as default. The classes for 'service'
6+
* have to implement Webfactor\Laravel\Generators\Contracts\MakeServiceInterface and
7+
* conversion uses Webfactor\Laravel\Generators\Contracts\ConversionNameInterface.
8+
*/
9+
'services' => [
10+
Webfactor\Laravel\Generators\Services\MakeMigrationService::class => [
11+
'name_conversion' => Webfactor\Laravel\Generators\Services\Conversion\MigrationName::class,
12+
'schema' => 'name:string',
13+
],
14+
Webfactor\Laravel\Generators\Services\MakeFactoryService::class => [
15+
'name_conversion' => Webfactor\Laravel\Generators\Services\Conversion\FactoryName::class,
16+
],
17+
Webfactor\Laravel\Generators\Services\MakeSeederService::class => [
18+
'name_conversion' => Webfactor\Laravel\Generators\Services\Conversion\SeederName::class,
19+
],
20+
Webfactor\Laravel\Generators\Services\MakeBackpackCrudService::class => [
21+
'name_conversion' => Webfactor\Laravel\Generators\Services\Conversion\BackpackCrudName::class,
22+
],
23+
],
24+
];

src/Commands/MakeCrudEntity.php

Lines changed: 0 additions & 91 deletions
This file was deleted.

src/Commands/MakeEntity.php

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php
2+
3+
namespace Webfactor\Laravel\Generators\Commands;
4+
5+
use Illuminate\Console\Command;
6+
use Webfactor\Laravel\Generators\MakeServices;
7+
8+
class MakeEntity extends Command
9+
{
10+
/**
11+
* The name and signature of the console command.
12+
*
13+
* @var string
14+
*/
15+
protected $signature = 'make:entity {entity} {--schema=}';
16+
/**
17+
* The console command description.
18+
*
19+
* @var string
20+
*/
21+
protected $description = 'Make Entity';
22+
/**
23+
* Create a new command instance.
24+
*
25+
* @return void
26+
*/
27+
public function __construct()
28+
{
29+
parent::__construct();
30+
}
31+
32+
/**
33+
* Execute the console command.
34+
*
35+
* @return mixed
36+
*/
37+
public function handle()
38+
{
39+
(new MakeServices($this))->call();
40+
}
41+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?php
2+
3+
namespace Webfactor\Laravel\Generators\Contracts;
4+
5+
interface ConversionNameInterface
6+
{
7+
public static function getName(string $entityName);
8+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
namespace Webfactor\Laravel\Generators\Contracts;
4+
5+
use Webfactor\Laravel\Generators\Commands\MakeEntity;
6+
7+
abstract class MakeServiceAbstract
8+
{
9+
protected $command;
10+
protected $options;
11+
protected $entity;
12+
13+
public function __construct(MakeEntity $command, array $options)
14+
{
15+
$this->command = $command;
16+
$this->options = $options;
17+
$this->entity = $command->argument('entity');
18+
}
19+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?php
2+
3+
namespace Webfactor\Laravel\Generators\Contracts;
4+
5+
interface MakeServiceInterface
6+
{
7+
public function make();
8+
}

src/GeneratorsServiceProvider.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
namespace Webfactor\Laravel\Generators;
44

55
use Illuminate\Support\ServiceProvider;
6-
use Webfactor\Laravel\Generators\Commands\MakeCrudEntity;
6+
use Webfactor\Laravel\Generators\Commands\MakeEntity;
77

88
class GeneratorsServiceProvider extends ServiceProvider
99
{
@@ -16,9 +16,17 @@ public function boot()
1616
{
1717
if ($this->app->runningInConsole()) {
1818
$this->commands([
19-
MakeCrudEntity::class,
19+
MakeEntity::class,
2020
]);
21+
22+
$this->publishes([
23+
__DIR__ . '/../config/generators.php' => config_path('webfactor/generators.php'),
24+
], 'config');
2125
}
26+
27+
$this->mergeConfigFrom(
28+
__DIR__ . '/../config/generators.php', 'webfactor.generators'
29+
);
2230
}
2331

2432
/**

src/MakeServices.php

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
3+
namespace Webfactor\Laravel\Generators;
4+
5+
use Webfactor\Laravel\Generators\Commands\MakeEntity;
6+
use Webfactor\Laravel\Generators\Contracts\MakeServiceInterface;
7+
use Webfactor\Laravel\Generators\Services\MakeMigrationService;
8+
9+
class MakeServices
10+
{
11+
private $services;
12+
13+
private $command;
14+
15+
public function __construct(MakeEntity $command)
16+
{
17+
$this->command = $command;
18+
19+
$this->services = config('webfactor.generators.services', []);
20+
}
21+
22+
public function call()
23+
{
24+
foreach ($this->services as $service => $options) {
25+
$this->callService(new $service($this->command, $options));
26+
}
27+
}
28+
29+
private function callService(MakeServiceInterface $service)
30+
{
31+
$service->make();
32+
}
33+
}

0 commit comments

Comments
 (0)