[COMPOSER] Added predis/predis and updated packages

This commit is contained in:
Miguel Dantas
2019-08-13 01:31:05 +01:00
committed by Diogo Cordeiro
parent 0bb35d7e7f
commit 630a578e1d
641 changed files with 58448 additions and 83 deletions

View File

@@ -0,0 +1,18 @@
<?php
namespace RabbitMq\ManagementApi\Api;
use RabbitMq\ManagementApi\Client;
/**
* @author Richard Fullmer <richard.fullmer@opensoftdev.com>
*/
class AbstractApi
{
protected $client;
public function __construct(Client $client)
{
$this->client = $client;
}
}

View File

@@ -0,0 +1,181 @@
<?php
namespace RabbitMq\ManagementApi\Api;
/**
* @author Richard Fullmer <richard.fullmer@opensoftdev.com>
*/
class Binding extends AbstractApi
{
/**
* A list of all bindings.
*
* OR
*
* A list of all bindings in a given virtual host.
*
* @param string|null $vhost
* @return array
*/
public function all($vhost = null)
{
if ($vhost) {
return $this->client->send(sprintf('/api/bindings/%s', urlencode($vhost)));
} else {
return $this->client->send('/api/bindings');
}
}
/**
* A list of all bindings between an exchange and a queue. Remember, an exchange and a queue can be bound together
* many times!
*
* @param string $vhost
* @param string $exchange
* @param string $queue
* @return array
*/
public function binding($vhost, $exchange, $queue)
{
return $this->client->send(sprintf('/api/bindings/%s/e/%s/q/%s', urlencode($vhost), urlencode($exchange), urlencode($queue)));
}
/**
* A list of all bindings between two exchanges. Remember, two exchanges can be bound together many times with
* different parameters!
*
* @param string $vhost
* @param string $source
* @param string $destination
*
* @return array
*/
public function exchangeBinding($vhost, $source, $destination)
{
return $this->client->send(sprintf('/api/bindings/%s/e/%s/e/%s', urlencode($vhost), urlencode($source), urlencode($destination)));
}
/**
* To create a new binding, POST to this URI. You will need a body looking something like this:
*
* {
* "routing_key": "my_routing_key",
* "arguments": []
* }
*
* All keys are optional. The response will contain a Location header telling you the URI of your new binding.
*
* @param string $vhost
* @param string $exchange
* @param string $queue
* @param string|null $routingKey
* @param array|null $arguments
* @return array
*/
public function create($vhost, $exchange, $queue, $routingKey = null, array $arguments = null)
{
$parameters = array();
if ($routingKey) {
$parameters['routing_key'] = $routingKey;
} else {
$parameters['routing_key'] = '';
}
if ($arguments) {
$parameters['arguments'] = $arguments;
}
return $this->client->send(sprintf('/api/bindings/%s/e/%s/q/%s', urlencode($vhost), urlencode($exchange), urlencode($queue)), 'POST', [], $parameters);
}
/**
* To create a new exchange to exchange binding, POST to this URI. You will need a body looking something like this:
*
* {
* "routing_key": "my_routing_key",
* "arguments": []
* }
*
* All keys are optional. The response will contain a Location header telling you the URI of your new binding.
*
* @param string $vhost
* @param string $source
* @param string $destination
* @param string|null $routingKey
* @param array|null $arguments
* @return array
*/
public function createExchange($vhost, $source, $destination, $routingKey = null, array $arguments = null)
{
$parameters = array();
if ($routingKey) {
$parameters['routing_key'] = $routingKey;
} else {
$parameters['routing_key'] = '';
}
if ($arguments) {
$parameters['arguments'] = $arguments;
}
return $this->client->send(sprintf('/api/bindings/%s/e/%s/e/%s', urlencode($vhost), urlencode($source), urlencode($destination)), 'POST', [], $parameters);
}
/**
* An individual binding between an exchange and a queue. The props part of the URI is a "name" for the binding
* composed of its routing key and a hash of its arguments.
*
* @param string $vhost
* @param string $exchange
* @param string $queue
* @param string $props
* @return array
*/
public function get($vhost, $exchange, $queue, $props)
{
return $this->client->send(sprintf('/api/bindings/%s/e/%s/q/%s/%s', urlencode($vhost), urlencode($exchange), urlencode($queue), urlencode($props)));
}
/**
* An individual binding between two exchanges. The props part of the URI is a "name" for the binding
* composed of its routing key and a hash of its arguments.
*
* @param string $vhost
* @param string $source
* @param string $destination
* @param string $props
* @return array
*/
public function getExchange($vhost, $source, $destination, $props)
{
return $this->client->send(sprintf('/api/bindings/%s/e/%s/e/%s/%s', urlencode($vhost), urlencode($source), urlencode($destination), urlencode($props)));
}
/**
* Remove an individual binding between an exchange and a queue.
*
* @param string $vhost
* @param string $exchange
* @param string $queue
* @param string $props
* @return array
*/
public function delete($vhost, $exchange, $queue, $props)
{
return $this->client->send(sprintf('/api/bindings/%s/e/%s/q/%s/%s', urlencode($vhost), urlencode($exchange), urlencode($queue), urlencode($props)), 'DELETE');
}
/**
* Remove an individual binding between two exchanges.
*
* @param string $vhost
* @param string $source
* @param string $destination
* @param string $props
* @return array
*/
public function deleteExchange($vhost, $source, $destination, $props)
{
return $this->client->send(sprintf('/api/bindings/%s/e/%s/e/%s/%s', urlencode($vhost), urlencode($source), urlencode($destination), urlencode($props)), 'DELETE');
}
}

