Пример #1
0
Variant f_preg_match_all(CStrRef pattern, CStrRef subject, VRefParam matches,
                         int flags /* = 0 */, int offset /* = 0 */) {
  if (matches.isReferenced()) {
    return preg_match_all(pattern, subject, matches, flags, offset);
  } else {
    return preg_match_all(pattern, subject, flags, offset);
  }
}
Пример #2
0
Variant HHVM_FUNCTION(preg_match_all, const String& pattern,
                                      const String& subject,
                                      VRefParam matches /* = null */,
                                      int flags /* = 0 */,
                                      int offset /* = 0 */) {
  if (matches.isReferenced()) {
    return preg_match_all(pattern, subject, matches, flags, offset);
  } else {
    return preg_match_all(pattern, subject, flags, offset);
  }
}
Пример #3
0
Variant HHVM_FUNCTION(preg_match_all,
                      const String& pattern,
                      const String& subject,
                      VRefParam matches /* = null */,
                      int flags /* = 0 */,
                      int offset /* = 0 */) {
  return preg_match_all(pattern, subject,
                        matches.getVariantOrNull(),
                        flags, offset);
}
Пример #4
0
TypedValue HHVM_FUNCTION(preg_match_all,
                         const String& pattern,
                         const String& subject,
                         OutputArg matches /* = null */,
                         int flags /* = 0 */,
                         int offset /* = 0 */) {
  return tvReturn(preg_match_all(pattern, subject,
                                 matches.get() ? matches->var() : nullptr,
                                 flags, offset));
}
Пример #5
0
Array HHVM_FUNCTION(get_meta_tags, const String& filename,
                                   bool use_include_path /* = false */) {
  String f = HHVM_FN(file_get_contents)(filename);

  Variant matches;
  preg_match_all("/<meta\\s+name=\"(.*?)\"\\s+content=\"(.*?)\".*?>/s",
                 f, &matches, PREG_SET_ORDER);

  Array ret = Array::Create();
  for (ArrayIter iter(matches.toArray()); iter; ++iter) {
    Array pair = iter.second().toArray();
    ret.set(normalize_variable_name(pair[1].toString()), pair[2]);
  }
  return ret;
}
Пример #6
0
static Variant yaf_route_rewrite_match(const Object& o, 
        const char* req_uri, int req_uri_len)
{
    char match[8192];
    auto ptr_match = o->o_realProp(YAF_ROUTE_PROPETY_NAME_MATCH,
                    ObjectData::RealPropUnchecked, "Yaf_Route_Rewrite");
    snprintf(match, sizeof(match), "%s", ptr_match->toString().c_str());

    std::string pattern;
    pattern.append(YAF_ROUTE_REGEX_DILIMITER_STR);
    pattern.append("^");

    char* save_ptr;
    char* seg = strtok_r(match, YAF_ROUTER_URL_DELIMIETER, &save_ptr);
    while (seg != NULL) {
        int len = strlen(seg);
        if (len) {
            pattern.append(YAF_ROUTER_URL_DELIMIETER);
            if (*seg == '*') {
                pattern.append("(?P<__yaf_route_rest>.*)");
                break;
            }

            if (*seg == ':') {
                pattern.append("(?P<");
                pattern.append(std::string(seg+1));
                pattern.append(std::string(">[^") + YAF_ROUTER_URL_DELIMIETER + "]+)");
            } else {
                pattern.append(seg);
            }
        }

        seg = strtok_r(NULL, YAF_ROUTER_URL_DELIMIETER, &save_ptr);
    }

    pattern.append(YAF_ROUTE_REGEX_DILIMITER_STR);
    pattern.append("i");

    Variant matches;
    Variant ret = preg_match_all(String(pattern), 
                   String(std::string(req_uri, req_uri_len)), matches);
    int match_count = 0;
    if (ret.isIntVal() ) {
        match_count = ret.toInt32();
    }

    if (match_count <= 0) {
        return init_null_variant;
    }

    if (!matches.isArray()) {
        return init_null_variant;
    }

    Array args = Array::Create();
    Array& arr_matches = matches.toArrRef();
    ArrayIter iter = arr_matches.begin();
    while (!iter.end()) {
        Variant key = iter.first();
        Variant value = iter.second();
        
        if (!key.isString()) {
            iter.next();
            continue;
        }

        if (!strncmp(key.toString().c_str(), "__yaf_route_rest", key.toString().length())) {
            Variant retval = yaf_router_parse_parameters(value.toArrRef()[0].toString().c_str());
            if (retval.isArray()) {
                args.merge(retval.toArray());
            }
        } else {
            args.set(key, value.toArrRef()[0]);
        }

        iter.next();
    }

    return args;
}