This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include
, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | namespace Drupal\rabbitmq\Commands; |
||
4 | |||
5 | use Consolidation\OutputFormatters\StructuredData\PropertyList; |
||
6 | use Drupal\rabbitmq\ConnectionFactory; |
||
7 | use Drupal\rabbitmq\Consumer; |
||
8 | use Drupal\rabbitmq\Service\QueueInfo; |
||
9 | use Drush\Commands\DrushCommands; |
||
10 | use PhpAmqpLib\Connection\AMQPStreamConnection; |
||
11 | use PhpAmqpLib\Message\AMQPMessage; |
||
12 | |||
13 | /** |
||
14 | * Implementation of the Drush commands for RabbitMQ. |
||
15 | */ |
||
16 | class RabbitmqCommands extends DrushCommands { |
||
17 | |||
18 | const WORKER_DEFAULTS = [ |
||
19 | Consumer::OPTION_MEMORY_LIMIT => NULL, |
||
20 | Consumer::OPTION_MAX_ITERATIONS => NULL, |
||
21 | Consumer::OPTION_TIMEOUT => NULL, |
||
22 | ]; |
||
23 | |||
24 | /** |
||
25 | * The rabbitmq.queue_info service. |
||
26 | * |
||
27 | * @var \Drupal\rabbitmq\Service\QueueInfo |
||
28 | */ |
||
29 | protected $queueInfo; |
||
30 | |||
31 | /** |
||
32 | * The rabbitmq.consumer service. |
||
33 | * |
||
34 | * @var \Drupal\rabbitmq\Consumer |
||
35 | */ |
||
36 | protected $consumer; |
||
37 | |||
38 | /** |
||
39 | * RabbitmqCommands constructor. |
||
40 | * |
||
41 | * @param \Drupal\rabbitmq\Service\QueueInfo $queueInfo |
||
42 | * The rabbitmq.queue_info service. |
||
43 | * @param \Drupal\rabbitmq\Consumer $consumer |
||
44 | * The rabbitmq.consumer service. |
||
45 | */ |
||
46 | public function __construct( |
||
47 | QueueInfo $queueInfo, |
||
48 | Consumer $consumer |
||
49 | ) { |
||
50 | $this->queueInfo = $queueInfo; |
||
51 | $this->consumer = $consumer; |
||
52 | } |
||
53 | |||
54 | /** |
||
55 | * Connect to RabbitMQ and wait for jobs to do. |
||
56 | * |
||
57 | * @param string $queueName |
||
58 | * The name of the queue to process, also the name of the worker plugin. |
||
59 | * @param mixed $options |
||
60 | * The command options. |
||
61 | * |
||
62 | * @return int |
||
0 ignored issues
–
show
|
|||
63 | * Exit code. |
||
64 | * |
||
65 | * @command rabbitmq:worker |
||
66 | * @option Consumer::OPTION_MEMORY_LIMIT |
||
67 | * Set the max amount of memory the worker should occupy before exiting. |
||
68 | * Given in megabytes. |
||
69 | * @option Consumer::OPTION_MAX_ITERATIONS |
||
70 | * Number of iterations to process before exiting.If not present, exit |
||
71 | * criteria will not evaluate the amount of iterations processed. |
||
72 | * @option Consumer::OPTION_TIMEOUT |
||
73 | * Timeout to limit time worker should keep waiting messages from RabbitMQ. |
||
74 | * @aliases rqwk |
||
75 | */ |
||
76 | public function worker($queueName, $options = self::WORKER_DEFAULTS) { |
||
77 | $this->consumer->setOptionGetter(function (string $name) use ($options) { |
||
78 | return (int) $options[$name]; |
||
79 | }); |
||
80 | |||
81 | drupal_register_shutdown_function(function () use ($queueName) { |
||
82 | $this->consumer->shutdownQueue($queueName); |
||
83 | }); |
||
84 | |||
85 | $this->consumer->logStart(); |
||
86 | $this->consumer->consumeQueueApi($queueName); |
||
87 | } |
||
88 | |||
89 | /** |
||
90 | * Return information about a queue. |
||
91 | * |
||
92 | * @param string|null $queueName |
||
93 | * The name of the queue to get information from. |
||
94 | * |
||
95 | * @return \Consolidation\OutputFormatters\StructuredData\PropertyList|null |
||
96 | * The command result. |
||
97 | * |
||
98 | * @command rabbitmq:queue-info |
||
99 | * @aliases rqqi |
||
100 | * @field-labels |
||
101 | * queue-name: Queue name |
||
102 | * count: Items count |
||
103 | */ |
||
104 | public function queueInfo($queueName = NULL) { |
||
105 | if (NULL === $queueName) { |
||
106 | $this->yell('Queue name required.', NULL, 'red'); |
||
107 | return NULL; |
||
108 | } |
||
109 | $count = $this->queueInfo->count($queueName); |
||
110 | |||
111 | return new PropertyList(['queue-name' => $queueName, 'count' => $count]); |
||
112 | } |
||
113 | |||
114 | /** |
||
115 | * Run the RabbitMQ tutorial test producer. |
||
116 | * |
||
117 | * @see https://www.rabbitmq.com/tutorials/tutorial-one-php.html |
||
118 | * |
||
119 | * @command rabbitmq:test-producer |
||
120 | * @aliases rqtp |
||
121 | */ |
||
122 | View Code Duplication | public function testProducer() { |
|
123 | $connection = new AMQPStreamConnection( |
||
124 | ConnectionFactory::DEFAULT_HOST, |
||
125 | ConnectionFactory::DEFAULT_PORT, |
||
126 | ConnectionFactory::DEFAULT_USER, |
||
127 | ConnectionFactory::DEFAULT_PASS |
||
128 | ); |
||
129 | $channel = $connection->channel(); |
||
130 | $routingKey = $queueName = 'hello'; |
||
131 | $channel->queue_declare($queueName, FALSE, FALSE, FALSE, FALSE); |
||
132 | $message = new AMQPMessage('Hello World!'); |
||
133 | $channel->basic_publish($message, '', $routingKey); |
||
134 | $this->writeln(" [x] Sent 'Hello World!'"); |
||
135 | $channel->close(); |
||
136 | $connection->close(); |
||
137 | } |
||
138 | |||
139 | /** |
||
140 | * Run the RabbitMQ tutorial test consumer. |
||
141 | * |
||
142 | * @see https://www.rabbitmq.com/tutorials/tutorial-one-php.html |
||
143 | * |
||
144 | * @command rabbitmq:test-consumer |
||
145 | * @aliases rqtc |
||
146 | */ |
||
147 | public function testConsumer() { |
||
148 | $connection = new AMQPStreamConnection( |
||
149 | ConnectionFactory::DEFAULT_HOST, |
||
150 | ConnectionFactory::DEFAULT_PORT, |
||
151 | ConnectionFactory::DEFAULT_USER, |
||
152 | ConnectionFactory::DEFAULT_PASS |
||
153 | ); |
||
154 | $channel = $connection->channel(); |
||
155 | $queueName = 'hello'; |
||
156 | $channel->queue_declare($queueName, FALSE, FALSE, FALSE, FALSE); |
||
157 | $this->writeln(' [*] Waiting for messages. To exit press CTRL+C'); |
||
158 | |||
159 | $callback = function ($msg) { |
||
160 | $this->writeln(" [x] Received {$msg->body}"); |
||
161 | }; |
||
162 | |||
163 | $channel->basic_consume($queueName, '', FALSE, TRUE, FALSE, FALSE, $callback); |
||
164 | |||
165 | while (count($channel->callbacks)) { |
||
166 | $channel->wait(); |
||
167 | } |
||
168 | $channel->close(); |
||
169 | $connection->close(); |
||
170 | } |
||
171 | |||
172 | } |
||
173 |
This check compares the return type specified in the
@return
annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.