View File

@@ -0,0 +1,32 @@
<?php
namespace RabbitMq\ManagementApi\Api;
/**
* Channel
*
* @author Richard Fullmer <richard.fullmer@opensoftdev.com>
*/
class Channel extends AbstractApi
{
/**
* A list of all open channels.
*
* @return array
*/
public function all()
{
return $this->client->send('/api/channels');
}
/**
* Details about an individual channel.
*
* @param string $channel
* @return array
*/
public function get($channel)
{
return $this->client->send(sprintf('/api/channels/%s', urlencode($channel)));
}
}

View File

@@ -0,0 +1,43 @@
<?php
namespace RabbitMq\ManagementApi\Api;
/**
* Connection
*
* @author Richard Fullmer <richard.fullmer@opensoftdev.com>
*/
class Connection extends AbstractApi
{
/**
* A list of all open connections.
*
* @return array
*/
public function all()
{
return $this->client->send('/api/connections');
}
/**
* An individual connection.
*
* @param string $name
* @return array|int
*/
public function get($name)
{
return $this->client->send(sprintf('/api/connections/%s', urlencode($name)));
}
/**
* Deleting a connection will close it.
*
* @param string $name
* @return array|int
*/
public function delete($name)
{
return $this->client->send(sprintf('/api/connections/%s', urlencode($name)), 'DELETE');
}
}

View File

