1
|
|
|
<?php |
|
|
|
|
2
|
|
|
error_reporting(E_ALL); |
3
|
|
|
ini_set('display_errors', 1); |
4
|
|
|
|
5
|
|
|
require 'vendor/autoload.php'; |
6
|
|
|
|
7
|
|
|
use GuzzleHttp\Client; |
8
|
|
|
use mcorten87\rabbitmq_api\jobs\JobBaseCreateVirtualHost; |
9
|
|
|
use mcorten87\rabbitmq_api\MqManagementConfig; |
10
|
|
|
use mcorten87\rabbitmq_api\MqManagementFactory; |
11
|
|
|
use mcorten87\rabbitmq_api\objects\Password; |
12
|
|
|
use mcorten87\rabbitmq_api\objects\QueueArgument; |
13
|
|
|
use mcorten87\rabbitmq_api\objects\QueueName; |
14
|
|
|
use mcorten87\rabbitmq_api\objects\Url; |
15
|
|
|
use mcorten87\rabbitmq_api\objects\User; |
16
|
|
|
use mcorten87\rabbitmq_api\objects\VirtualHost; |
17
|
|
|
use mcorten87\rabbitmq_api\services\MqManagermentService; |
18
|
|
|
|
19
|
|
|
function myErrorHandler($errno, $errstr, $errfile, $errline) |
|
|
|
|
20
|
|
|
{ |
21
|
|
|
if (!(error_reporting() & $errno)) { |
22
|
|
|
// This error code is not included in error_reporting |
23
|
|
|
return; |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
switch ($errno) { |
27
|
|
|
case 2: // Declaration of errors <- they are equal to the base... stop complaining |
28
|
|
|
return strpos($errstr, 'Declaration of') !== false; |
29
|
|
|
break; |
|
|
|
|
30
|
|
|
} |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
// set to the user defined error handler |
34
|
|
|
$old_error_handler = set_error_handler("myErrorHandler"); |
35
|
|
|
|
36
|
|
|
|
37
|
|
|
$url = new Url('http://192.168.33.11:15672/api/'); |
38
|
|
|
$user = new User('admin'); |
39
|
|
|
$password = new Password('admin'); |
40
|
|
|
|
41
|
|
|
$factory = new MqManagementFactory(); |
42
|
|
|
$config = new MqManagementConfig($user, $password, $url); |
43
|
|
|
$mqManagerment = new MqManagermentService($factory, $config); |
44
|
|
|
|
45
|
|
|
$client = new Client(); |
46
|
|
|
|
47
|
|
|
$jobService = $factory->getJobService(); |
48
|
|
|
|
49
|
|
|
//// list vhosts |
|
|
|
|
50
|
|
|
//$job = $factory->getJobListVirtualHost(); |
51
|
|
|
//var_dump($jobService->execute($job)->getBody()); |
52
|
|
|
//// |
53
|
|
|
//// create vhost |
54
|
|
|
//$job = $factory->getJobCreateVirtualHost(new VirtualHost('/foo/test')); |
55
|
|
|
//var_dump($jobService->execute($job)->getBody()); |
56
|
|
|
//// |
57
|
|
|
////// list vhosts |
58
|
|
|
//$job = $factory->getJobListVirtualHost(); |
59
|
|
|
//var_dump($jobService->execute($job)->getBody()); |
60
|
|
|
//// |
61
|
|
|
//$job = $factory->getJobListVirtualHost(new VirtualHost('/')); |
62
|
|
|
//var_dump($jobService->execute($job)->getBody()); |
63
|
|
|
// |
64
|
|
|
//// |
65
|
|
|
//// list specific vhost |
66
|
|
|
//$job = $factory->getJobListVirtualHost(new VirtualHost('/foo/test')); |
67
|
|
|
//var_dump($jobService->execute($job)->getBody()); |
68
|
|
|
// |
69
|
|
|
//// delete vhost |
70
|
|
|
//$job = $factory->getJobDeleteVirtualHost(new VirtualHost('/foo/test')); |
71
|
|
|
//var_dump($jobService->execute($job)->getBody()); |
72
|
|
|
// |
73
|
|
|
//// list vhosts |
74
|
|
|
//$job = $factory->getJobListVirtualHost(); |
75
|
|
|
//var_dump($jobService->execute($job)->getBody()); |
76
|
|
|
//// |
77
|
|
|
//// |
78
|
|
|
////// queues |
79
|
|
|
$job = $factory->getJobCreateQueue(new VirtualHost('/example/'),new QueueName('test')); |
80
|
|
|
$job->setDurable(true); |
81
|
|
|
$job->addArgument(new QueueArgument(QueueArgument::MAX_PRIORITY, 10)); |
82
|
|
|
var_dump($jobService->execute($job)->getBody()); |
|
|
|
|
83
|
|
|
// |
|
|
|
|
84
|
|
|
//$job = $factory->getJobListQueues(); |
85
|
|
|
//var_dump($jobService->execute($job)->getBody()); |
86
|
|
|
// |
87
|
|
|
//$job = $factory->getJobListQueues(new VirtualHost('/example/')); |
88
|
|
|
//var_dump($jobService->execute($job)->getBody()); |
89
|
|
|
// |
90
|
|
|
//$job = $factory->getJobListQueue(new VirtualHost('/example/'),new QueueName('test')); |
91
|
|
|
//var_dump($jobService->execute($job)->getBody()); |
92
|
|
|
//// |
93
|
|
|
//// |
94
|
|
|
//// |
95
|
|
|
//$job = $factory->getJobDeleteQueue(new VirtualHost('/example/'),new QueueName('test')); |
96
|
|
|
//var_dump($jobService->execute($job)->getBody()); |
97
|
|
|
// |
98
|
|
|
// |
99
|
|
|
//$job = $factory->getJobListUser(); |
100
|
|
|
//var_dump($jobService->execute($job)->getBody()); |
101
|
|
|
// |
102
|
|
|
// |
103
|
|
|
//$job = $factory->getJobCreateUser(new User('mathijs'), new UserTag(UserTag::MANAGEMENT), new Password('test')); |
104
|
|
|
//$job->addUserTag(new UserTag(UserTag::MONITORING)); |
105
|
|
|
//var_dump($jobService->execute($job)->getBody()); |
106
|
|
|
// |
107
|
|
|
//$job = $factory->getJobListUser(new User('mathijs')); |
108
|
|
|
//$userListResult = $jobService->execute($job); |
109
|
|
|
//$userListResult = json_decode($userListResult->getBody()); |
110
|
|
|
//var_dump($userListResult); |
111
|
|
|
// |
112
|
|
|
//$job = $factory->getJobCreateUser(new User("mathijs"), new UserTag(UserTag::MANAGEMENT), null, new PasswordHash($userListResult->password_hash)); |
113
|
|
|
//$job->addUserTag(new UserTag(UserTag::MONITORING)); |
114
|
|
|
//$job->addUserTag(new UserTag(UserTag::ADMINISTRATOR)); |
115
|
|
|
//var_dump($jobService->execute($job)->getBody()); |
116
|
|
|
// |
117
|
|
|
//$job = $factory->getJobListUser(new User('mathijs')); |
118
|
|
|
//var_dump($jobService->execute($job)->getBody()); |
119
|
|
|
|
120
|
|
|
//$job = $factory->getJobListPermission(); |
|
|
|
|
121
|
|
|
//var_dump($jobService->execute($job)->getBody()); |
122
|
|
|
// |
123
|
|
|
//$job = $factory->getJobListVirtualHostPermission(new VirtualHost('/example/')); |
124
|
|
|
//var_dump($jobService->execute($job)->getBody()); |
125
|
|
|
// |
126
|
|
|
//$job = $factory->getJobListUserPermission(new User('admin')); |
127
|
|
|
//var_dump($jobService->execute($job)->getBody()); |
128
|
|
|
|
129
|
|
|
//$job = $factory->getJobCreatePermission(new VirtualHost('/'), new User('admin')); |
|
|
|
|
130
|
|
|
//var_dump($jobService->execute($job)->getBody()); |
131
|
|
|
// |
132
|
|
|
//$job = $factory->getJobDeletePermission(new VirtualHost('/'), new User('admin')); |
133
|
|
|
//var_dump($jobService->execute($job)->getBody()); |
134
|
|
|
|
The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.
The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.
To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.