示例#1
0
 public function request($request)
 {
     $this->connect();
     if ($this->_close != null) {
         $request['close'] = $this->_close;
     }
     if ($this->_context != null) {
         $request['context'] = $this->_context;
     }
     if ($this->suspend != null) {
         $request['suspend'] = $this->_suspend;
     }
     $this->_stream->put($request);
     $response = $this->_stream->get();
     $type = gettype($response);
     if ($type != 'array') {
         throw new IMuException('SessionResponse', $type);
     }
     if (array_key_exists('context', $response)) {
         $this->_context = $response['context'];
     }
     if (array_key_exists('reconnect', $response)) {
         $this->_port = $response['reconnect'];
     }
     $disconnect = false;
     if ($this->_close != null) {
         $disconnect = $this->_close;
     }
     if ($disconnect) {
         $this->disconnect();
     }
     $status = $response['status'];
     if ($status == 'error') {
         IMuTrace::write(2, 'server error');
         $id = 'SessionServerError';
         if (array_key_exists('error', $response)) {
             $id = $response['error'];
         } else {
             if (array_key_exists('id', $response)) {
                 $id = $response['id'];
             }
         }
         $e = new IMuException($id);
         if (array_key_exists('args', $response)) {
             $e->setArgs($response['args']);
         }
         if (array_key_exists('code', $response)) {
             $e->setCode($response['code']);
         }
         IMuTrace::write(2, 'throwing exception %s', $e->__toString());
         throw $e;
     }
     return $response;
 }
示例#2
0
/**
 * @details Write an error to the trace file and throw an IMuException.
 * @note Optionally, any number of additional parameters can be supplied when
 * calling this function. Usually these are messages or values that provide
 * more information about the error that is being raised.
 *
 * Usage examples:
 * @code{.php}
 *   raise(400, 'UpdateNoFiles');
 *   raise(500, 'MultimediaTempFileOpen', $tempName);
 * @endcode
 *
 * @param int $code
 *   Usually the HTTP error code that should be used in the HTTP response.
 * @param string $id
 *   A string that identifies the exception.
 *
 * @throws IMuException
 */
function raise($code, $id)
{
    $exception = new IMuException($id);
    $args = func_get_args();
    array_shift($args);
    array_shift($args);
    $exception->setArgs($args);
    $exception->setCode($code);
    IMuTrace::write(2, 'raising exception %s', $exception);
    throw $exception;
}