Skip to content
This repository was archived by the owner on Apr 16, 2024. It is now read-only.

Commit 30263e2

Browse files
committed
Add delete service command
1 parent 1ea6c18 commit 30263e2

File tree

3 files changed

+100
-3
lines changed

3 files changed

+100
-3
lines changed

src/Commands/ServiceDeleteCommand.php

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the lucid-console project.
5+
*
6+
* (c) Vinelab <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Lucid\Console\Commands;
13+
14+
use Lucid\Console\Finder;
15+
use Lucid\Console\Filesystem;
16+
use Illuminate\Console\GeneratorCommand;
17+
18+
/**
19+
* @author Charalampos Raftopoulos <[email protected]>
20+
*/
21+
class ServiceDeleteCommand extends GeneratorCommand
22+
{
23+
use Finder;
24+
use Filesystem;
25+
26+
/**
27+
* The base namespace for this command.
28+
*
29+
* @var string
30+
*/
31+
private $namespace;
32+
33+
/**
34+
* The Services path.
35+
*
36+
* @var string
37+
*/
38+
private $path;
39+
40+
/**
41+
* The console command name.
42+
*
43+
* @var string
44+
*/
45+
protected $name = 'delete:service';
46+
47+
/**
48+
* The console command description.
49+
*
50+
* @var string
51+
*/
52+
protected $description = 'Delete an existing Service';
53+
54+
/**
55+
* Get the stub file for the generator.
56+
*
57+
* @return string
58+
*/
59+
protected function getStub()
60+
{
61+
return __DIR__.'/../Generators/stubs/service.stub';
62+
}
63+
64+
/**
65+
* Execute the console command.
66+
*
67+
* @return bool|null
68+
*/
69+
public function fire()
70+
{
71+
try {
72+
$name = $this->getNameInput();
73+
74+
$this->deleteDirectory($this->findServicePath($name));
75+
76+
$this->info('Service '.$name.' deleted successfully.'."\n");
77+
78+
$this->info('Please remove your registered service providers, if any.');
79+
} catch (\Exception $e) {
80+
dd($e->getMessage(), $e->getFile(), $e->getLine());
81+
}
82+
}
83+
}

src/Filesystem.php

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,14 @@
1313

1414
/**
1515
* @author Abed Halawi <[email protected]>
16+
* @author Charalampos Raftopoulos <[email protected]>
1617
*/
1718
trait Filesystem
1819
{
1920
/**
2021
* Create an empty directory at the given path.
2122
*
22-
* @param string $path
23+
* @param string $path
2324
*
2425
* @return bool
2526
*/
@@ -31,13 +32,25 @@ public function createDirectory($path)
3132
/**
3233
* Create a file at the given path with the given contents.
3334
*
34-
* @param string $path
35-
* @param string $contents
35+
* @param string $path
36+
* @param string $contents
3637
*
3738
* @return bool
3839
*/
3940
public function createFile($path, $contents = '')
4041
{
4142
return $this->files->put($path, $contents);
4243
}
44+
45+
/**
46+
* Delete an existing directory at the given path.
47+
*
48+
* @param string $path
49+
*
50+
* @return bool
51+
*/
52+
public function deleteDirectory($path)
53+
{
54+
return $this->files->deleteDirectory($path, false);
55+
}
4356
}

src/Kernel.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ class Kernel extends ConsoleKernel
2727
Commands\NewCommand::class,
2828
Commands\JobMakeCommand::class,
2929
Commands\ServiceMakeCommand::class,
30+
Commands\ServiceDeleteCommand::class,
3031
Commands\FeatureMakeCommand::class,
3132
Commands\ServicesListCommand::class,
3233
Commands\FeaturesListCommand::class,

0 commit comments

Comments
 (0)