@@ -0,0 +1,151 @@
<?php
namespace RabbitMq\ManagementApi\Api;
use RabbitMq\ManagementApi\Exception\InvalidArgumentException;
/**
* Exchange
*
* @author Richard Fullmer <richard.fullmer@opensoftdev.com>
*/
class Exchange extends AbstractApi
{
/**
* A list of all exchanges.
*
* OR
*
* A list of all exchanges in a given virtual host.
*
* @param null|string $vhost
* @return array
*/
public function all($vhost = null)
{
if ($vhost) {
return $this->client->send(sprintf('/api/exchanges/%s', urlencode($vhost)));
} else {
return $this->client->send('/api/exchanges');
}
}
/**
* An individual exchange.
*
* @param string $vhost
* @param string $name
* @return array
*/
public function get($vhost, $name)
{
return $this->client->send(sprintf('/api/exchanges/%s/%s', urlencode($vhost), urlencode($name)));
}
/**
* To create an exchange, you will need a body looking something like this:
*
* {
* "type": "direct",
* "auto_delete": false,
* "durable": true,
* "internal": false,
* "arguments": []
* }
*
* The 'type' key is mandatory; other keys are optional.
*
* @param string $vhost
* @param string $name
* @param array $exchange
* @return array
* @throws \RabbitMq\ManagementApi\Exception\InvalidArgumentException
*/
public function create($vhost, $name, array $exchange)
{
if (!isset($exchange['type'])) {
throw new InvalidArgumentException("Error creating exchange: Exchange key 'type' is mandatory");
}
return $this->client->send(sprintf('/api/exchanges/%s/%s', urlencode($vhost), urlencode($name)), 'PUT', [], $exchange);
}
/**
* Delete an exchange
*
* @param string $vhost
* @param string $name
* @return array
*/
public function delete($vhost, $name)
{
return $this->client->send(sprintf('/api/exchanges/%s/%s', urlencode($vhost), urlencode($name)), 'DELETE');
}
/**
* A list of all bindings in which a given exchange is the source.
*
* @param string $vhost
* @param string $name
* @return array
*/
public function sourceBindings($vhost, $name)
{
return $this->client->send(sprintf('/api/exchanges/%s/%s/bindings/source', urlencode($vhost), urlencode($name)));
}
/**
* A list of all bindings in which a given exchange is the destination.
*
* @param string $vhost
* @param string $name
* @return array
*/
public function destinationBindings($vhost, $name)
{
return $this->client->send(sprintf('/api/exchanges/%s/%s/bindings/destination', urlencode($vhost), urlencode($name)));
}
/**
* Publish a message to a given exchange. You will need a body looking something like:
*
* {
* "properties": {},
* "routing_key": "my key",
* "payload": "my body",
* "payload_encoding":"string"
* }
*
* All keys are mandatory. The payload_encoding key should be either "string" (in which case the payload will be
* taken to be the UTF-8 encoding of the payload field) or "base64" (in which case the payload field is taken to be
* base64 encoded).
*
* If the message is published successfully, the response will look like:
*
* {"routed": true}
*
* routed will be true if the message was sent to at least one queue.
*
* Please note that the publish / get paths in the HTTP API are intended for injecting test messages, diagnostics etc - they do not implement reliable delivery and so should be treated as a sysadmin's tool rather than a general API for messaging.
*
* @param string $vhost
* @param string $name
* @param array $message
* @throws InvalidArgumentException
* @return array
*/
public function publish($vhost, $name, array $message)
{
if (!isset($message['properties'])) {
throw new InvalidArgumentException("Error publishing to exchange: Message key 'properties' is mandatory");
} elseif (!isset($message['routing_key'])) {
throw new InvalidArgumentException("Error publishing to exchange: Message key 'routing_key' is mandatory");
} elseif (!isset($message['payload'])) {
throw new InvalidArgumentException("Error publishing to exchange: Message key 'payload' is mandatory");
} elseif (!isset($message['payload_encoding'])) {
throw new InvalidArgumentException("Error publishing to exchange: Message key 'payload_encoding' is mandatory");
}
return $this->client->send(sprintf('/api/exchanges/%s/%s/publish', urlencode($vhost), urlencode($name)), 'POST', [], $message);
}
}

View File

@@ -0,0 +1,33 @@
<?php
namespace RabbitMq\ManagementApi\Api;
/**
* Nodes
*
* @author Richard Fullmer <richard.fullmer@opensoftdev.com>
*/
class Node extends AbstractApi
{
/**
* A list of nodes in the RabbitMQ cluster.
*
* @return array
*/
public function all()
{
return $this->client->send('/api/nodes');
}
/**
* An individual node in the RabbitMQ cluster. Add "?memory=true" to get memory statistics.
*
* @param string $name
* @param bool $memory
* @return array
*/
public function get($name, $memory = false)
{
return $this->client->send(sprintf('/api/nodes/%s%s', urlencode($name), $memory ? '?memory=true' : ''));
}
}

View File

