Skip to content

Commit 6b4b750

Browse files
committed
feat: switch from aloe to sprout
1 parent 5482642 commit 6b4b750

File tree

4 files changed

+42
-52
lines changed

4 files changed

+42
-52
lines changed

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
"format": "vendor/bin/php-cs-fixer fix --config=.php_cs.dist.php --allow-risky=yes"
4040
},
4141
"require": {
42-
"dragonmantank/cron-expression": "^3.4"
42+
"dragonmantank/cron-expression": "^3.4",
43+
"leafs/sprout": "*"
4344
}
4445
}

src/Queue/Commands/DeleteJobCommand.php

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,15 @@
22

33
namespace Leaf\Queue\Commands;
44

5-
use Aloe\Command;
65
use Illuminate\Support\Str;
6+
use Leaf\Sprout\Command;
77

88
class DeleteJobCommand extends Command
99
{
10-
protected static $defaultName = 'd:job';
11-
public $description = 'Delete a job class';
12-
public $help = 'Delete a job class';
13-
14-
protected function config()
15-
{
16-
$this->setArgument('job', 'required', 'job name');
17-
}
10+
protected $signature = 'd:job
11+
{job : job name}';
12+
protected $description = 'Delete a job class';
13+
protected $help = 'Delete a job class';
1814

1915
protected function handle()
2016
{
@@ -24,15 +20,14 @@ protected function handle()
2420
$job .= 'Job';
2521
}
2622

27-
$file = \Aloe\Command\Config::rootpath(AppPaths('jobs') . "/$job.php");
23+
$file = getcwd() . DIRECTORY_SEPARATOR . AppPaths('jobs') . "/$job.php";
2824

29-
if (!file_exists($file)) {
25+
if (!\Leaf\FS\File::exists($file)) {
3026
$this->error("$job doesn't exist");
31-
3227
return 1;
3328
}
3429

35-
unlink($file);
30+
\Leaf\FS\File::delete($file);
3631

3732
$this->comment("$job deleted successfully");
3833

src/Queue/Commands/GenerateJobCommand.php

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,46 +2,44 @@
22

33
namespace Leaf\Queue\Commands;
44

5-
use Aloe\Command;
65
use Illuminate\Support\Str;
6+
use Leaf\Sprout\Command;
77

88
class GenerateJobCommand extends Command
99
{
10-
protected static $defaultName = 'g:job';
11-
public $description = 'Create a job class';
12-
public $help = 'Generate a new job class';
13-
14-
protected function config()
15-
{
16-
$this->setArgument('job', 'required', 'job name');
17-
}
10+
protected $signature = 'g:job
11+
{job : job name}';
12+
protected $description = 'Create a job class';
13+
protected $help = 'Generate a new job class';
1814

1915
protected function handle()
2016
{
17+
$rootDir = getcwd();
2118
$job = Str::studly(Str::singular($this->argument('job')));
2219

2320
if (!strpos($job, 'Job')) {
2421
$job .= 'Job';
2522
}
2623

27-
$file = \Aloe\Command\Config::rootpath(AppPaths('jobs') . "/$job.php");
24+
$file = $rootDir . DIRECTORY_SEPARATOR . AppPaths('jobs') . "/$job.php";
2825

29-
if (!is_dir(\Aloe\Command\Config::rootpath(AppPaths('jobs')))) {
30-
mkdir(\Aloe\Command\Config::rootpath(AppPaths('jobs')));
26+
if (!\Leaf\FS\Directory::exists($rootDir . DIRECTORY_SEPARATOR . AppPaths('jobs'))) {
27+
\Leaf\FS\Directory::create($rootDir . DIRECTORY_SEPARATOR . AppPaths('jobs'), [
28+
'recursive' => true,
29+
]);
3130
}
3231

33-
if (file_exists($file)) {
32+
if (\Leaf\FS\File::exists($file)) {
3433
$this->error("$job already exists");
35-
3634
return 1;
3735
}
3836

39-
touch($file);
40-
41-
$fileContent = \file_get_contents(__DIR__ . '/stubs/job.stub');
42-
$fileContent = str_replace('ClassName', $job, $fileContent);
37+
\Leaf\FS\File::create($file, function () use ($job) {
38+
$fileContent = \file_get_contents(__DIR__ . '/stubs/job.stub');
39+
$fileContent = str_replace('ClassName', $job, $fileContent);
4340

44-
file_put_contents($file, $fileContent);
41+
return $fileContent;
42+
});
4543

4644
$this->comment("$job generated successfully");
4745

src/Queue/Commands/QueueWorkCommand.php

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,22 @@
22

33
namespace Leaf\Queue\Commands;
44

5-
use Aloe\Command;
5+
use Leaf\Sprout\Command;
66

77
class QueueWorkCommand extends Command
88
{
99
protected $queueConfig;
1010

11-
protected static $defaultName = 'queue:work';
12-
public $description = 'Start your queue worker';
13-
public $help = 'Start your queue worker';
14-
15-
protected function config()
16-
{
17-
$this->queueConfig = MvcConfig('queue');
18-
$this->setOption('queue', 'queue', 'optional', 'The queue you want to run', $this->queueConfig['default']);
19-
}
11+
protected $signature = 'queue:work
12+
{--queue? : The queue you want to run}';
13+
protected $description = 'Start your queue worker';
14+
protected $help = 'Start your queue worker';
2015

2116
protected function handle()
2217
{
23-
$queue = $this->option('queue');
18+
$queue = $this->option('queue')
19+
?? $this->queueConfig = MvcConfig('queue')['default']
20+
?? null;
2421

2522
$this->writeln("Queue worker started for queue '$queue'...");
2623

@@ -33,14 +30,13 @@ protected function handle()
3330
\Leaf\FS\File::copy(__DIR__ . '/stubs/schema.yml', DatabasePath("{$this->queueConfig['connections'][$queue]['table']}.yml"));
3431
\Leaf\FS\File::copy(__DIR__ . '/stubs/schedules.yml', DatabasePath("{$this->queueConfig['connections'][$queue]['schedules.table']}.yml"));
3532

36-
\Aloe\Core::run(
37-
"php leaf db:migrate {$this->queueConfig['connections'][$queue]['table']}",
38-
$this->output
39-
);
40-
\Aloe\Core::run(
41-
"php leaf db:migrate {$this->queueConfig['connections'][$queue]['schedules.table']}",
42-
$this->output
43-
);
33+
sprout()
34+
->process("php leaf db:migrate {$this->queueConfig['connections'][$queue]['table']}")
35+
->run();
36+
37+
sprout()
38+
->process("php leaf db:migrate {$this->queueConfig['connections'][$queue]['schedules.table']}")
39+
->run();
4440
}
4541
} else {
4642
$this->writeln('> Using redis connection for queue...');

0 commit comments

Comments
 (0)