1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Lacasera\ApiJwtScaffold\Installers; |
4
|
|
|
|
5
|
|
|
abstract class InstallerContract |
6
|
|
|
{ |
7
|
|
|
|
8
|
|
|
abstract public function scaffold(); |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* install laravel-passport package using composer |
12
|
|
|
* @param $package |
13
|
|
|
* @return array|bool |
14
|
|
|
*/ |
15
|
|
|
public function installPackage($package) |
16
|
|
|
{ |
17
|
|
|
if (!class_exists("Laravel\Passport\Client")) { |
18
|
|
|
return $this->terminal("composer require ${package}"); |
19
|
|
|
} |
20
|
|
|
return true; |
21
|
|
|
} |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* run additional commands needed by passport |
25
|
|
|
* @param array $commands |
26
|
|
|
*/ |
27
|
|
|
public function runCommands(array $commands) |
28
|
|
|
{ |
29
|
|
|
foreach ($commands as $cmd) { |
30
|
|
|
$this->terminal("php artisan $cmd -q"); |
31
|
|
|
} |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @param $command |
36
|
|
|
* @return array |
37
|
|
|
*/ |
38
|
|
|
public function terminal($command) |
39
|
|
|
{ |
40
|
|
View Code Duplication |
if (function_exists('system')) { |
|
|
|
|
41
|
|
|
ob_start(); |
42
|
|
|
system($command, $status); |
43
|
|
|
$output = ob_get_contents(); |
44
|
|
|
ob_end_clean(); |
45
|
|
|
|
46
|
|
|
return compact('output', 'status'); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
View Code Duplication |
if (function_exists('passthru')) { |
|
|
|
|
50
|
|
|
ob_start(); |
51
|
|
|
passthru($command, $status); |
52
|
|
|
$output = ob_get_contents(); |
53
|
|
|
ob_end_clean(); |
54
|
|
|
|
55
|
|
|
return compact('output', 'status'); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
if (function_exists('exec')) { |
59
|
|
|
exec($command, $output, $status); |
60
|
|
|
$output = implode(""n"", $output); |
61
|
|
|
|
62
|
|
|
return compact('output', 'status'); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
if (function_exists('shell_exec')) { |
66
|
|
|
$output = shell_exec($command) ; |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
return compact('output', 'status'); |
70
|
|
|
} |
71
|
|
|
} |
72
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.