|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Aimeos\MW\MQueue; |
|
4
|
|
|
|
|
5
|
|
|
|
|
6
|
|
|
class Stomp extends Base implements Iface |
|
7
|
|
|
{ |
|
8
|
|
|
private $queues = array(); |
|
9
|
|
|
|
|
10
|
|
|
|
|
11
|
|
|
/** |
|
12
|
|
|
* Returns the queue for the given name |
|
13
|
|
|
* |
|
14
|
|
|
* @param string $name Queue name |
|
15
|
|
|
* @return \Aimeos\MW\MQueue\Queue\Iface Message queue |
|
16
|
|
|
*/ |
|
17
|
|
|
public function getQueue( $name ) |
|
18
|
|
|
{ |
|
19
|
|
|
if( !isset( $this->queues[$name] ) ) |
|
20
|
|
|
{ |
|
21
|
|
|
$uri = $this->getConfig( 'uri', 'tcp://localhost:61613' ); |
|
22
|
|
|
$user = $this->getConfig( 'username', null ); |
|
23
|
|
|
$pass = $this->getConfig( 'password', null ); |
|
24
|
|
|
|
|
25
|
|
|
if( is_array( $uri ) ) |
|
26
|
|
|
{ |
|
27
|
|
|
foreach( $uri as $idx => $entry ) |
|
28
|
|
|
{ |
|
29
|
|
|
$iuser = ( is_array( $user) ? $user[$idx] : $user ); |
|
30
|
|
|
$ipass = ( is_array( $pass) ? $pass[$idx] : $pass ); |
|
31
|
|
|
|
|
32
|
|
|
$result = $this->connect( $entry, $iuser, $ipass ); |
|
33
|
|
|
|
|
34
|
|
|
if( $result instanceof \Stomp ) { |
|
|
|
|
|
|
35
|
|
|
break; |
|
36
|
|
|
} |
|
37
|
|
|
} |
|
38
|
|
|
} |
|
39
|
|
|
else |
|
40
|
|
|
{ |
|
41
|
|
|
$result = $this->connect( $uri, $user, $pass ); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
if( $result instanceof \StompException ) { |
|
|
|
|
|
|
45
|
|
|
throw new \Aimeos\MW\MQueue\Exception( $result->getMessage() ); |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
$this->queues[$name] = new \Aimeos\MW\MQueue\Queue\Stomp( $result, $name ); |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
return $this->queues[$name]; |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* Opens a connection to the message queue server |
|
57
|
|
|
* |
|
58
|
|
|
* @param string $uri Connection URI |
|
59
|
|
|
* @param string $user User name for authentication |
|
60
|
|
|
* @param string $pass Password for authentication |
|
61
|
|
|
* @return \Stomp|\StompException |
|
62
|
|
|
*/ |
|
63
|
|
|
protected function connect( $uri, $user, $pass ) |
|
64
|
|
|
{ |
|
65
|
|
|
try { |
|
66
|
|
|
return new \Stomp( $uri, $user, $pass ); |
|
67
|
|
|
} catch( \StompException $e ) { |
|
|
|
|
|
|
68
|
|
|
return $e; |
|
69
|
|
|
} |
|
70
|
|
|
} |
|
71
|
|
|
} |
This error could be the result of:
1. Missing dependencies
PHP Analyzer uses your
composer.jsonfile (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects thecomposer.jsonto be in the root folder of your repository.Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the
requireorrequire-devsection?2. Missing use statement
PHP does not complain about undefined classes in
ìnstanceofchecks. For example, the following PHP code will work perfectly fine:If you have not tested against this specific condition, such errors might go unnoticed.