1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace LaravelFeature\Console\Command; |
4
|
|
|
|
5
|
|
|
use Illuminate\Console\Command; |
6
|
|
|
use LaravelFeature\Service\FeaturesViewScanner; |
7
|
|
|
|
8
|
|
|
class ScanViewsForFeaturesCommand extends Command |
9
|
|
|
{ |
10
|
|
|
/** |
11
|
|
|
* The name and signature of the console command. |
12
|
|
|
* |
13
|
|
|
* @var string |
14
|
|
|
*/ |
15
|
|
|
protected $signature = 'feature:scan'; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* The console command description. |
19
|
|
|
* |
20
|
|
|
* @var string |
21
|
|
|
*/ |
22
|
|
|
protected $description = 'Scan project views to find new features.'; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @var FeaturesViewScanner |
26
|
|
|
*/ |
27
|
|
|
private $service; |
28
|
|
|
|
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* Create a new command instance. |
32
|
|
|
* |
33
|
|
|
* @return void |
|
|
|
|
34
|
|
|
*/ |
35
|
|
|
public function __construct() |
36
|
|
|
{ |
37
|
|
|
parent::__construct(); |
38
|
|
|
|
39
|
|
|
$this->service = app()->make(FeaturesViewScanner::class); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* Execute the console command. |
44
|
|
|
* |
45
|
|
|
* @return mixed |
46
|
|
|
*/ |
47
|
|
|
public function handle() |
48
|
|
|
{ |
49
|
|
|
$features = $this->service->scan(); |
50
|
|
|
$areEnabledByDefault = config('features.scanned_default_enabled'); |
51
|
|
|
|
52
|
|
|
$this->getOutput()->writeln(''); |
53
|
|
|
|
54
|
|
|
if (count($features) === 0) { |
55
|
|
|
$this->error('No features were found in the project views!'); |
56
|
|
|
$this->getOutput()->writeln(''); |
57
|
|
|
return; |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
$this->info(count($features) . ' features found in views:'); |
61
|
|
|
$this->getOutput()->writeln(''); |
62
|
|
|
|
63
|
|
|
foreach ($features as $feature) { |
64
|
|
|
$this->getOutput()->writeln('- ' . $feature); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
$this->getOutput()->writeln(''); |
68
|
|
|
$this->info('All the new features were added to the database with the ' |
69
|
|
|
. ($areEnabledByDefault ? 'ENABLED' : 'disabled') . |
70
|
|
|
' status by default. Nothing changed for the already present ones.'); |
71
|
|
|
|
72
|
|
|
$this->getOutput()->writeln(''); |
73
|
|
|
} |
74
|
|
|
} |
75
|
|
|
|
Adding a
@return
annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.Please refer to the PHP core documentation on constructors.