2 +----------------------------------------------------------------------+
4 +----------------------------------------------------------------------+
5 | Copyright (c) 2010-2013 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 +----------------------------------------------------------------------+
16 #ifndef incl_HPHP_RUNTIME_VM_NAME_VALUE_TABLE_WRAPPER_H
17 #define incl_HPHP_RUNTIME_VM_NAME_VALUE_TABLE_WRAPPER_H
19 #include "hphp/runtime/vm/name_value_table.h"
20 #include "hphp/runtime/base/array/array_data.h"
24 //////////////////////////////////////////////////////////////////////
27 * Wrapper to provide a KindOfArray interface to a NameValueTable.
28 * This is used to expose a NameValueTable to php code, particularly
29 * for $GLOBALS, but also for some internal generated-bytecode
30 * initialization routines (86pinit, 86sinit).
32 * Some differences compared to normal php arrays:
34 * - Does not behave as if it has value semantics. (I.e., no COW.)
36 * - Iteration order is not specified.
38 * - Non-string keys are not really supported. (Integers are
39 * converted to strings.)
41 * - size() is an O(N) operation. (This is because of KindOfIndirect
42 * support in the underlying NameValueTable.)
44 * - Append/prepend operations are not supported.
46 * - Strong iterators "past the end" are not updated when new
47 * elements are added. (Since iteration order is unspecified,
48 * this semantic would seem weird anyway.)
50 * This holds a pointer to a NameValueTable whose lifetime must be
51 * guaranteed to outlast the lifetime of the NameValueTableWrapper.
52 * (The wrapper is refcounted, as required by ArrayData, but the table
55 struct NameValueTableWrapper
: public ArrayData
{
56 explicit NameValueTableWrapper(NameValueTable
* tab
)
57 : ArrayData(kNameValueTableWrapper
)
61 public: // ArrayData implementation
63 // these using directives ensure the full set of overloaded functions
64 // are visible in this class, to avoid triggering implicit conversions
65 // from a CVarRef key to int64.
66 using ArrayData::exists
;
68 using ArrayData::getIndex
;
69 using ArrayData::lval
;
70 using ArrayData::lvalNew
;
71 using ArrayData::lvalPtr
;
73 using ArrayData::setRef
;
75 using ArrayData::addLval
;
76 using ArrayData::remove
;
78 virtual ssize_t
vsize() const;
79 virtual Variant
getKey(ssize_t pos
) const;
80 virtual Variant
getValue(ssize_t pos
) const;
81 virtual CVarRef
getValueRef(ssize_t pos
) const;
82 virtual bool noCopyOnWrite() const;
84 virtual bool exists(int64_t k
) const;
85 virtual bool exists(const StringData
* k
) const;
86 virtual bool idxExists(ssize_t idx
) const;
88 virtual CVarRef
get(int64_t k
, bool error
= false) const;
89 virtual CVarRef
get(const StringData
* k
, bool error
= false) const;
91 virtual TypedValue
* nvGet(int64_t k
) const;
92 virtual TypedValue
* nvGet(const StringData
* k
) const;
94 virtual ssize_t
getIndex(int64_t k
) const;
95 virtual ssize_t
getIndex(const StringData
* k
) const;
97 virtual ArrayData
* lval(int64_t k
, Variant
*& ret
, bool copy
,
98 bool checkExist
= false);
99 virtual ArrayData
* lval(StringData
* k
, Variant
*& ret
,
100 bool copy
, bool checkExist
= false);
101 virtual ArrayData
* lvalNew(Variant
*& ret
, bool copy
);
103 virtual ArrayData
* set(int64_t k
, CVarRef v
, bool copy
);
104 virtual ArrayData
* set(StringData
* k
, CVarRef v
, bool copy
);
105 virtual ArrayData
* setRef(int64_t k
, CVarRef v
, bool copy
);
106 virtual ArrayData
* setRef(StringData
* k
, CVarRef v
, bool copy
);
107 virtual ArrayData
* remove(int64_t k
, bool copy
);
108 virtual ArrayData
* remove(const StringData
* k
, bool copy
);
110 virtual ArrayData
* copy() const { return 0; }
112 virtual ArrayData
* append(CVarRef v
, bool copy
);
113 virtual ArrayData
* appendRef(CVarRef v
, bool copy
);
114 virtual ArrayData
* appendWithRef(CVarRef v
, bool copy
);
116 virtual ArrayData
* append(const ArrayData
* elems
, ArrayOp op
, bool copy
);
118 virtual ArrayData
* prepend(CVarRef v
, bool copy
);
120 virtual ssize_t
iter_begin() const;
121 virtual ssize_t
iter_end() const;
122 virtual ssize_t
iter_advance(ssize_t prev
) const;
123 virtual ssize_t
iter_rewind(ssize_t prev
) const;
125 virtual Variant
reset();
126 virtual Variant
prev();
127 virtual Variant
current() const;
128 virtual CVarRef
currentRef();
129 virtual Variant
next();
130 virtual Variant
end();
131 virtual CVarRef
endRef();
132 virtual Variant
key() const;
133 virtual Variant
value(int32_t &pos
) const;
134 virtual Variant
each();
135 virtual bool validFullPos(const FullPos
& fp
) const;
136 virtual bool advanceFullPos(FullPos
&);
138 virtual ArrayData
* escalateForSort();
139 virtual void ksort(int sort_flags
, bool ascending
);
140 virtual void sort(int sort_flags
, bool ascending
);
141 virtual void asort(int sort_flags
, bool ascending
);
142 virtual void uksort(CVarRef cmp_function
);
143 virtual void usort(CVarRef cmp_function
);
144 virtual void uasort(CVarRef cmp_function
);
147 NameValueTable
* const m_tab
;
150 class GlobalNameValueTableWrapper
: public NameValueTableWrapper
{
152 explicit GlobalNameValueTableWrapper(NameValueTable
* tab
);
161 Variant gvm__REQUEST
;
162 Variant gvm__SESSION
;
163 Variant gvm_HTTP_RAW_POST_DATA
;
164 Variant gvm_http_response_header
;
166 Variant __realPropProxy
;
169 Variant stgv_Variant
[1];
170 #define k_SID stgv_Variant[0]
173 //////////////////////////////////////////////////////////////////////