예제 #1
0
void HHVM_METHOD(DateTime, __wakeup) {
  Object dtz_obj{DateTimeZoneData::getClass()};
  HHVM_MN(DateTimeZone, __construct)(dtz_obj.get(),
                                     this_->o_get(s_timezone).toString());
  HHVM_MN(DateTime, __construct)(this_, this_->o_get(s_date).toString(),
                                 std::move(dtz_obj));

  // cleanup
  Class* cls = this_->getVMClass();
  this_->unsetProp(cls, s_date.get());
  this_->unsetProp(cls, s_timezone_type.get());
  this_->unsetProp(cls, s_timezone.get());
}
예제 #2
0
void HHVM_METHOD(DateTime, __wakeup) {
  ObjectData* dtz_obj = ObjectData::newInstance(DateTimeZoneData::getClass());
  HHVM_MN(DateTimeZone, __construct)(dtz_obj,
                                     this_->o_get(s_timezone).toString());
  HHVM_MN(DateTime, __construct)(this_, this_->o_get(s_date).toString(),
                                 Object(dtz_obj));

  // cleanup
  Class* cls = this_->getVMClass();
  this_->unsetProp(cls, s_date.get());
  this_->unsetProp(cls, s_timezone_type.get());
  this_->unsetProp(cls, s_timezone.get());
}
예제 #3
0
Variant HHVM_METHOD(SQLite3, query,
                    const String& sql) {
  auto *data = Native::data<SQLite3>(this_);
  SYNC_VM_REGS_SCOPED();
  data->validate();
  if (!sql.empty()) {
    Variant stmt = HHVM_MN(SQLite3, prepare)(this_, sql);
    if (!same(stmt, false)) {
      Object obj_stmt = stmt.toObject();
      assert(obj_stmt.instanceof(SQLite3Stmt::getClass()));
      return HHVM_MN(SQLite3Stmt, execute)(obj_stmt.get());
    }
  }
  return false;
}
예제 #4
0
void HHVM_METHOD(SQLite3, __construct,
                 const String& filename,
                 int64_t flags /* = SQLITE3_OPEN_READWRITE |
                   SQLITE3_OPEN_CREATE */,
                 const Variant& encryption_key /* = null */) {
  HHVM_MN(SQLite3, open)(this_, filename, flags, encryption_key);
}
예제 #5
0
Variant HHVM_FUNCTION(date_create,
                      const Variant& time /* = null_string */,
                      const Variant& timezone /* = uninit_variant */) {
  const String& str_time = time.isNull() ? null_string : time.toString();
  auto tz = TimeZone::Current();
  if (!timezone.isNull()) {
    const Object& obj_timezone = timezone.toObject();
    if (!obj_timezone.instanceof(s_DateTimeZone)) {
      raise_argument_warning("date_create", 2, s_DateTimeZone, obj_timezone);
      return false;
    }
    tz = DateTimeZoneData::unwrap(obj_timezone);
  }
  Object ret{DateTimeData::getClass()};
  // Don't set the time here because it will throw if it is bad
  HHVM_MN(DateTime, __construct)(ret.get());
  if (str_time.empty()) {
    // zend does this, so so do we
    return ret;
  }
  auto dt = DateTimeData::unwrap(ret);
  if (!dt->fromString(str_time, tz, nullptr, false)) {
    return false;
  }
  return ret;
}
예제 #6
0
Variant HHVM_METHOD(SQLite3, prepare,
                    const String& sql) {
  auto *data = Native::data<SQLite3>(this_);
  data->validate();
  if (!sql.empty()) {
    Object ret{SQLite3Stmt::getClass()};
    SQLite3Stmt *stmt = Native::data<SQLite3Stmt>(ret);
    HHVM_MN(SQLite3Stmt, __construct)(ret.get(), this_, sql);
    if (stmt->m_raw_stmt) {
      return ret;
    }
  }
  return false;
}
예제 #7
0
bool HHVM_FUNCTION(cancel, const Object& obj, const Object& exception) {
  if (!obj->instanceof(c_WaitHandle::classof())) {
    SystemLib::throwInvalidArgumentExceptionObject(
      "Cancellation unsupported for user-land Awaitable");
  }
  auto handle = wait_handle<c_WaitHandle>(obj.get());

  switch(handle->getKind()) {
    case c_WaitHandle::Kind::ExternalThreadEvent:
      return handle->asExternalThreadEvent()->cancel(exception);
    case c_WaitHandle::Kind::Sleep:
      return handle->asSleep()->cancel(exception);
    default:
      SystemLib::throwInvalidArgumentExceptionObject(
        "Cancellation unsupported for " +
        HHVM_MN(WaitHandle, getName) (handle)
      );
  }
}
예제 #8
0
static Variant HHVM_METHOD(Closure, call,
                           const Variant& newthis,
                           const Array& params) {
  if (newthis.isNull() || !newthis.isObject()) {
    raise_warning(
      "Closure::call() expects parameter 1 to be object, %s given",
      getDataTypeString(newthis.getType()).c_str()
    );
    return init_null_variant;
  }

  // So, with bind/bindTo, if we are trying to bind an instance to a static
  // closure, we just raise a warning and continue on. However, with call
  // we are supposed to just return null (according to the PHP 7 implementation)
  // Here is that speciality check, then. Do it here so we don't have to go
  // through the rigormorale of binding if this is the case.
  if (this_->getVMClass()->getCachedInvoke()->isStatic()) {
    raise_warning("Cannot bind an instance to a static closure");
    return init_null_variant;
  }

  auto bound = HHVM_MN(Closure, bindto)(this_, newthis, newthis);
  // If something went wrong in the binding (warning, for example), then
  // we can get an empty object back. And an empty object is null by
  // default. Return null if that is the case.
  if (bound.isNull()) {
    return init_null_variant;
  }

  // Could call vm_user_func(bound, params) here which goes through a
  // whole decode function process to get a Func*. But we know this
  // is a closure, and we can get a Func* via getInvokeFunc(), so just
  // bypass all that decode process to save time.
  return Variant::attach(
    g_context->invokeFunc(c_Closure::fromObject(this_)->getInvokeFunc(),
                          params, bound.toObject().get(),
                          nullptr, nullptr, nullptr,
                          ExecutionContext::InvokeCuf,
                          false, false)
  );
}
예제 #9
0
Variant HHVM_FUNCTION(date_create,
                      const Variant& time /* = null_string */,
                      const Variant& timezone /* = null_variant */) {
  const String& str_time = time.isNull() ? null_string : time.toString();
  const Object& obj_timezone = timezone.isNull()
                             ? null_object
                             : timezone.toObject();
  ObjectData* obj = ObjectData::newInstance(DateTimeData::getClass());
  Object ret(obj);
  // Don't set the time here because it will throw if it is bad
  HHVM_MN(DateTime, __construct)(obj);
  if (str_time.empty()) {
    // zend does this, so so do we
    return ret;
  }
  auto dt = DateTimeData::unwrap(ret);
  auto tz = DateTimeZoneData::unwrap(obj_timezone);
  if (!dt->fromString(str_time, tz, nullptr, false)) {
    return false;
  }
  return ret;
}
예제 #10
0
Variant HHVM_METHOD(SQLite3, querysingle,
                    const String& sql,
                    bool entire_row /* = false */) {
  auto *data = Native::data<SQLite3>(this_);
  SYNC_VM_REGS_SCOPED();
  data->validate();
  if (!sql.empty()) {
    Variant stmt = HHVM_MN(SQLite3, prepare)(this_, sql);
    if (!same(stmt, false)) {
      Object obj_stmt = stmt.toObject();
      assert(obj_stmt.instanceof(SQLite3Stmt::getClass()));
      sqlite3_stmt *pstmt =
        Native::data<SQLite3Stmt>(obj_stmt)->m_raw_stmt;
      switch (sqlite3_step(pstmt)) {
      case SQLITE_ROW: /* Valid Row */
        if (entire_row) {
          Array ret = Array::Create();
          for (int i = 0; i < sqlite3_data_count(pstmt); i++) {
            ret.set(String((char*)sqlite3_column_name(pstmt, i), CopyString),
                    get_column_value(pstmt, i));
          }
          return ret;
        }
        return get_column_value(pstmt, 0);
      case SQLITE_DONE: /* Valid but no results */
        if (entire_row) {
          return empty_array();
        } else {
          return init_null();
        }
      default:
        raise_warning("Unable to execute statement: %s",
                      sqlite3_errmsg(data->m_raw_db));
      }
    }
  }
  return false;
}
예제 #11
0
static bool HHVM_METHOD(ImagickDraw, destroy) {
  return HHVM_MN(ImagickDraw, clear)(this_);
}
예제 #12
0
Variant HHVM_METHOD(MongoDBDriverReadPreference, bsonSerialize)
{
	Array retval = HHVM_MN(MongoDBDriverReadPreference, __debugInfo)(this_);
	return Variant(Variant(retval).toObject());
}