/** * @param NULL|bool|int|float|string|application_data|Value|array $application_data Primitive PHP value, application_data or array(application_data). NULL is converted to libamqp\amqp_value(libamqp\null) * @param header|NULL $header * @param \libamqp\annotations|\libamqp\delivery_annotations|null $delivery_annotations * @param \libamqp\annotations|\libamqp\message_annotations|null $message_annotations * @param properties|NULL $properties * @param application_properties|NULL $application_properties * @param array|NULL $footer_callbacks An array of callbacks * @param int $delivery_mode * @param callback|NULL $delivery_state_callback * @internal param bool|constant("LIBAMQP_SEND_AT_MOST_ONCE") $exactly_once */ function send($application_data, header $header = NULL, delivery_annotations $delivery_annotations = NULL, message_annotations $message_annotations = NULL, properties $properties = NULL, application_properties $application_properties = NULL, array $footer_callbacks = array(), $delivery_mode = 0, $delivery_state_callback = NULL) { if (is_null($application_data)) { $applicationDataSections = array(new amqp_value(\libamqp\null::NULL())); } else { if (is_bool($application_data)) { $applicationDataSections = array(new amqp_value(\libamqp\boolean::instance_from_php_value($application_data))); } else { if (is_int($application_data)) { $applicationDataSections = array(new amqp_value(long::instance_from_php_value($application_data))); } else { if (is_float($application_data)) { $applicationDataSections = array(new amqp_value(double::instance_from_php_value($application_data))); } else { if (is_string($application_data)) { $applicationDataSections = array(new data($application_data)); } else { if ($application_data instanceof application_data) { $applicationDataSections = array($application_data); } else { if ($application_data instanceof Value) { $applicationDataSections = array(new amqp_value($application_data)); } else { if (is_array($application_data)) { $length = count($application_data); if ($length == 0) { throw new InvalidArgumentException("application_data can not be an empty array()"); } if (!$application_data[0] instanceof application_data) { throw new InvalidArgumentException("application_data must be of type application_data"); } if ($length > 1) { $firstObjectsClass = get_class($application_data[0]); for ($index = 1; $index < $length; $index++) { if (get_class($application_data[$index]) != $firstObjectsClass) { throw new InvalidArgumentException("array(application_data) must all be of the same instance of application_data, eg {$firstObjectsClass}"); } } } $applicationDataSections = $application_data; } else { throw new InvalidArgumentException('application_data must be either NULL (maps to libamqp\\null), int (maps to long) bool (maps to boolean) string (a byte array), Value or an array of application_data'); } } } } } } } } c_attach_sending_link_if_necessary($this); $this->validate_settlement_choice($delivery_mode, $delivery_state_callback); if (count($footer_callbacks) > 0) { $fake_enconded_binary_string = c_footer_encode($properties, $application_properties, $applicationDataSections); $footer = new footer(); foreach ($footer_callbacks as $footer_callback) { if (!is_callable($footer_callback)) { throw new InvalidArgumentException("a footer_callback is not a callback but {$footer_callback}"); } call_user_func($footer_callback, &$footer, $fake_enconded_binary_string); } } else { $footer = NULL; } /* * Link settings negotiation:- * - link is negotiated as mixed * - presence of settlement object is used as hint to whether to use first or second */ echo "Sending Message\n"; echo "\theader: {$header}\n"; echo "\tdelivery-annotations: {$delivery_annotations}\n"; echo "\tmessage-annotations: {$message_annotations}\n"; echo "\tproperties: {$properties}\n"; echo "\tapplication-properties: {$application_properties}\n"; foreach ($applicationDataSections as $applicationDataSection) { echo "\tapplication-data: {$applicationDataSection}\n"; } echo "\tfooter: {$footer}\n"; if (isset($delivery_state_callback)) { $delivery_state = new accepted(); echo "Receiving delivery-state {$delivery_state}\n"; $result = call_user_func($delivery_state_callback, &$delivery_state); if ($delivery_mode == constant('LIBAMQP_DELIVERY_MODE_EXACTLY_ONCE')) { if (is_null($result)) { $result = new accepted(); } c_settle_exactly_once($result); } else { if (isset($result)) { throw new BadFunctionCallException("delivery_mode is LIBAMQP_DELIVERY_MODE_AT_LEAST_ONCE but callback {$delivery_state_callback} returned {$result} and not NULL"); } } } }
$section0[2] = new string("hello"); $section1 = new amqp_sequence(); $section1[0] = boolean::FALSE(); $section1[2] = new string("world"); $amqp_data_sections = array($section0, $section1); $link->send($amqp_data_sections); /* 1 (Restablishes connection, session or link if necessary) 2 Sends header and binary message */ $link->send("messsage", new header(true, 6)); /* 1 (Restablishes connection, session or link if necessary) 2 Sends header, delivery-annotations, message-annotations, properties, application-properties and binary message */ $link->send("messsage", new header(FALSE, 3, NULL, TRUE, 2), new delivery_annotations(array("x-opt-delivery-something" => boolean::TRUE(), "x-opt-delivery-whatever" => char::instance_from_php_value(56789))), new message_annotations(array("x-opt-message-somesuch" => byte::instance_from_php_value(-1), "x-opt-message-somesuch" => ubyte::instance_from_php_value(15))), new properties("message-id-56", "somebinarydataforuserid", "to", "subject", "reply-to", binary::instance_from_php_value("correlation-id"), "text/plain;charset=utf-8", NULL, 123456, new timestamp(123456), "group-id", 90, string::instance_from_php_value("reply-to-group-id")), new application_properties(array("my-key-1" => boolean::TRUE(), "my-key-2" => boolean::FALSE()))); /* 1 (Restablishes connection, session or link if necessary) 2 Sends binary message and uses an array of callbacks to create the footer */ $footer_callbacks = array(function (footer &$footer, $encoded_data_binary_string) { $footer->set('x-hash-sha1', new binary(sha1($encoded_data_binary_string, TRUE))); $footer->set('x-hash-md5', new binary(md5($encoded_data_binary_string, TRUE))); }, function (footer &$footer, $encoded_data_binary_string) { $key = 'fsfsfsfsfs342534534'; $footer->set('x-hmac-sha256', new binary(hash_hmac('sha256', $encoded_data_binary_string, $key, TRUE))); }); $link->send("message", NULL, NULL, NULL, NULL, NULL, $footer_callbacks); /* 1 (Restablishes connection, session or link if necessary) 2 Sends binary message using at-least-once messaging
} throw new BadMethodCallException('Not allowed.'); } /** * @param string $name * @param bool $value * @throws \BadMethodCallException */ public function __set($name, $value) { throw new BadMethodCallException('Not allowed.'); } /** * @param \string $name * @return bool */ public function __isset($name) { return $name == "value"; } /** * @param string $name * @throws \BadMethodCallException */ public function __unset($name) { throw new BadMethodCallException('Not allowed.'); } } boolean::init();