Beispiel #1
0
Array f_get_class_vars(CStrRef class_name) {
  ClassInfo::PropertyVec properties;
  ClassInfo::GetClassProperties(properties, class_name);
  CStrRef context = FrameInjection::GetClassName(true);
  const ClassInfo *cls = NULL;
  if (!context.empty()) {
    cls = ClassInfo::FindClass(context);
  }

  Array ret = Array::Create();
  // PHP has instance variables appear before static variables...
  for (unsigned int i = 0; i < properties.size(); i++) {
    if (!(properties[i]->attribute & ClassInfo::IsStatic) &&
        properties[i]->isVisible(cls)) {
      ret.set(properties[i]->name,
              get_class_var_init(class_name.c_str(), properties[i]->name));
    }
  }
  for (unsigned int i = 0; i < properties.size(); i++) {
    if (properties[i]->attribute & ClassInfo::IsStatic &&
        properties[i]->isVisible(cls)) {
      ret.set(properties[i]->name,
              get_static_property(class_name.c_str(), properties[i]->name));
    }
  }
  return ret;
}
void BuiltinSymbols::ImportExtProperties(AnalysisResultPtr ar,
                                         VariableTablePtr dest,
                                         ClassInfo *cls) {
  ClassInfo::PropertyVec src = cls->getPropertiesVec();
  for (auto it = src.begin(); it != src.end(); ++it) {
    ClassInfo::PropertyInfo *pinfo = *it;
    int attrs = pinfo->attribute;
    ModifierExpressionPtr modifiers(
      new ModifierExpression(BlockScopePtr(), LocationPtr()));
    if (attrs & ClassInfo::IsPrivate) {
      modifiers->add(T_PRIVATE);
    } else if (attrs & ClassInfo::IsProtected) {
      modifiers->add(T_PROTECTED);
    }
    if (attrs & ClassInfo::IsStatic) {
      modifiers->add(T_STATIC);
    }

    dest->add(pinfo->name.data(),
              typePtrFromDataType(pinfo->type, Type::Variant),
              false, ar, ExpressionPtr(), modifiers);
  }
}
void VariableSerializer::write(CObjRef v) {
  if (!v.isNull() && m_type == JSON) {
    Array props = v->o_toArray();
    ClassInfo::PropertyVec properties;
    ClassInfo::GetClassProperties(properties, v->o_getClassName());
    for (ClassInfo::PropertyVec::const_iterator iter = properties.begin();
         iter != properties.end(); ++iter) {
      if ((*iter)->attribute & ClassInfo::IsProtected) {
        props.remove((*iter)->name);
      }
    }
    // Remove private props
    for (ArrayIter it(props); !it.end(); it.next()) {
      if (it.first().toString().charAt(0) == '\0') {
        props.remove(it.first());
      }
    }
    setObjectInfo(v->o_getClassName(), v->o_getId());
    props.serialize(this);
  } else {
    v.serialize(this);
  }
}