@@ -0,0 +1,74 @@
<?php
namespace RabbitMq\ManagementApi\Api;
/**
* Parameter
*
* @author Richard Fullmer <richard.fullmer@opensoftdev.com>
*/
class Parameter extends AbstractApi
{
/**
* A list of all parameters.
*
* @return array
*/
public function all()
{
return $this->client->send('/api/parameters');
}
/**
* A list of all parameters for a given component and virtual host.
*
* @param string $component
* @param string|null $vhost
* @param string|null $name
* @return array
*/
public function get($component, $vhost = null, $name = null)
{
if ($vhost && $name) {
return $this->client->send(sprintf('/api/parameters/%s/%s/%s', urlencode($component), urlencode($vhost), urlencode($name)));
} elseif ($vhost) {
return $this->client->send(sprintf('/api/parameters/%s/%s', urlencode($component), urlencode($vhost)));
} else {
return $this->client->send(sprintf('/api/parameters/%s', urlencode($component)));
}
}
/**
* To PUT a parameter, you will need a body looking something like this:
*
* {
* "vhost": "/",
* "component": "federation",
* "name": "local_username",
* "value": "guest"
* }
*
* @param string $component
* @param string $vhost
* @param string $name
* @param array $parameter
* @return array
*/
public function create($component, $vhost, $name, array $parameter)
{
return $this->client->send(sprintf('/api/parameters/%s/%s/%s', urlencode($component), urlencode($vhost), urlencode($name)), 'PUT', [], $parameter);
}
/**
* Delete a parameter
*
* @param string $component
* @param string $vhost
* @param string $name
* @return array
*/
public function delete($component, $vhost, $name)
{
return $this->client->send(sprintf('/api/parameters/%s/%s/%s', urlencode($component), urlencode($vhost), urlencode($name)), 'DELETE');
}
}

View File

@@ -0,0 +1,70 @@
<?php
namespace RabbitMq\ManagementApi\Api;
use RabbitMq\ManagementApi\Exception\InvalidArgumentException;
/**
* Permission
*
* @author Richard Fullmer <richard.fullmer@opensoftdev.com>
*/
class Permission extends AbstractApi
{
/**
* A list of all permissions for all users.
*
* @return array
*/
public function all()
{
return $this->client->send('/api/permissions');
}
/**
* An individual permission of a user and virtual host.
*
* @param string $vhost
* @param string $user
* @return array
*/
public function get($vhost, $user)
{
return $this->client->send(sprintf('/api/permissions/%s/%s', urlencode($vhost), urlencode($user)));
}
/**
* To PUT a permission, you will need a body looking something like this:
*
* {"configure":".*","write":".*","read":".*"}
*
* All keys are mandatory.
*
* @param string $vhost
* @param string $user
* @param array $permission
* @return array
* @throws InvalidArgumentException
*/
public function create($vhost, $user, array $permission)
{
if (!isset($permission['configure']) || !isset($permission['write']) || !isset($permission['read'])) {
throw new InvalidArgumentException("Error creating permission: 'configure', 'write', and 'read' permissions must be properly set.");
}
return $this->client->send(sprintf('/api/permissions/%s/%s', urlencode($vhost), urlencode($user)), 'PUT', [], $permission);
}
/**
* Delete a specific set of permissions
*
* @param string $vhost
* @param string $user
* @return array
*/
public function delete($vhost, $user)
{
return $this->client->send(sprintf('/api/permissions/%s/%s', urlencode($vhost), urlencode($user)), 'DELETE');
}
}

View File

