Skip to content

Commit b70f885

Browse files
committed
add make seed comamnd and remove fill command
1 parent aaf09c5 commit b70f885

File tree

16 files changed

+356
-389
lines changed

16 files changed

+356
-389
lines changed

README.md

Lines changed: 25 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -14,111 +14,79 @@ Install via composer
1414
composer require guysolamour/laravel-commands
1515
```
1616

17-
### Publish Configuration File
18-
19-
```bash
20-
php artisan vendor:publish --provider="Guysolamour\Command\ServiceProvider" --tag="config"
21-
```
2217

2318
## Usage
2419

2520
### Create Database Command
2621

2722
```bash
28-
php artisan cmd:db:create
23+
php artisan cmd:db:create databasename
2924
```
3025

31-
By default, the package will look for information at the **.env** file in the database section
32-
33-
However, you can pass the name of the database
34-
35-
```bash
36-
php artisan cmd:db:create {name}
37-
```
26+
You can use ***--help*** option to have more informations about this command
3827

39-
Supported drivers are (mysql & sqlite).
40-
The connection can be changed with 'connection' option which is mysql by default.
28+
### Drop Database Command
4129

4230
```bash
43-
php artisan cmd:db:create {name} --connection={mysql|sqlite}
31+
php artisan cmd:db:drop databasename
4432
```
4533

46-
For mysql driver, login credentials can be changed with the options below:
34+
You can use ***--help*** option to have more informations about this command
4735

48-
```bash
49-
php artisan cmd:db:create {name}
50-
--connection={mysql|sqlite}
51-
--username=root
52-
--password=root
53-
--port=3306
54-
```
5536

56-
### Drop Database Command
37+
### Trait Command
5738

5839
```bash
59-
php artisan cmd:db:drop
40+
php artisan cmd:make:trait traitname
6041
```
6142

62-
By default, the package will look for information at the **.env** file in the database section
63-
64-
However, you can pass the name of the database.
43+
Folder can be changed with ***--folder*** option
6544

6645
```bash
67-
php artisan cmd:db:drop {name}
46+
php artisan cmd:make:trait traitname --folder={folder}
6847
```
6948

70-
Supported drivers are (mysql & sqlite).
71-
The connection can be changed with 'connection' option which is mysql by default.
72-
73-
```bash
74-
php artisan cmd:db:drop {name} --connection={mysql|sqlite}
75-
```
49+
You can use ***--help*** option to have more informations about this command
7650

77-
For mysql driver, login credentials can be changed with the options below:
51+
### Service Provider Command
7852

7953
```bash
80-
php artisan cmd:db:drop {name}
81-
--connection={mysql|sqlite}
82-
--username=root
83-
--password=root
84-
--port=3306
54+
php artisan cmd:make:provider providername
8555
```
8656

87-
### Trait Command
57+
Folder can be changed with ***--folder*** option
8858

8959
```bash
90-
php artisan cmd:make:trait {name}
60+
php artisan cmd:make:provider providername --folder={folder}
9161
```
9262

93-
Folder name can be changed with _'folder'_ option
63+
You can use ***--help*** option to have more informations about this command
9464

95-
```bash
96-
php artisan cmd:make:trait {name} --folder={folder}
97-
```
98-
99-
### Service Provider Command
65+
### Helper Command
10066

10167
```bash
102-
php artisan cmd:make:provider {name}
68+
php artisan cmd:make:helper helpername
10369
```
10470

105-
Folder name can be changed with _'folder'_ option
71+
Folder name can be changed with ***--folder*** option
10672

10773
```bash
108-
php artisan cmd:make:provider {name} --folder={folder}
74+
php artisan cmd:make:helper helpername --folder={folder}
10975
```
76+
You can use ***--help*** option to have more informations about this command
11077

111-
### Helper Command
78+
### Seed Command
11279

11380
```bash
114-
php artisan cmd:make:helper {name}
81+
php artisan cmd:db:seed
11582
```
11683

117-
Folder name can be changed with _'folder'_ option
84+
If you want to run a specific class you can use ***--class*** option
11885

11986
```bash
120-
php artisan cmd:make:helper {name} --folder={folder}
87+
php artisan cmd:db:seed --class=UsersTableSeeder
12188
```
89+
You can use ***--help*** option to have more informations about this command
12290

12391
### Security
12492

config/command.php

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,5 @@
11
<?php
22

33
return [
4-
/*
5-
* The admin model namespace
6-
*/
7-
'admin_model' => 'App\\Admin', # App\Admin::class
8-
9-
/**
10-
* Le dossier ou mettre les models dans le dossier app
11-
* Laisser vide si vous voulez les mettre à la racine
12-
*/
13-
// 'models_folder' => 'Models',
14-
'models_folder' => '',
4+
155
];

src/Console/Commands/BaseCommand.php

Lines changed: 12 additions & 138 deletions
Original file line numberDiff line numberDiff line change
@@ -5,48 +5,35 @@
55
use Illuminate\Support\Str;
66
use Illuminate\Console\Command;
77
use Illuminate\Container\Container;
8-
use Illuminate\Filesystem\Filesystem;
98

109

1110
abstract class BaseCommand extends Command
1211
{
13-
14-
/**
15-
* @var string
16-
*/
17-
protected $template_path = '';
12+
/** @var string */
13+
private $template_path;
1814

1915

20-
protected $filesystem;
2116

2217

2318
public function __construct()
2419
{
2520
parent::__construct();
2621

27-
$this->template_path = (dirname(dirname(__DIR__))) . "/templates";
28-
$this->filesystem = new Filesystem;
22+
$this->template_path = dirname(dirname(__DIR__)) . "/stubs";
2923
}
3024

3125

32-
/**
33-
* Parse guard name
34-
* Get the guard name in different cases
35-
* @param string $name
36-
* @return array
37-
*/
38-
protected function parseName($name = null) :array
26+
protected function getTemplatePath(string $path = ''): string
27+
{
28+
$path = Str::start($path, '/');
29+
30+
return $this->template_path . $path;
31+
}
32+
33+
protected function parseName() :array
3934
{
4035
return [
4136
'{{namespace}}' => $this->getNamespace(),
42-
// '{{pluralCamel}}' => Str::plural(Str::camel($name)),
43-
// '{{pluralSlug}}' => Str::plural(Str::slug($name)),
44-
// '{{pluralSnake}}' => Str::plural(Str::snake($name)),
45-
// '{{pluralClass}}' => Str::plural(Str::studly($name)),
46-
// '{{singularCamel}}' => Str::singular(Str::camel($name)),
47-
// '{{singularSlug}}' => Str::singular(Str::slug($name)),
48-
// '{{singularSnake}}' => Str::singular(Str::snake($name)),
49-
// '{{singularClass}}' => Str::singular(Str::studly($name)),
5037
];
5138
}
5239

@@ -58,121 +45,8 @@ protected function parseName($name = null) :array
5845
protected function getNamespace()
5946
{
6047
$namespace = Container::getInstance()->getNamespace();
61-
return rtrim($namespace, '\\');
62-
}
63-
6448

65-
/**
66-
* @param string|array $files
67-
* @param string $path
68-
* @return void
69-
*/
70-
protected function compliedAndWriteFile($files, string $path): void
71-
{
72-
73-
if (is_array($files)) {
74-
foreach ($files as $file) {
75-
$this->compliedAndWriteFile($file, $path);
76-
}
77-
return;
78-
}
79-
80-
$data_map = $this->parseName();
81-
82-
$stub = $this->isSingleFile($files) ? $files : $this->filesystem->get($files->getRealPath());
83-
84-
$this->createDirectoryIfNotExists(
85-
$path,
86-
!$this->isSingleFile($files)
87-
);
88-
$complied = strtr($stub, $data_map);
89-
90-
$this->writeFile(
91-
$complied,
92-
$this->isSingleFile($files) ? $path : $path . '/' . $files->getFilenameWithoutExtension() . '.php'
93-
);
94-
}
95-
96-
97-
protected function compliedAndWriteFileRecursively($files, string $path)
98-
{
99-
if (is_array($files)) {
100-
foreach ($files as $file) {
101-
$this->compliedAndWriteFileRecursively($file, $path);
102-
}
103-
return;
104-
}
105-
106-
$this->compliedAndWriteFile(
107-
$this->filesystem->get($files),
108-
$path . '/' . $files->getRelativePath() . '/' . $files->getFilenameWithoutExtension() . '.php'
109-
);
110-
}
111-
112-
/**
113-
* @param string|array $files
114-
* @param string $search
115-
* @param string $path
116-
* @return void
117-
*/
118-
protected function replaceAndWriteFile($files, string $search, $replace, string $path)
119-
{
120-
if (is_array($files)) {
121-
foreach ($files as $file) {
122-
$this->replaceAndWriteFile($file, $search, $replace, $path);
123-
}
124-
return;
125-
}
126-
127-
$stub = $this->isSingleFile($files) ? $files : $this->filesystem->get($files->getRealPath());
128-
// $stub = $this->filesystem->get($files->getRealPath());
129-
$this->createDirectoryIfNotExists(
130-
$path,
131-
!$this->isSingleFile($files)
132-
);
133-
$complied = str_replace($search, $replace, $stub);
134-
135-
$this->writeFile(
136-
$complied,
137-
$this->isSingleFile($files) ? $path : $path . '/' . $files->getFilenameWithoutExtension() . '.php'
138-
);
139-
}
140-
141-
142-
/**
143-
* Permet de créer un dossier
144-
* @param string $path
145-
* @param boolean $folder Permet de savoir si le chemin passé est un dossier ou fichier
146-
* @return void
147-
*/
148-
protected function createDirectoryIfNotExists(string $path, bool $folder = true): void
149-
{
150-
151-
$dir = $folder ? $path : $this->filesystem->dirname($path);
152-
153-
if (!$this->filesystem->exists($dir)) {
154-
$this->filesystem->makeDirectory($dir, 0755, true);
155-
}
156-
}
157-
158-
/**
159-
* @param mixte $compiled
160-
* @param string $path
161-
* @return void
162-
*/
163-
protected function writeFile($compiled, string $path): void
164-
{
165-
// dd($path, $compiled);
166-
$this->filesystem->put(
167-
$path,
168-
$compiled
169-
);
170-
}
171-
172-
173-
protected function isSingleFile($file): bool
174-
{
175-
return is_string($file);
49+
return rtrim($namespace, '\\');
17650
}
17751

17852
}

src/Console/Commands/Database/BaseCommand.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ protected function getConnection()
2424
return $connection;
2525
}
2626
$this->error(sprintf("The [`%s`] connection is not allowed. Allowed values are [`%s`]", $connection, join(',', self::DEFAULT_CONNECTIONS)));
27-
// $this->error("The connection ['{$connection}'] must be mysql or sqlite");
2827
exit;
2928
}
3029

src/Console/Commands/Database/CreateDatabase.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ class CreateDatabase extends BaseCommand
3838
*/
3939
public function handle()
4040
{
41-
4241
$connection = $this->getConnection();
4342

4443
$this->create($connection);
@@ -69,10 +68,12 @@ private function CreateSqliteDatabase($schemaName): void
6968
{
7069
$databaseName = $this->guestName($schemaName);
7170
$url = $this->SqliteFullPath($databaseName);
71+
7272
if (File::exists($url)){
7373
$this->error("{$databaseName} database already exists");
7474
exit;
7575
}
76+
7677
File::put($url, null);
7778
}
7879

@@ -86,7 +87,5 @@ private function CreateMysqlDatabase($schemaName): void
8687
$query = "CREATE DATABASE IF NOT EXISTS $schemaName CHARACTER SET $charset COLLATE $collation;";
8788

8889
$this->getPDO()->exec($query);
89-
9090
}
91-
9291
}

src/Console/Commands/Database/DropDatabase.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,5 @@ private function DropSqliteDatabase($schemaName): void
6868
private function DropMysqlDatabase($schemaName): void
6969
{
7070
$this->getPDO()->exec("DROP DATABASE IF EXISTS $schemaName");
71-
7271
}
7372
}

0 commit comments

Comments
 (0)