Add sub-controls for Hack array compat runtime checks
[hiphop-php.git] / hphp / runtime / base / user-directory.cpp
blob0f88c766db8b01f38e9bb9aeb16f5abec25c891e
1 /*
2 +----------------------------------------------------------------------+
3 | HipHop for PHP |
4 +----------------------------------------------------------------------+
5 | Copyright (c) 2010-present Facebook, Inc. (http://www.facebook.com) |
6 +----------------------------------------------------------------------+
7 | This source file is subject to version 3.01 of the PHP license, |
8 | that is bundled with this package in the file LICENSE, and is |
9 | available through the world-wide-web at the following url: |
10 | http://www.php.net/license/3_01.txt |
11 | If you did not receive a copy of the PHP license and are unable to |
12 | obtain it through the world-wide-web, please send a note to |
13 | license@php.net so we can mail you a copy immediately. |
14 +----------------------------------------------------------------------+
17 #include "hphp/runtime/base/user-directory.h"
18 #include "hphp/runtime/base/runtime-error.h"
19 #include "hphp/runtime/base/array-init.h"
20 #include "hphp/runtime/ext/stream/ext_stream.h"
22 namespace HPHP {
24 const StaticString
25 s_dir_opendir("dir_opendir"),
26 s_dir_closedir("dir_closedir"),
27 s_dir_readdir("dir_readdir"),
28 s_dir_rewinddir("dir_rewinddir");
30 ///////////////////////////////////////////////////////////////////////////////
32 UserDirectory::UserDirectory(Class* cls) : UserFSNode(cls) {
33 m_DirOpen = lookupMethod(s_dir_opendir.get());
34 m_DirClose = lookupMethod(s_dir_closedir.get());
35 m_DirRead = lookupMethod(s_dir_readdir.get());
36 m_DirRewind = lookupMethod(s_dir_rewinddir.get());
39 void UserDirectory::sweep() {
40 // Don't close like the parent, 'cause that's what zend does
43 bool UserDirectory::open(const String& path) {
44 // bool dir_opendir ( string $path , int $options )
45 bool invoked = false;
46 Variant ret = invoke(m_DirOpen, s_dir_opendir,
47 make_packed_array(path, 0), invoked);
48 if (invoked && ret.toBoolean()) {
49 return true;
51 raise_warning("\"%s::dir_opendir\" call failed", m_cls->name()->data());
52 return false;
55 void UserDirectory::close() {
56 // void dir_closedir()
57 invoke(m_DirClose, s_dir_closedir, Array::Create());
60 Variant UserDirectory::read() {
61 // String dir_readdir()
62 bool invoked = false;
63 auto ret = invoke(m_DirRead, s_dir_readdir,
64 Array::Create(), invoked);
65 if (!invoked) {
66 raise_warning("%s::dir_readdir is not implemented",
67 m_cls->name()->data());
68 return init_null();
70 return ret;
73 void UserDirectory::rewind() {
74 // String dir_rewinddir()
75 bool invoked = false;
76 invoke(m_DirRewind, s_dir_rewinddir, Array::Create(), invoked);
77 if (!invoked) {
78 raise_warning("%s::dir_rewinddir is not implemented",
79 m_cls->name()->data());