@@ -0,0 +1,68 @@
<?php
namespace RabbitMq\ManagementApi\Api;
/**
* Policy
*
* @author Richard Fullmer <richard.fullmer@opensoftdev.com>
*/
class Policy extends AbstractApi
{
/**
* A list of all policies.
*
* @return array
*/
public function all()
{
return $this->client->send('/api/policies');
}
/**
* A list of all policies in a given virtual host.
*
* OR
*
* An individual policy.
*
* @param string $vhost
* @param string|null $name
* @return array
*/
public function get($vhost, $name = null)
{
if ($name) {
return $this->client->send(sprintf('/api/policies/%s/%s', urlencode($vhost), urlencode($name)));
}
return $this->client->send(sprintf('/api/policies/%s', urlencode($vhost)));
}
/**
* To PUT a policy, you will need a body looking something like this:
*
* {"pattern":"^amq.", "definition": {"federation-upstream-set":"all"}, "priority":0}
*
* @param string $vhost
* @param string $name
* @param array $policy
* @return array
*/
public function create($vhost, $name, array $policy)
{
return $this->client->send(sprintf('/api/policies/%s/%s', urlencode($vhost), urlencode($name)), 'PUT', [], $policy);
}
/**
* Delete a policy
*
* @param string $vhost
* @param string $name
* @return array
*/
public function delete($vhost, $name)
{
return $this->client->send(sprintf('/api/policies/%s/%s', urlencode($vhost), urlencode($name)), 'DELETE');
}
}

View File

@@ -0,0 +1,144 @@
<?php
namespace RabbitMq\ManagementApi\Api;
/**
* Queue
*
* @author Richard Fullmer <richard.fullmer@opensoftdev.com>
*/
class Queue extends AbstractApi
{
/**
* A list of all queues.
*
* OR
*
* A list of all queues in a given virtual host.
*
* @param string|null $vhost
* @return array
*/
public function all($vhost = null)
{
if ($vhost) {
return $this->client->send(sprintf('/api/queues/%s', urlencode($vhost)));
} else {
return $this->client->send('/api/queues');
}
}
/**
* An individual queue.
*
* @param string $vhost
* @param string $name
* @return array
*/
public function get($vhost, $name)
{
return $this->client->send(sprintf('/api/queues/%s/%s', urlencode($vhost), urlencode($name)));
}
/**
* To PUT a queue, you will need a body looking something like this:
*
* {
* "auto_delete": false,
* "durable": true,
* "arguments":[],
* "node":"rabbit@smacmullen"
* }
*
* All keys are optional.
*
* @param string $vhost
* @param string $name
* @param array $queue
* @return array
*/
public function create($vhost, $name, array $queue)
{
return $this->client->send(sprintf('/api/queues/%s/%s', urlencode($vhost), urlencode($name)), 'PUT', [], $queue);
}
/**
* @param string $vhost
* @param string $name
* @return array
*/
public function delete($vhost, $name)
{
return $this->client->send(sprintf('/api/queues/%s/%s', urlencode($vhost), urlencode($name)), 'DELETE');
}
/**
* A list of all bindings on a given queue.
*
* @param string $vhost
* @param string $queue
* @return array
*/
public function bindings($vhost, $queue)
{
return $this->client->send(sprintf('/api/queues/%s/%s/bindings', urlencode($vhost), urlencode($queue)));
}
/**
* Contents of a queue. DELETE to purge. Note you can't GET this.
*
* @param string $vhost
* @param string $name
* @return array
*/
public function purgeMessages($vhost, $name)
{
return $this->client->send(sprintf('/api/queues/%s/%s/contents', urlencode($vhost), urlencode($name)), 'DELETE');
}
/**
* Get messages from a queue. (This is not an HTTP GET as it will alter the state of the queue.) You should post a
* body looking like:
*
* {"count":5,"requeue":true,"encoding":"auto","truncate":50000}
*
* count controls the number of messages to get. You may get fewer messages than this if the queue cannot
* immediately provide them.
*
* requeue determines whether the messages will be removed from the queue. If requeue is true they will be
* requeued - but their position in the queue may change and their redelivered flag will be set.
*
* encoding must be either "auto" (in which case the payload will be returned as a string if it is valid UTF-8, and
* base64 encoded otherwise), or "base64" (in which case the payload will always be base64 encoded).
*
* If truncate is present it will truncate the message payload if it is larger than the size given (in bytes).
*
* truncate is optional; all other keys are mandatory.
*
* Please note that the publish / get paths in the HTTP API are intended for injecting test messages, diagnostics
* etc - they do not implement reliable delivery and so should be treated as a sysadmin's tool rather than a general
* API for messaging.
*
* @param string $vhost
* @param string $name
* @param integer $count
* @param bool $requeue
* @param string $encoding
* @param null|integer $truncate
* @return array
*/
public function retrieveMessages($vhost, $name, $count = 5, $requeue = true, $encoding = 'auto', $truncate = null)
{
$parameters = array(
'count' => $count,
'requeue' => $requeue,
'encoding' => $encoding
);
if ($truncate) {
$parameters['truncate'] = $truncate;
}
return $this->client->send(sprintf('/api/queues/%s/%s/get', urlencode($vhost), urlencode($name)), 'POST', [], $parameters);
}
}

