예제 #1
0
Variant f_hphp_recursivedirectoryiterator_key(CObjRef obj) {
  RecursiveDirectoryIterator *rdi = get_recursivedirectoryiterator(obj);
  if (rdi->m_flags == KEY_AS_FILENAME) {
    return rdi->m_dirEntry;
  }
  return rdi->getPathName();
}
예제 #2
0
bool f_hphp_recursiveiteratoriterator_valid(CObjRef obj) {
  RecursiveIteratorIterator *rii = get_recursiveiteratoriterator(obj);
  unsigned int size = rii->m_iterators.size();
  if (!size) return false;
  if (rii->m_iterators[size-1].first.is<RecursiveDirectoryIterator>()) {
    RecursiveDirectoryIterator *rdi =
      rii->m_iterators[size-1].first.getTyped<RecursiveDirectoryIterator>();
    bool valid = rdi->valid();
    if (valid) {
      if (rii->m_mode == HPHP::q_recursiveiteratoriterator_LEAVES_ONLY ||
          rii->m_mode == HPHP::q_recursiveiteratoriterator_CHILD_FIRST) {
        String pathName = rdi->getPathName();
        if (f_is_dir(pathName)) {
          if (rii->m_iterators[size-1].second > 0 &&
              rii->m_mode == HPHP::q_recursiveiteratoriterator_CHILD_FIRST) {
            return true;
          }
          return false;
        }
      }
    }
    return valid;
  }
  throw InvalidArgumentException("iterator", "unsupported type");
}
예제 #3
0
bool f_hphp_recursiveiteratoriterator_valid(CObjRef obj) {
  RecursiveIteratorIterator *rii = get_recursiveiteratoriterator(obj);
  unsigned int size = rii->m_iterators.size();
  if (!size) return false;
  Object firstIt = rii->m_iterators[size-1].first;
  if (firstIt.is<RecursiveDirectoryIterator>()) {
    RecursiveDirectoryIterator* rdi =
      firstIt.getTyped<RecursiveDirectoryIterator>();
    bool valid = rdi->valid();
    if (valid) {
      if (rii->m_mode == LEAVES_ONLY ||
          rii->m_mode == CHILD_FIRST) {
        String pathName = rdi->getPathName();
        if (f_is_dir(pathName)) {
          if (rii->m_iterators[size-1].second > 0 &&
              rii->m_mode == CHILD_FIRST) {
            return true;
          }
          return false;
        }
      }
    }
    return valid;
  }
  throw NotImplementedException("this type of iterator");
}
예제 #4
0
Object f_hphp_recursivedirectoryiterator_getchildren(CObjRef obj) {
  if (!f_hphp_recursivedirectoryiterator_haschildren(obj)) return Object();
  RecursiveDirectoryIterator *rdi = get_recursivedirectoryiterator(obj);
  c_recursivedirectoryiterator *c_rdi = NEW(c_recursivedirectoryiterator)();
  c_rdi->m_rsrc =
    NEW(RecursiveDirectoryIterator)(rdi->getPathName(), rdi->m_flags);
  return c_rdi;
}
예제 #5
0
Object f_hphp_recursivedirectoryiterator_getchildren(CObjRef obj) {
  if (!f_hphp_recursivedirectoryiterator_haschildren(obj)) return Object();
  RecursiveDirectoryIterator *rdi = get_recursivedirectoryiterator(obj);
  ObjectData* o_rdi = SystemLib::AllocRecursiveDirectoryIteratorObject();
  o_rdi->o_set("rsrc",
               NEWOBJ(RecursiveDirectoryIterator)(rdi->getPathName(),
                                                  rdi->m_flags),
               "SplFileInfo");
  return o_rdi;
}
예제 #6
0
Variant f_hphp_recursivedirectoryiterator_current(CObjRef obj) {
  RecursiveDirectoryIterator *rdi = get_recursivedirectoryiterator(obj);
  String pathName = rdi->getPathName();
  if (rdi->m_flags & CURRENT_AS_PATHNAME) {
    return pathName;
  }
  if (rdi->m_flags & CURRENT_AS_FILEINFO) {
    return SystemLib::AllocSplFileInfoObject(pathName);
  }
  return obj;
}
예제 #7
0
Variant f_hphp_recursivedirectoryiterator_current(CObjRef obj) {
  RecursiveDirectoryIterator *rdi = get_recursivedirectoryiterator(obj);
  String pathName = rdi->getPathName();
  if (rdi->m_flags & HPHP::q_recursivedirectoryiterator_CURRENT_AS_PATHNAME) {
    return pathName;
  }
  if (rdi->m_flags & HPHP::q_recursivedirectoryiterator_CURRENT_AS_FILEINFO) {
    c_splfileinfo *c_splfi = NEW(c_splfileinfo)();
    c_splfi->m_rsrc = NEW(SplFileInfo)(pathName);
    return c_splfi;
  }
  return obj;
}
예제 #8
0
Variant f_hphp_recursivedirectoryiterator_current(CObjRef obj) {
  RecursiveDirectoryIterator *rdi = get_recursivedirectoryiterator(obj);
  String pathName = rdi->getPathName();
  if (rdi->m_flags & HPHP::q_RecursiveDirectoryIterator$$CURRENT_AS_PATHNAME) {
    return pathName;
  }
  if (rdi->m_flags & HPHP::q_RecursiveDirectoryIterator$$CURRENT_AS_FILEINFO) {
    ObjectData* c_splfi = SystemLib::AllocSplFileInfoObject();
    c_splfi->o_set("rsrc", NEWOBJ(SplFileInfo)(pathName), "SplFileInfo");
    return c_splfi;
  }
  return obj;
}
예제 #9
0
void f_hphp_recursiveiteratoriterator_next(CObjRef obj) {
  RecursiveIteratorIterator *rii = get_recursiveiteratoriterator(obj);
  unsigned int size = rii->m_iterators.size();
  if (!size) return;
  Object ci = rii->m_iterators[size-1].first;
  if (rii->m_mode == SELF_FIRST) {
    if (!ci.is<RecursiveDirectoryIterator>()) {
      throw NotImplementedException("this type of iterator");
    }
    RecursiveDirectoryIterator *rdi =
      ci.getTyped<RecursiveDirectoryIterator>();
    String pathName = rdi->getPathName();
    if (f_is_dir(pathName) && !rii->m_iterators[size-1].second) {
      rii->m_iterators[size-1].second = 1;
      RecursiveDirectoryIterator *ii =
        NEWOBJ(RecursiveDirectoryIterator)(pathName, rdi->m_flags);
      rii->m_iterators.push_back(std::make_pair(ii, 0));
      ii->incRefCount();
      if (ii->isdot()) ii->next();
    } else {
      rdi->next();
      rii->m_iterators[size-1].second = 0;
    }
    if (f_hphp_recursiveiteratoriterator_valid(obj)) return;
    decRefObj(rii->m_iterators.back().first);
    rii->m_iterators.pop_back();
    return f_hphp_recursiveiteratoriterator_next(obj);
  } else if (rii->m_mode == CHILD_FIRST ||
             rii->m_mode == LEAVES_ONLY) {
    if (!ci.is<RecursiveDirectoryIterator>()) {
      throw NotImplementedException("this type of iterator");
    }
    RecursiveDirectoryIterator *rdi =
      ci.getTyped<RecursiveDirectoryIterator>();
    String pathName = rdi->getPathName();
    if (pathName.empty()) {
      decRefObj(rii->m_iterators.back().first);
      rii->m_iterators.pop_back();
      return f_hphp_recursiveiteratoriterator_next(obj);
    } else if (f_is_dir(pathName)) {
      if (!rii->m_iterators[size-1].second) {
        rii->m_iterators[size-1].second = 1;
        RecursiveDirectoryIterator *ii =
          NEWOBJ(RecursiveDirectoryIterator)(pathName, rdi->m_flags);
        rii->m_iterators.push_back(std::make_pair(ii, 0));
        ii->incRefCount();
        ii->rewind();
        if (f_hphp_recursiveiteratoriterator_valid(obj)) return;
        return f_hphp_recursiveiteratoriterator_next(obj);
      } else {
        // CHILD_FIRST: 0 - drill down; 1 - visit 2 - next
        // LEAVES_ONLY: 0 - drill down; 1 - next
        if (rii->m_mode == CHILD_FIRST &&
          rii->m_iterators[size-1].second == 1) {
          rii->m_iterators[size-1].second = 2;
          return;
        }
      }
    }
    rii->m_iterators[size-1].second = 0;
    rdi->next();
    if (f_hphp_recursiveiteratoriterator_valid(obj)) return;
    return f_hphp_recursiveiteratoriterator_next(obj);
  } else {
    if (!ci.is<RecursiveDirectoryIterator>()) {
      throw NotImplementedException("this type of iterator");
    }
    RecursiveDirectoryIterator *rdi =
      ci.getTyped<RecursiveDirectoryIterator>();
    assert(rii->m_iterators[size-1].second == 0);
    rdi->next();
  }
}
예제 #10
0
void f_hphp_recursiveiteratoriterator_next(CObjRef obj) {
  RecursiveIteratorIterator *rii = get_recursiveiteratoriterator(obj);
  unsigned int size = rii->m_iterators.size();
  if (!size) return;
  Object ci = rii->m_iterators[size-1].first;
  if (rii->m_mode == HPHP::q_recursiveiteratoriterator_SELF_FIRST) {
    if (!ci.is<RecursiveDirectoryIterator>()) {
      throw InvalidArgumentException("iterator", "unsupported type");
    }
    RecursiveDirectoryIterator *rdi =
      ci.getTyped<RecursiveDirectoryIterator>();
    String pathName = rdi->getPathName();
    if (f_is_dir(pathName) && !rii->m_iterators[size-1].second) {
      rii->m_iterators[size-1].second = 1;
      RecursiveDirectoryIterator *ii =
        NEW(RecursiveDirectoryIterator)(pathName, rdi->m_flags);
      rii->m_iterators.push_back(std::pair<Object, bool>(ii, 0));
      ii->next();
    } else {
      rdi->next();
      rii->m_iterators[size-1].second = 0;
    }
    if (f_hphp_recursiveiteratoriterator_valid(obj)) return;
    rii->m_iterators.pop_back();
    return f_hphp_recursiveiteratoriterator_next(obj);
  } else if (rii->m_mode == HPHP::q_recursiveiteratoriterator_CHILD_FIRST ||
             rii->m_mode == HPHP::q_recursiveiteratoriterator_LEAVES_ONLY) {
    if (!ci.is<RecursiveDirectoryIterator>()) {
      throw InvalidArgumentException("iterator", "unsupported type");
    }
    RecursiveDirectoryIterator *rdi =
      ci.getTyped<RecursiveDirectoryIterator>();
    String pathName = rdi->getPathName();
    if (pathName.empty()) {
      rii->m_iterators.pop_back();
      return f_hphp_recursiveiteratoriterator_next(obj);
    } else if (f_is_dir(pathName)) {
      if (!rii->m_iterators[size-1].second) {
        rii->m_iterators[size-1].second = 1;
        RecursiveDirectoryIterator *ii =
          NEW(RecursiveDirectoryIterator)(pathName, rdi->m_flags);
        rii->m_iterators.push_back(std::pair<Object, bool>(ii, 0));
        ii->rewind();
        if (f_hphp_recursiveiteratoriterator_valid(obj)) return;
        return f_hphp_recursiveiteratoriterator_next(obj);
      } else {
        // CHILD_FIRST: 0 - drill down; 1 - visit 2 - next
        // LEAVES_ONLY: 0 - drill down; 1 - next
        if (rii->m_mode == HPHP::q_recursiveiteratoriterator_CHILD_FIRST &&
          rii->m_iterators[size-1].second == 1) {
          rii->m_iterators[size-1].second = 2;
          return;
        }
      }
    }
    rii->m_iterators[size-1].second = 0;
    rdi->next();
    if (f_hphp_recursiveiteratoriterator_valid(obj)) return;
    return f_hphp_recursiveiteratoriterator_next(obj);
  } else if (rii->m_mode == HPHP::q_recursiveiteratoriterator_CATCH_GET_CHILD) {
    throw InvalidArgumentException("iterator", "unsupported mode");
  }
  throw InvalidArgumentException("iterator", "unsupported mode");
}