Skip to content

Commit 0ce71f7

Browse files
committed
Console Commands
1 parent 6811912 commit 0ce71f7

File tree

3 files changed

+97
-1
lines changed

3 files changed

+97
-1
lines changed
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?php
2+
3+
namespace SoftinkLab\LaravelKeyvalueStorage\Console;
4+
5+
use Illuminate\Console\Command;
6+
use SoftinkLab\LaravelKeyvalueStorage\Facades\KVOption;
7+
8+
class KeyValueDeleteCommand extends Command
9+
{
10+
/**
11+
* The name and signature of the console command.
12+
*
13+
* @var string
14+
*/
15+
protected $signature = 'kvoption:delete {key}';
16+
17+
/**
18+
* The console command description.
19+
*
20+
* @var string
21+
*/
22+
protected $description = 'Delete a key-value pair in Key Value Storage';
23+
24+
/**
25+
* Create a new command instance.
26+
*
27+
* @return void
28+
*/
29+
public function __construct()
30+
{
31+
parent::__construct();
32+
}
33+
34+
/**
35+
* Execute the console command.
36+
*
37+
* @param \App\DripEmailer $drip
38+
* @return mixed
39+
*/
40+
public function handle()
41+
{
42+
KVOption::remove($this->argument('key'));
43+
$this->info('Key removed from the storage!');
44+
}
45+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?php
2+
3+
namespace SoftinkLab\LaravelKeyvalueStorage\Console;
4+
5+
use Illuminate\Console\Command;
6+
use SoftinkLab\LaravelKeyvalueStorage\Facades\KVOption;
7+
8+
class KeyValueStorageCommand extends Command
9+
{
10+
/**
11+
* The name and signature of the console command.
12+
*
13+
* @var string
14+
*/
15+
protected $signature = 'kvoption:create {key} {value} {--comment=}';
16+
17+
/**
18+
* The console command description.
19+
*
20+
* @var string
21+
*/
22+
protected $description = 'Create/Update a key-value pair in Key Value Storage';
23+
24+
/**
25+
* Create a new command instance.
26+
*
27+
* @return void
28+
*/
29+
public function __construct()
30+
{
31+
parent::__construct();
32+
}
33+
34+
/**
35+
* Execute the console command.
36+
*
37+
* @param \App\DripEmailer $drip
38+
* @return mixed
39+
*/
40+
public function handle()
41+
{
42+
KVOption::set($this->argument('key'), $this->argument('value'), $this->option('comment'));
43+
$this->info('Option storage updated!');
44+
}
45+
}

src/KeyValueStorageServiceProvider.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,13 @@ public function boot()
1616
__DIR__ . '/../config/kvstorage.php' => config_path('kvstorage.php'),
1717
]);
1818

19-
19+
//Commands
20+
if ($this->app->runningInConsole()) {
21+
$this->commands([
22+
Console\KeyValueStorageCommand::class,
23+
Console\KeyValueDeleteCommand::class,
24+
]);
25+
}
2026
}
2127

2228
/**

0 commit comments

Comments
 (0)