View File

@@ -0,0 +1,76 @@
<?php
namespace RabbitMq\ManagementApi\Api;
/**
* User
*
* @author Richard Fullmer <richard.fullmer@opensoftdev.com>
*/
class User extends AbstractApi
{
/**
* A list of all users.
*
* @return array
*/
public function all()
{
return $this->client->send('/api/users');
}
/**
* An individual user.
*
* @param string $name
* @return array
*/
public function get($name)
{
return $this->client->send(sprintf('/api/users/%s', urlencode($name)));
}
/**
* To PUT a user, you will need a body looking something like this:
*
* {"password":"secret","tags":"administrator"}
*
* or:
*
* {"password_hash":"2lmoth8l4H0DViLaK9Fxi6l9ds8=", "tags":"administrator"}
*
* The tags key is mandatory. Either password or password_hash must be set. Setting password_hash to "" will
* ensure the user cannot use a password to log in. tags is a comma-separated list of tags for the user. Currently
* recognised tags are "administrator", "monitoring" and "management".
*
* @param string $name
* @param array $user
* @return mixed
*/
public function create($name, array $user)
{
return $this->client->send(sprintf('/api/users/%s', urlencode($name)), 'PUT', [], $user);
}
/**
* Delete a user.
*
* @param string $name
* @return array
*/
public function delete($name)
{
return $this->client->send(sprintf('/api/users/%s', urlencode($name)), 'DELETE');
}
/**
* A list of all permissions for a given user.
*
* @param string $name
* @return array
*/
public function permissions($name)
{
return $this->client->send(sprintf('/api/users/%s/permissions', urlencode($name)));
}
}

View File

@@ -0,0 +1,65 @@
<?php
namespace RabbitMq\ManagementApi\Api;
/**
* Vhost
*
* @author Richard Fullmer <richard.fullmer@opensoftdev.com>
*/
class Vhost extends AbstractApi
{
/**
* A list of all vhosts.
*
* @return array
*/
public function all()
{
return $this->client->send('/api/vhosts');
}
/**
* An individual virtual host.
*
* @param string $name
* @return array
*/
public function get($name)
{
return $this->client->send(sprintf('/api/vhosts/%s', urlencode($name)));
}
/**
* As a virtual host only has a name, you do not need an HTTP body when PUTing one of these.
*
* @param string $name
* @return array
*/
public function create($name)
{
return $this->client->send(sprintf('/api/vhosts/%s', urlencode($name)), 'PUT');
}
/**
* Delete a vhost.
*
* @param string $name
* @return array
*/
public function delete($name)
{
return $this->client->send(sprintf('/api/vhosts/%s', urlencode($name)), 'DELETE');
}
/**
* A list of all permissions for a given virtual host.
*
* @param string $name
* @return array
*/
public function permissions($name)
{
return $this->client->send(sprintf('/api/vhosts/%s/permissions', urlencode($name)));
}
}

View File

