/**
  * @param string $name
  * @param mixed $value Can be a primitive PHP value or a Value
  */
 public function __set($name, $value)
 {
     if (!array_key_exists($name, static::$listMappings)) {
         throw new OutOfBoundsException("no such property {$name}");
     }
     $listMapping = static::$listMappings[$name];
     $index = $listMapping[0];
     if ($value == NULL) {
         $amqpValue = \libamqp\null::NULL();
     } else {
         if ($value instanceof Value) {
             $interfaceClass = $listMapping[2];
             if (!$value instanceof $interfaceClass) {
                 throw new InvalidArgumentException("{$value} is not an instance of {$interfaceClass}");
             }
             $amqpValue = $value;
         } else {
             $constructorClass = $listMapping[3];
             $amqpValue = call_user_func(array($constructorClass, 'instance_from_php_value'), $value);
         }
     }
     $this->value[$index] = $amqpValue;
 }
示例#2
0
 /**
  * @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");
             }
         }
     }
 }
示例#3
0
 /**
  * (PHP 5 &gt;= 5.1.0)<br/>
  * Offset to set
  *
  * @link http://php.net/manual/en/arrayaccess.offsetset.php
  * @param mixed $offset <p>
  * The offset to assign the value to.
  * </p>
  * @param mixed $value <p>
  * The value to set.
  * </p>
  * @return void
  */
 public function offsetSet($offset, $value)
 {
     if (!is_int($offset)) {
         throw new InvalidArgumentException("Only integer index keys are permitted, not {$offset}");
     }
     if ($offset < 0) {
         throw new InvalidArgumentException("Negative integer index keys, {$offset}, are not permitted");
     }
     if (!$value instanceof Value) {
         throw new InvalidArgumentException("value must be instanceof Value, not {$value}");
     }
     // Fill in any lesser indices with libamqp\null if not set
     for ($previousIndex = $offset - 1; $previousIndex >= 0; $previousIndex--) {
         if (array_key_exists($previousIndex, $this->list)) {
             break;
         }
         $this->list[$previousIndex] = null::NULL();
     }
     $this->list[$offset] = $value;
 }
示例#4
0
        }
        throw new BadMethodCallException('Not allowed.');
    }
    /**
     * @param string $name
     * @param NULL $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.');
    }
}
null::init();