Skip to content

Commit 0f09498

Browse files
authored
Merge pull request #177 from cakephp/rename-plugin-class
Rename Plugin to QueuePlugin
2 parents 23da00f + d96a817 commit 0f09498

File tree

3 files changed

+105
-81
lines changed

3 files changed

+105
-81
lines changed

src/Plugin.php

Lines changed: 2 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -16,85 +16,9 @@
1616
*/
1717
namespace Cake\Queue;
1818

19-
use Bake\Command\SimpleBakeCommand;
20-
use Cake\Console\CommandCollection;
21-
use Cake\Core\BasePlugin;
22-
use Cake\Core\Configure;
23-
use Cake\Core\ContainerInterface;
24-
use Cake\Core\PluginApplicationInterface;
25-
use Cake\Queue\Command\JobCommand;
26-
use Cake\Queue\Command\PurgeFailedCommand;
27-
use Cake\Queue\Command\RequeueCommand;
28-
use Cake\Queue\Command\WorkerCommand;
29-
use InvalidArgumentException;
30-
3119
/**
32-
* Plugin for Queue
20+
* @deprecated 2.2.1 Use QueuePlugin instead
3321
*/
34-
class Plugin extends BasePlugin
22+
class Plugin extends QueuePlugin
3523
{
36-
/**
37-
* Plugin name.
38-
*/
39-
protected ?string $name = 'Cake/Queue';
40-
41-
/**
42-
* Load routes or not
43-
*/
44-
protected bool $routesEnabled = false;
45-
46-
/**
47-
* Load the Queue configuration
48-
*
49-
* @param \Cake\Core\PluginApplicationInterface $app The host application
50-
* @return void
51-
*/
52-
public function bootstrap(PluginApplicationInterface $app): void
53-
{
54-
if (!Configure::read('Queue')) {
55-
throw new InvalidArgumentException(
56-
'Missing `Queue` configuration key, please check the CakePHP Queue documentation' .
57-
' to complete the plugin setup.',
58-
);
59-
}
60-
61-
foreach (Configure::read('Queue') as $key => $data) {
62-
if (QueueManager::getConfig($key) === null) {
63-
QueueManager::setConfig($key, $data);
64-
}
65-
}
66-
}
67-
68-
/**
69-
* Add console commands for the plugin.
70-
*
71-
* @param \Cake\Console\CommandCollection $commands The command collection to update
72-
* @return \Cake\Console\CommandCollection
73-
*/
74-
public function console(CommandCollection $commands): CommandCollection
75-
{
76-
if (class_exists(SimpleBakeCommand::class)) {
77-
$commands->add('bake job', JobCommand::class);
78-
}
79-
80-
return $commands
81-
->add('queue worker', WorkerCommand::class)
82-
->add('worker', WorkerCommand::class)
83-
->add('queue requeue', RequeueCommand::class)
84-
->add('queue purge_failed', PurgeFailedCommand::class);
85-
}
86-
87-
/**
88-
* Add DI container to Worker command
89-
*
90-
* @param \Cake\Core\ContainerInterface $container The DI container
91-
* @return void
92-
*/
93-
public function services(ContainerInterface $container): void
94-
{
95-
$container->add(ContainerInterface::class, $container);
96-
$container
97-
->add(WorkerCommand::class)
98-
->addArgument(ContainerInterface::class);
99-
}
10024
}

