forked from codeigniter4/queue
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQueuePublish.php
More file actions
89 lines (72 loc) · 2.97 KB
/
QueuePublish.php
File metadata and controls
89 lines (72 loc) · 2.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
<?php
declare(strict_types=1);
/**
* This file is part of CodeIgniter Queue.
*
* (c) CodeIgniter Foundation <admin@codeigniter.com>
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/
namespace CodeIgniter\Queue\Commands;
use CodeIgniter\CLI\CLI;
use CodeIgniter\Publisher\Publisher;
use Throwable;
class QueuePublish extends QueueCommand
{
protected $name = 'queue:publish';
protected $description = 'Publish Queue config file into the current application.';
public function run(array $params): void
{
$source = service('autoloader')->getNamespace('CodeIgniter\\Queue')[0];
$publisher = new Publisher($source, APPPATH);
try {
$publisher->addPaths([
'Config/Queue.php',
])->merge(false);
} catch (Throwable $e) {
$this->showError($e);
return;
}
foreach ($publisher->getPublished() as $file) {
$contents = file_get_contents($file);
$contents = str_replace('namespace CodeIgniter\\Queue\\Config', 'namespace Config', $contents);
$contents = str_replace('use CodeIgniter\\Config\\BaseConfig', 'use CodeIgniter\\Queue\\Config\\Queue as BaseQueue', $contents);
$contents = str_replace('class Queue extends BaseConfig', 'class Queue extends BaseQueue', $contents);
$method = <<<'EOT'
public function __construct()
{
parent::__construct();
if (ENVIRONMENT === 'testing') {
$this->database['dbGroup'] = config('database')->defaultGroup;
}
}
/**
* Resolve job class name.
*
* @return class-string<JobInterface>
*/
public function resolveJobClass(string $name): string
{
if (! isset($this->jobHandlers[$name])) {
throw QueueException::forIncorrectJobHandler();
}
return $this->jobHandlers[$name];
}
/**
* Stringify queue priorities.
*/
public function getQueuePriorities(string $name): ?string
{
if (! isset($this->queuePriorities[$name])) {
return null;
}
return implode(',', $this->queuePriorities[$name]);
}
EOT;
$contents = str_replace($method, '', $contents);
file_put_contents($file, $contents);
}
CLI::write(CLI::color(' Published! ', 'green') . 'You can customize the configuration by editing the "app/Config/Queue.php" file.');
}
}