1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Cherrypulp\LaravelPackageGenerator\Commands; |
4
|
|
|
|
5
|
|
|
use Exception; |
6
|
|
|
use Illuminate\Console\Command; |
7
|
|
|
use Cherrypulp\LaravelPackageGenerator\Commands\Traits\InteractsWithUser; |
8
|
|
|
use Cherrypulp\LaravelPackageGenerator\Commands\Traits\ChangesComposerJson; |
9
|
|
|
use Cherrypulp\LaravelPackageGenerator\Commands\Traits\InteractsWithComposer; |
10
|
|
|
use Cherrypulp\LaravelPackageGenerator\Commands\Traits\ManipulatesPackageFolder; |
11
|
|
|
|
12
|
|
|
class PackageRemove extends Command |
13
|
|
|
{ |
14
|
|
|
use ChangesComposerJson; |
15
|
|
|
use ManipulatesPackageFolder; |
16
|
|
|
use InteractsWithUser; |
17
|
|
|
use InteractsWithComposer; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* The name and signature of the console command. |
21
|
|
|
* |
22
|
|
|
* @var string |
23
|
|
|
*/ |
24
|
|
|
protected $signature = 'package:remove |
25
|
|
|
{vendor : The vendor part of the namespace} |
26
|
|
|
{package : The name of package for the namespace} |
27
|
|
|
{--i|interactive : Interactive mode}'; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* The console command description. |
31
|
|
|
* |
32
|
|
|
* @var string |
33
|
|
|
*/ |
34
|
|
|
protected $description = 'Remove the existing package.'; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* Execute the console command. |
38
|
|
|
* |
39
|
|
|
* @return mixed |
40
|
|
|
*/ |
41
|
|
|
public function handle() |
42
|
|
|
{ |
43
|
|
|
$vendor = $this->getVendor(); |
44
|
|
|
$package = $this->getPackage(); |
45
|
|
|
|
46
|
|
|
$vendorFolderName = $this->getVendorFolderName($vendor); |
47
|
|
|
$packageFolderName = $this->getPackageFolderName($package); |
48
|
|
|
|
49
|
|
|
$relPackagePath = "packages/$vendorFolderName/$packageFolderName"; |
50
|
|
|
$packagePath = base_path($relPackagePath); |
|
|
|
|
51
|
|
|
|
52
|
|
|
if (getcwd() !== base_path()) { |
53
|
|
|
$packagePath = getcwd()."/".$relPackagePath; |
54
|
|
|
chdir(getcwd()); |
55
|
|
|
define("LARAVEL_PACKAGE_CLI_MODE", getcwd()); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
try { |
59
|
|
|
$this->composerRemovePackage($vendorFolderName, $packageFolderName); |
60
|
|
|
$this->removePackageFolder($packagePath); |
61
|
|
|
$this->unregisterPackage($vendor, $package, "packages/$vendorFolderName/$packageFolderName"); |
62
|
|
|
$this->composerDumpAutoload(); |
63
|
|
|
|
64
|
|
|
return 0; |
65
|
|
|
} catch (Exception $e) { |
66
|
|
|
$this->error($e->getMessage()); |
67
|
|
|
|
68
|
|
|
return -1; |
69
|
|
|
} |
70
|
|
|
} |
71
|
|
|
} |
72
|
|
|
|