src/QueuePlugin.php

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
<?php
2+
declare(strict_types=1);
3+
4+
/**
5+
* CakePHP(tm) : Rapid Development Framework (https://cakephp.org)
6+
* Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org/)
7+
*
8+
* Licensed under The MIT License
9+
* For full copyright and license information, please see the LICENSE.txt
10+
* Redistributions of files must retain the above copyright notice.
11+
*
12+
* @copyright Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org/)
13+
* @link https://cakephp.org CakePHP(tm) Project
14+
* @since 2.2.1
15+
* @license https://opensource.org/licenses/MIT MIT License
16+
*/
17+
namespace Cake\Queue;
18+
19+
use Bake\Command\SimpleBakeCommand;
20+
use Cake\Console\CommandCollection;
21+
use Cake\Core\BasePlugin;
22+
use Cake\Core\Configure;
23+
use Cake\Core\ContainerInterface;
24+
use Cake\Core\PluginApplicationInterface;
25+
use Cake\Queue\Command\JobCommand;
26+
use Cake\Queue\Command\PurgeFailedCommand;
27+
use Cake\Queue\Command\RequeueCommand;
28+
use Cake\Queue\Command\WorkerCommand;
29+
use InvalidArgumentException;
30+
31+
/**
32+
* Plugin for Queue
33+
*/
34+
class QueuePlugin extends BasePlugin
35+
{
36+
/**
37+
* Plugin name.
38+
*/
39+
protected ?string $name = 'Cake/Queue';
40+
41+
/**
42+
* Load routes or not
43+
*/
44+
protected bool $routesEnabled = false;
45+
46+
/**
47+
* Load the Queue configuration
48+
*
49+
* @param \Cake\Core\PluginApplicationInterface $app The host application
50+
* @return void
51+
*/
52+
public function bootstrap(PluginApplicationInterface $app): void
53+
{
54+
if (!Configure::read('Queue')) {
55+
throw new InvalidArgumentException(
56+
'Missing `Queue` configuration key, please check the CakePHP Queue documentation' .
57+
' to complete the plugin setup.',
58+
);
59+
}
60+
61+
foreach (Configure::read('Queue') as $key => $data) {
62+
if (QueueManager::getConfig($key) === null) {
63+
QueueManager::setConfig($key, $data);
64+
}
65+
}
66+
}
67+
68+
/**
69+
* Add console commands for the plugin.
70+
*
71+
* @param \Cake\Console\CommandCollection $commands The command collection to update
72+
* @return \Cake\Console\CommandCollection
73+
*/
74+
public function console(CommandCollection $commands): CommandCollection
75+
{
76+
if (class_exists(SimpleBakeCommand::class)) {
77+
$commands->add('bake job', JobCommand::class);
78+
}
79+
80+
return $commands
81+
->add('queue worker', WorkerCommand::class)
82+
->add('worker', WorkerCommand::class)
83+
->add('queue requeue', RequeueCommand::class)
84+
->add('queue purge_failed', PurgeFailedCommand::class);
85+
}
86+
87+
/**
88+
* Add DI container to Worker command
89+
*
90+
* @param \Cake\Core\ContainerInterface $container The DI container
91+
* @return void
92+
*/
93+
public function services(ContainerInterface $container): void
94+
{
95+
$container->add(ContainerInterface::class, $container);
96+
$container
97+
->add(WorkerCommand::class)
98+
->addArgument(ContainerInterface::class);
99+
}
100+
}

tests/TestCase/PluginTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
namespace Cake\Queue\Test\TestCase;
55

66
use Cake\Core\Configure;
7-
use Cake\Queue\Plugin;
87
use Cake\Queue\QueueManager;
8+
use Cake\Queue\QueuePlugin;
99
use Cake\TestSuite\TestCase;
1010
use InvalidArgumentException;
1111
use TestApp\Application;
@@ -22,7 +22,7 @@ public function testBootstrapNoConfig()
2222
$this->expectException(InvalidArgumentException::class);
2323
$this->expectExceptionMessage('Missing `Queue` configuration key, please check the CakePHP Queue documentation to complete the plugin setup');
2424
Configure::delete('Queue');
25-
$plugin = new Plugin();
25+
$plugin = new QueuePlugin();
2626
$app = $this->getMockBuilder(Application::class)->disableOriginalConstructor()->getMock();
2727
$plugin->bootstrap($app);
2828
}
@@ -40,7 +40,7 @@ public function testBootstrapWithConfig()
4040
'logger' => 'stdout',
4141
];
4242
Configure::write('Queue', ['default' => $queueConfig]);
43-
$plugin = new Plugin();
43+
$plugin = new QueuePlugin();
4444
$app = $this->getMockBuilder(Application::class)->disableOriginalConstructor()->getMock();
4545
$plugin->bootstrap($app);
4646
$queueConfig['url'] = [

0 commit comments

Comments
 (0)