Skip to content

Commit 759c20e

Browse files
committed
[RF/EH] refactor, prepare many new features - wip
1 parent 4bc0395 commit 759c20e

19 files changed

+125
-65
lines changed

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,20 @@
88
[![Quality Score][ico-code-quality]][link-code-quality]
99
[![Total Downloads][ico-downloads]][link-downloads]
1010

11+
This is a package developed by us for internal use. It is supposed to help us during development and save plenty of time by automating many steps while creating typical entities. You can write your own Services (have to implement `Webfactor\Laravel\Generators\Contracts\ServiceInterface`) and register them in the `generators.php` config file, or use this as an inspiration for a own implementation.
12+
1113
## Install
1214

1315
Via Composer
1416

1517
``` bash
16-
$ composer require webfactor/laravel-generators
18+
$ composer require-dev webfactor/laravel-generators
1719
```
1820

1921
## Usage
2022

2123
``` bash
22-
php artisan make:entity {entity_name}
24+
php artisan make:entity {entity_name} {--schema=} {}
2325
```
2426

2527
Use *singular* for entity. This will automatically create (while respecting naming conventions):

config/generators.php

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,22 @@
66
* have to implement Webfactor\Laravel\Generators\Contracts\MakeServiceInterface.
77
*/
88
'services' => [
9-
Webfactor\Laravel\Generators\Services\MakeMigrationService::class,
10-
/*Webfactor\Laravel\Generators\Services\MakeLanguageService::class,
9+
/*Webfactor\Laravel\Generators\Services\MakeMigrationService::class,
10+
Webfactor\Laravel\Generators\Services\MakeLanguageService::class,
1111
Webfactor\Laravel\Generators\Services\MakeBackpackCrudModelService::class,
1212
Webfactor\Laravel\Generators\Services\MakeBackpackCrudControllerService::class,
1313
Webfactor\Laravel\Generators\Services\MakeBackpackCrudRequestService::class,
1414
Webfactor\Laravel\Generators\Services\MakeFactoryService::class,
1515
Webfactor\Laravel\Generators\Services\MakeSeederService::class,
1616
Webfactor\Laravel\Generators\Services\MakeRouteService::class,*/
17+
Webfactor\Laravel\Generators\Services\OpenIdeService::class,
18+
],
19+
20+
/*
21+
* Recipe classes for opening all generated files directly in IDE if the option --ide={key}
22+
* is used. Have to implement Webfactor\Laravel\Generators\Contracts\OpenIdeInterface.
23+
*/
24+
'ides' => [
25+
'pstorm' => Webfactor\Laravel\Generators\Recipes\PhpStormOpener::class,
1726
],
1827
];

src/Commands/MakeEntity.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,15 @@
99
class MakeEntity extends Command
1010
{
1111
/**
12-
* The name of the entity beeing created.
12+
* Paths to files which should automatically be opened in IDE if the
13+
* option --ide is set (and IDE capable).
14+
*
15+
* @var array
16+
*/
17+
public $filesToBeOpened = [];
18+
19+
/**
20+
* The name of the entity being created.
1321
*
1422
* @var string
1523
*/
@@ -27,7 +35,7 @@ class MakeEntity extends Command
2735
*
2836
* @var string
2937
*/
30-
protected $signature = 'make:entity {entity} {--schema="name:string"} {--migrate}';
38+
protected $signature = 'make:entity {entity} {--schema="name:string"} {--migrate} {--ide=}';
3139

3240
/**
3341
* The console command description.
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
3+
namespace Webfactor\Laravel\Generators\Contracts;
4+
5+
use Webfactor\Laravel\Generators\Commands\MakeEntity;
6+
7+
abstract class OpenInIdeAbstract
8+
{
9+
protected $files;
10+
11+
public function __construct(array $files)
12+
{
13+
$this->files = $files;
14+
}
15+
}

src/Contracts/MakeServiceInterface.php renamed to src/Contracts/OpenInIdeInterface.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace Webfactor\Laravel\Generators\Contracts;
44

5-
interface MakeServiceInterface
5+
interface OpenInIdeInterface
66
{
7-
public function make();
7+
public function open();
88
}

src/Contracts/MakeServiceAbstract.php renamed to src/Contracts/ServiceAbstract.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
use Webfactor\Laravel\Generators\Commands\MakeEntity;
66

7-
abstract class MakeServiceAbstract
7+
abstract class ServiceAbstract
88
{
99
protected $command;
1010

src/Contracts/ServiceInterface.php

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 ServiceInterface
6+
{
7+
public function call();
8+
}

src/MakeServices.php

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

55
use Webfactor\Laravel\Generators\Commands\MakeEntity;
6-
use Webfactor\Laravel\Generators\Contracts\MakeServiceInterface;
7-
use Webfactor\Laravel\Generators\Services\MakeMigrationService;
6+
use Webfactor\Laravel\Generators\Contracts\ServiceInterface;
7+
use Webfactor\Laravel\Generators\Services\MigrationService;
88

99
class MakeServices
1010
{
@@ -26,8 +26,8 @@ public function call()
2626
}
2727
}
2828

29-
private function callService(MakeServiceInterface $service)
29+
private function callService(ServiceInterface $service)
3030
{
31-
$service->make();
31+
$service->call();
3232
}
3333
}

src/MigrationSchema.php

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6,30 +6,12 @@ class MigrationSchema
66
{
77
protected $schema;
88

9-
protected $original;
10-
119
public function __construct(string $schema)
1210
{
13-
$this->original = $schema;
1411
$this->schema = collect();
1512

16-
$this->parse();
17-
}
18-
19-
private function parse()
20-
{
21-
foreach ($this->parseSchemaString($this->original) as $field) {
22-
$this->schema->push($this->parseField($field));
13+
foreach (explode(',', $schema) as $field) {
14+
$this->schema->push(new MigrationField($field));
2315
}
2416
}
25-
26-
private function parseSchemaString(string $schema)
27-
{
28-
return explode(',', $schema);
29-
}
30-
31-
private function parseField(string $field)
32-
{
33-
return new MigrationField($field);
34-
}
3517
}

src/Recipes/PhpStormOpener.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
namespace Webfactor\Laravel\Generators\Recipes;
4+
5+
use Webfactor\Laravel\Generators\Contracts\OpenInIdeAbstract;
6+
use Webfactor\Laravel\Generators\Contracts\OpenInIdeInterface;
7+
8+
class PhpStormOpener extends OpenInIdeAbstract implements OpenInIdeInterface
9+
{
10+
public function open()
11+
{
12+
foreach ($this->files as $file) {
13+
exec('pstorm ' . $file);
14+
}
15+
}
16+
}

0 commit comments

Comments
 (0)