@@ -0,0 +1,208 @@
<?php
namespace RabbitMq\ManagementApi;
use Http\Client\Common\Plugin\AuthenticationPlugin;
use Http\Client\Common\Plugin\HeaderDefaultsPlugin;
use Http\Client\Common\PluginClient;
use Http\Client\HttpClient;
use Http\Discovery\HttpClientDiscovery;
use Http\Discovery\MessageFactoryDiscovery;
use Http\Message\Authentication\BasicAuth;
/**
* ManagementApi
*
* @author Richard Fullmer <richard.fullmer@opensoftdev.com>
*/
class Client
{
/**
* @var HttpClient
*/
protected $client;
protected $messageFactory;
protected $baseUrl;
protected $username;
protected $password;
/**
* @param HttpClient $client
* @param string $baseUrl
* @param string $username
* @param string $password
*/
public function __construct(HttpClient $client = null, $baseUrl = 'http://localhost:15672', $username = 'guest', $password = 'guest')
{
$this->baseUrl = $baseUrl;
$this->messageFactory = MessageFactoryDiscovery::find();
$this->client = new PluginClient(
$client ?: HttpClientDiscovery::find(), [
new AuthenticationPlugin(new BasicAuth($username, $password)),
new HeaderDefaultsPlugin(['Content-Type' => 'application/json'])
]);
}
/**
* Declares a test queue, then publishes and consumes a message. Intended for use by monitoring tools. If
* everything is working correctly, will return HTTP status 200 with body:
*
* {"status":"ok"}
*
* Note: the test queue will not be deleted (to to prevent queue churn if this is repeatedly pinged).
*
* @param string $vhost
* @return array
*/
public function alivenessTest($vhost)
{
return $this->send(sprintf('/api/aliveness-test/%s', urlencode($vhost)));
}
/**
* Various random bits of information that describe the whole system.
*
* @return array
*/
public function overview()
{
return $this->send('/api/overview');
}
/**
* A list of extensions to the management plugin.
*
* @return array
*/
public function extensions()
{
return $this->send('/api/extensions');
}
/**
* The server definitions - exchanges, queues, bindings, users, virtual hosts, permissions and parameters.
*
* Everything apart from messages. POST to upload an existing set of definitions. Note that:
*
* - The definitions are merged. Anything already existing is untouched.
* - Conflicts will cause an error.
* - In the event of an error you will be left with a part-applied set of definitions.
*
* For convenience you may upload a file from a browser to this URI (i.e. you can use multipart/form-data as well as
* application/json) in which case the definitions should be uploaded as a form field named "file".
*
* @return mixed
*/
public function definitions()
{
return $this->send('/api/definitions');
}
/**
* @return Api\Connection
*/
public function connections()
{
return new Api\Connection($this);
}
/**
* @return Api\Channel
*/
public function channels()
{
return new Api\Channel($this);
}
/**
* @return Api\Exchange
*/
public function exchanges()
{
return new Api\Exchange($this);
}
/**
* @return Api\Queue
*/
public function queues()
{
return new Api\Queue($this);
}
/**
* @return Api\Vhost
*/
public function vhosts()
{
return new Api\Vhost($this);
}
/**
* @return Api\Binding
*/
public function bindings()
{
return new Api\Binding($this);
}
/**
* @return Api\User
*/
public function users()
{
return new Api\User($this);
}
/**
* @return Api\Permission
*/
public function permissions()
{
return new Api\Permission($this);
}
/**
* @return Api\Parameter
*/
public function parameters()
{
return new Api\Parameter($this);
}
/**
* @return Api\Policy
*/
public function policies()
{
return new Api\Policy($this);
}
/**
* @return array
*/
public function whoami()
{
return $this->send('/api/whoami');
}
/**
* @param string $endpoint Resource URI.
* @param string $method
* @param array $headers HTTP headers
* @param string|resource|array $body Entity body of request (POST/PUT) or response (GET)
* @return array
*/
public function send($endpoint, $method = 'GET', array $headers = [], $body = null)
{
if (null !== $body) {
$body = json_encode($body);
}
$request = $this->messageFactory->createRequest($method, $this->baseUrl . $endpoint, $headers, $body);
$response = $this->client->sendRequest($request);
return json_decode($response->getBody()->getContents(), true);
}
}

View File

@@ -0,0 +1,11 @@
<?php
namespace RabbitMq\ManagementApi\Exception;
/**
* @author Richard Fullmer <richard.fullmer@opensoftdev.com>
*/
class InvalidArgumentException extends \InvalidArgumentException
{
}