Skip to content

Commit b5aa5b4

Browse files
author
Ionut Rusen
committed
Add interface generation to BothCommand
Introduced interface creation logic within BothCommand to ensure that corresponding interfaces are generated alongside services and repositories. This includes creating the necessary directory and checking for existing interfaces to avoid conflicts, as well as adding a new stub file for interface templates.
1 parent 65e0396 commit b5aa5b4

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

src/Commands/BothCommand.php

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,10 @@ public function __construct()
2020
public function handle()
2121
{
2222

23-
//SERVICE
23+
2424
$name = $this->argument('name');
2525

26+
//SERVICE
2627
if ( ! file_exists ( $path = base_path ( 'app/Services' ) ) )
2728
mkdir($path, 0777, true);
2829

@@ -48,6 +49,19 @@ public function handle()
4849

4950
$this->info("Repository pattern implemented for model ". $name);
5051

52+
//Interface
53+
if ( ! file_exists ( $path = base_path ( 'app/Interfaces' ) ) )
54+
mkdir($path, 0777, true);
55+
56+
if ( file_exists ( base_path ( "app/Interfaces/{$name}Interface.php" ) ) ) {
57+
$this->error("Interface with that name ({$name}) already exists");
58+
exit(0);
59+
}
60+
61+
self::createInterface($name);
62+
63+
$this->info("Interface pattern implemented");
64+
5165

5266
}
5367

@@ -69,6 +83,11 @@ protected static function createRepository($name)
6983
$template = str_replace( ['{{modelName}}'], [$name], self::GetStubs('Repository') );
7084
file_put_contents(base_path("app/Repositories/{$name}Repository.php"), $template);
7185
}
86+
protected static function createInterface($name)
87+
{
88+
$template = str_replace( ['{{modelName}}'], [$name], self::GetStubs('Repository') );
89+
file_put_contents(base_path("app/Repositories/{$name}Interface.php"), $template);
90+
}
7291

7392

7493
}

src/resources/Interface.stub

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
namespace App\Interfaces;
3+
4+
5+
6+
interface {{modelName}}Interface
7+
{
8+
//code
9+
}
10+

0 commit comments

Comments
 (0)