Skip to content

Commit ea9c619

Browse files
committed
Add IdeHelper support for createJob().
1 parent 75a69ca commit ea9c619

File tree

3 files changed

+87
-3
lines changed

3 files changed

+87
-3
lines changed

config/bootstrap.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
<?php
22
use Cake\Core\Configure;
3+
use Queue\Generator\Task\QueuedJobTask;
34

4-
// Optionally load additional queue config defaults
5-
// from local app config
6-
5+
// Optionally load additional queue config defaults from local app config
76
if (file_exists(ROOT . DS . 'config' . DS . 'app_queue.php')) {
87
Configure::load('app_queue');
98
}
9+
10+
// For IdeHelper plugin if in use - make sure to run `bin/cake phpstorm generate` then
11+
$generatorTasks = (array)Configure::read('IdeHelper.generatorTasks');
12+
$generatorTasks[] = QueuedJobTask::class;
13+
Configure::write('IdeHelper.generatorTasks', $generatorTasks);

docs/README.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,27 @@ Then you can kill them gracefully with `-15` (or forcefully with `-9`, not recom
318318
Locally, if you want to kill them all, usually `killapp -15 php` does the trick.
319319
Do not run this with production ones, though.
320320

321+
## IDE support
322+
With [IdeHelper](https://github.com/dereuromark/cakephp-ide-helper/) plugin you can get typehinting and autocomplete for your createJob() calls.
323+
Especially if you use PHPStorm, this will make it possible to get support here.
324+
325+
Include that plugin, set up your generator config and run e.g. `bin/cake phpstorm generate`.
326+
327+
If you use `Plugin::load('Queue', ['bootstrap' => true, ...])`, the necessary config is already auto-included (recommended).
328+
Otherwise you can manually include the Queue plugin generator tasks in your `config/app.php` on project level:
329+
```php
330+
use Queue\Generator\Task\QueuedJobTask;
331+
332+
return [
333+
...
334+
'IdeHelper' => [
335+
'generatorTasks' => [
336+
QueuedJobTask::class
337+
],
338+
],
339+
];
340+
```
341+
321342
## Contributing
322343
I am looking forward to your contributions.
323344

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
<?php
2+
namespace Queue\Generator\Task;
3+
4+
use Cake\Core\App;
5+
use IdeHelper\Generator\Task\TaskInterface;
6+
use Queue\Queue\TaskFinder;
7+
8+
class QueuedJobTask implements TaskInterface {
9+
10+
/**
11+
* @var array
12+
*/
13+
protected $aliases = [
14+
'\Queue\Model\Table\QueuedJobsTable::createJob(0)',
15+
];
16+
17+
/**
18+
* @return array
19+
*/
20+
public function collect() {
21+
$map = [];
22+
23+
$models = $this->collectQueuedJobTasks();
24+
foreach ($models as $model => $className) {
25+
$map[$model] = '\\' . $className . '::class';
26+
}
27+
28+
$result = [];
29+
foreach ($this->aliases as $alias) {
30+
$result[$alias] = $map;
31+
}
32+
33+
return $result;
34+
}
35+
36+
/**
37+
* @return string[]
38+
*/
39+
protected function collectQueuedJobTasks() {
40+
$result = [];
41+
42+
$taskFinder = new TaskFinder();
43+
$tasks = $taskFinder->allAppAndPluginTasks();
44+
45+
foreach ($tasks as $task) {
46+
$className = App::className($task, 'Shell/Task', 'Task');
47+
48+
if (substr($task, 0, 6) === 'Queue.') {
49+
$task = 'Queue.' . substr($task, 11);
50+
} else {
51+
$task = substr($task, 5);
52+
}
53+
$result[$task] = $className;
54+
}
55+
56+
return $result;
57+
}
58+
59+
}

0 commit comments

Comments
 (0)