Пример #1
0
bool TestExtCurl::test_evhttp_get() {
  Variant ret = f_evhttp_get(String(get_request_uri()),
                             make_packed_array("ECHO: foo"));
  VS(ret[s_code], 200);
  VS(ret[s_response], "OK");
  VS(ret[s_headers][0], "ECHOED: foo");
  VS(ret[s_headers][4], "Content-Length: 2");
  return Count(true);
}
Пример #2
0
Array HHVM_METHOD(DateTime, __sleep) {
  DateTimeData* data = Native::data<DateTimeData>(this_);
  int zoneType = data->m_dt->zoneType();

  this_->o_set(s_date, data->format(s_ISOformat));
  this_->o_set(s_timezone_type, zoneType);
  this_->o_set(s_timezone, zone_type_to_string(zoneType, data->m_dt));
  return make_packed_array(s_date, s_timezone_type, s_timezone);
}
Пример #3
0
ObjectData* AllocSoapFaultObject(const Variant& code,
                                 const Variant& message,
                                 const Variant& actor /* = null_variant */,
                                 const Variant& detail /* = null_variant */,
                                 const Variant& name /* = null_variant */,
                                 const Variant& header /* = null_variant */) {
  CREATE_AND_CONSTRUCT(SoapFault, make_packed_array(code, message, actor,
                                                    detail, name, header));
}
Пример #4
0
void ExecutionContext::obClean(int handler_flag) {
  if (!m_buffers.empty()) {
    OutputBuffer *last = &m_buffers.back();
    if (!last->handler.isNull()) {
      m_insideOBHandler = true;
      SCOPE_EXIT { m_insideOBHandler = false; };
      vm_call_user_func(last->handler,
                        make_packed_array(last->oss.detach(), handler_flag));
    }
Пример #5
0
void AsioSession::onResumableCreate(
    c_ResumableWaitHandle* resumable,
    c_WaitableWaitHandle* child
) {
    runCallback(m_onResumableCreate,
                make_packed_array(resumable, child),
                "ResumableWaitHandle::onCreate"
               );
}
Пример #6
0
void bsonToMongoCode(bson_iter_t* iter, Array* output) {
  uint32_t length;
  const char* code = bson_iter_code(iter, &length);

  bsonToObject(iter, output,
    &s_MongoCode,
    make_packed_array(String(code, length, CopyString))
  );
}
Пример #7
0
void AsioSession::onExternalThreadEventCreate(
  c_ExternalThreadEventWaitHandle* waitHandle
) {
  runCallback(
    m_onExternalThreadEventCreateCallback,
    make_packed_array(waitHandle),
    "ExternalThreadEventWaitHandle::onCreate"
  );
}
Пример #8
0
void AsioSession::onExternalThreadEventSuccess(
  c_ExternalThreadEventWaitHandle* waitHandle,
  const Variant& result
) {
  runCallback(
    m_onExternalThreadEventSuccessCallback,
    make_packed_array(waitHandle, result),
    "ExternalThreadEventWaitHandle::onSuccess"
  );
}
Пример #9
0
void AsioSession::onGenVectorCreate(
  c_GenVectorWaitHandle* waitHandle,
  const Variant& dependencies
) {
  runCallback(
    m_onGenVectorCreateCallback,
    make_packed_array(waitHandle, dependencies),
    "GenVectorWaitHandle::onCreate"
  );
}
Пример #10
0
void AsioSession::onAwaitAllCreate(
  c_AwaitAllWaitHandle* waitHandle,
  const Variant &dependencies
) {
  runCallback(
    m_onAwaitAllCreateCallback,
    make_packed_array(waitHandle, dependencies),
    "AwaitAllWaitHandle::onCreate"
  );
}
Пример #11
0
void AsioSession::onResumableFail(
  c_ResumableWaitHandle* resumable,
  const Object& exception
) {
  runCallback(
    m_onResumableFailCallback,
    make_packed_array(resumable, exception),
    "ResumableWaitHandle::onFail"
  );
}
Пример #12
0
void AsioSession::onResumableSuccess(
  c_ResumableWaitHandle* resumable,
  const Variant& result
) {
  runCallback(
    m_onResumableSuccessCallback,
    make_packed_array(resumable, result),
    "ResumableWaitHandle::onSuccess"
  );
}
Пример #13
0
void AsioSession::onSetResultToRefCreate(c_SetResultToRefWaitHandle* wait_handle, CObjRef child) {
  assert(m_onSetResultToRefCreateCallback.get());
  try {
    vm_call_user_func(
      m_onSetResultToRefCreateCallback,
      make_packed_array(wait_handle, child));
  } catch (const Object& callback_exception) {
    raise_warning("[asio] Ignoring exception thrown by SetResultToRefWaitHandle::onCreate callback");
  }
}
Пример #14
0
void bsonToMongoTimestamp(bson_iter_t* iter, Array* output) {
  uint32_t timestamp;
  uint32_t increment;

  bson_iter_timestamp(iter, &timestamp, &increment);
  bsonToObject(iter, output,
    &s_MongoTimestamp,
    make_packed_array((int64_t)timestamp, (int64_t)increment)
  );
}
Пример #15
0
void bsonToMongoId(bson_iter_t* iter, Array* output) {
  const bson_oid_t* oid = bson_iter_oid(iter);
  char id[25];

  bson_oid_to_string(oid, id);
  bsonToObject(iter, output, 
    &s_MongoId, 
    make_packed_array(String(id))
  );
}
Пример #16
0
void AsioSession::onExternalThreadEventFail(
  c_ExternalThreadEventWaitHandle* waitHandle,
  const Object& exception
) {
  runCallback(
    m_onExternalThreadEventFailCallback,
    make_packed_array(waitHandle, exception),
    "ExternalThreadEventWaitHandle::onFail"
  );
}
Пример #17
0
void AsioSession::onResumableAwait(
  c_ResumableWaitHandle* resumable,
  c_WaitableWaitHandle* child
) {
  runCallback(
    m_onResumableAwaitCallback,
    make_packed_array(resumable, child),
    "ResumableWaitHandle::onAwait"
  );
}
Пример #18
0
void AsioSession::onAsyncFunctionFail(c_AsyncFunctionWaitHandle* cont, CObjRef exception) {
  assert(m_onAsyncFunctionFailCallback.get());
  try {
    vm_call_user_func(
      m_onAsyncFunctionFailCallback,
      make_packed_array(cont, exception));
  } catch (const Object& callback_exception) {
    raise_warning("[asio] Ignoring exception thrown by AsyncFunctionWaitHandle::onFail callback");
  }
}
Пример #19
0
void AsioSession::onResumableCreate(c_ResumableWaitHandle* resumable, c_WaitableWaitHandle* child) {
  assert(m_onResumableCreateCallback.get());
  try {
    vm_call_user_func(
      m_onResumableCreateCallback,
     make_packed_array(resumable, child));
  } catch (const Object& callback_exception) {
    raise_warning("[asio] Ignoring exception thrown by ResumableWaitHandle::onCreate callback");
  }
}
Пример #20
0
ObjectData*
SystemLib::AllocSoapFaultObject(CVarRef code,
                                CVarRef message,
                                CVarRef actor /* = null_variant */,
                                CVarRef detail /* = null_variant */,
                                CVarRef name /* = null_variant */,
                                CVarRef header /* = null_variant */) {
  CREATE_AND_CONSTRUCT(SoapFault, make_packed_array(code, message, actor,
                                                 detail, name, header));
}
Пример #21
0
void AsioSession::onConditionCreate(
  c_ConditionWaitHandle* waitHandle,
  c_WaitableWaitHandle* child
) {
  runCallback(
    m_onConditionCreateCallback,
    make_packed_array(waitHandle, child),
    "ConditionWaitHandle::onCreate"
  );
}
Пример #22
0
void AsioSession::onAsyncFunctionSuccess(c_AsyncFunctionWaitHandle* cont, const Variant& result) {
  assert(m_onAsyncFunctionSuccessCallback.get());
  try {
    vm_call_user_func(
      m_onAsyncFunctionSuccessCallback,
      make_packed_array(cont, result));
  } catch (const Object& callback_exception) {
    raise_warning("[asio] Ignoring exception thrown by AsyncFunctionWaitHandle::onSuccess callback");
  }
}
Пример #23
0
void ExecutionContext::obClean(int handler_flag) {
  if (!m_buffers.empty()) {
    OutputBuffer *last = m_buffers.back();
    if (!last->handler.isNull()) {
      vm_call_user_func(last->handler,
                        make_packed_array(last->oss.detach(), handler_flag));
    }
    last->oss.clear();
  }
}
Пример #24
0
void AsioSession::onAsyncFunctionAwait(c_AsyncFunctionWaitHandle* cont, c_WaitableWaitHandle* child) {
  assert(m_onAsyncFunctionAwaitCallback.get());
  try {
    vm_call_user_func(
      m_onAsyncFunctionAwaitCallback,
      make_packed_array(cont, child));
  } catch (const Object& callback_exception) {
    raise_warning("[asio] Ignoring exception thrown by AsyncFunctionWaitHandle::onAwait callback");
  }
}
Пример #25
0
void AsioSession::onGenVectorCreate(c_GenVectorWaitHandle* wait_handle, const Variant& dependencies) {
  assert(m_onGenVectorCreateCallback.get());
  try {
    vm_call_user_func(
      m_onGenVectorCreateCallback,
      make_packed_array(wait_handle, dependencies));
  } catch (const Object& callback_exception) {
    raise_warning("[asio] Ignoring exception thrown by GenVectorWaitHandle::onCreate callback");
  }
}
Пример #26
0
bool TestExtCurl::test_evhttp_async_post() {
  Variant ret = f_evhttp_async_post(String(get_request_uri()), "echo",
                                    make_packed_array("ECHO: foo"));
  ret = f_evhttp_recv(ret.toResource());
  VS(ret[s_code], 200);
  VS(ret[s_response], "POST: echo");
  VS(ret[s_headers][0], "ECHOED: foo");
  VS(ret[s_headers][4], "Content-Length: 10");
  return Count(true);
}
Пример #27
0
bool UserFile::truncate(int64_t size) {
  // bool stream_truncate()
  bool invoked = false;
  Variant ret = invoke(m_StreamTruncate, s_stream_truncate,
                       make_packed_array(size), invoked);
  if (!invoked) {
    return false;
  }
  return ret.isBoolean() ? ret.toBoolean() : false;
}
Пример #28
0
bool ExecutionContext::obFlush() {
  assert(m_protectedLevel >= 0);
  if ((int)m_buffers.size() > m_protectedLevel) {
    std::list<OutputBuffer*>::const_iterator iter = m_buffers.end();
    OutputBuffer *last = *(--iter);
    const int flag = k_PHP_OUTPUT_HANDLER_START | k_PHP_OUTPUT_HANDLER_END;
    if (iter != m_buffers.begin()) {
      OutputBuffer *prev = *(--iter);
      if (last->handler.isNull()) {
        prev->oss.absorb(last->oss);
      } else {
        try {
          Variant tout = vm_call_user_func(
            last->handler, make_packed_array(last->oss.detach(), flag)
          );
          prev->oss.append(tout.toString());
          last->oss.clear();
        } catch (...) {
          prev->oss.absorb(last->oss);
        }
      }
      return true;
    }

    if (!last->handler.isNull()) {
      try {
        Variant tout = vm_call_user_func(
          last->handler, make_packed_array(last->oss.detach(), flag)
        );
        String sout = tout.toString();
        writeStdout(sout.data(), sout.size());
        last->oss.clear();
        return true;
      } catch (...) {}
    }

    writeStdout(last->oss.data(), last->oss.size());
    last->oss.clear();
    return true;
  }
  return false;
}
Пример #29
0
AutoloadHandler::Result AutoloadHandler::loadFromMap(const String& name,
                                                     const String& kind,
                                                     bool toLower,
                                                     const T &checkExists) {
  assert(!m_map.isNull());
  while (true) {
    const Variant& type_map = m_map.get()->get(kind);
    auto const typeMapCell = type_map.asCell();
    if (typeMapCell->m_type != KindOfArray) return Failure;
    String canonicalName = toLower ? f_strtolower(name) : name;
    const Variant& file = typeMapCell->m_data.parr->get(canonicalName);
    bool ok = false;
    if (file.isString()) {
      String fName = file.toCStrRef().get();
      if (fName.get()->data()[0] != '/') {
        if (!m_map_root.empty()) {
          fName = m_map_root + fName;
        }
      }
      try {
        JIT::VMRegAnchor _;
        bool initial;
        auto const ec = g_context.getNoCheck();
        Unit* u = ec->evalInclude(fName.get(), nullptr, &initial);
        if (u) {
          if (initial) {
            TypedValue retval;
            ec->invokeFunc(&retval, u->getMain(), init_null_variant,
                           nullptr, nullptr, nullptr, nullptr,
                           ExecutionContext::InvokePseudoMain);
            tvRefcountedDecRef(&retval);
          }
          ok = true;
        }
      } catch (...) {}
    }
    if (ok && checkExists(name)) {
      return Success;
    }
    const Variant& func = m_map.get()->get(s_failure);
    if (func.isNull()) return Failure;
    // can throw, otherwise
    //  - true means the map was updated. try again
    //  - false means we should stop applying autoloaders (only affects classes)
    //  - anything else means keep going
    Variant action = vm_call_user_func(func, make_packed_array(kind, name));
    auto const actionCell = action.asCell();
    if (actionCell->m_type == KindOfBoolean) {
      if (actionCell->m_data.num) continue;
      return StopAutoloading;
    }
    return ContinueAutoloading;
  }
}
Пример #30
0
bool UserDirectory::open(const String& path) {
  // bool dir_opendir ( string $path , int $options )
  bool invoked = false;
  Variant ret = invoke(m_DirOpen, s_dir_opendir,
                       make_packed_array(path, 0), invoked);
  if (invoked && ret.toBoolean()) {
    return true;
  }
  raise_warning("\"%s::dir_opendir\" call failed", m_cls->name()->data());
  return false;
}