Use folly::dynamic::object and folly::dynamic::string exclusivly
[hiphop-php.git] / hphp / runtime / base / ini-setting.h
blobb2658297b9fb84105c89038882825be16d186848
1 /*
2 +----------------------------------------------------------------------+
3 | HipHop for PHP |
4 +----------------------------------------------------------------------+
5 | Copyright (c) 2010-2014 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 #ifndef incl_HPHP_INI_SETTING_H_
18 #define incl_HPHP_INI_SETTING_H_
20 #include "hphp/runtime/base/complex-types.h"
21 #include "folly/dynamic.h"
23 namespace HPHP {
24 ///////////////////////////////////////////////////////////////////////////////
26 class Extension;
28 class IniSetting {
29 public:
30 static const Extension* CORE;
31 enum ScannerMode {
32 NormalScanner,
33 RawScanner,
35 typedef folly::dynamic Map;
37 class ParserCallback {
38 public:
39 virtual ~ParserCallback() {};
40 virtual void onSection(const std::string &name, void *arg);
41 virtual void onLabel(const std::string &name, void *arg);
42 virtual void onEntry(const std::string &key, const std::string &value,
43 void *arg);
44 virtual void onPopEntry(const std::string &key, const std::string &value,
45 const std::string &offset, void *arg);
46 virtual void onConstant(std::string &result, const std::string &name);
47 virtual void onVar(std::string &result, const std::string &name);
48 virtual void onOp(std::string &result, char type, const std::string& op1,
49 const std::string& op2);
50 private:
51 void makeArray(Variant &hash, const std::string &offset,
52 const std::string &value);
54 class SectionParserCallback : public ParserCallback {
55 public:
56 struct CallbackData {
57 Variant active_section;
58 Variant arr;
60 virtual void onSection(const std::string &name, void *arg);
61 virtual void onLabel(const std::string &name, void *arg);
62 virtual void onEntry(const std::string &key, const std::string &value,
63 void *arg);
64 virtual void onPopEntry(const std::string &key, const std::string &value,
65 const std::string &offset, void *arg);
66 private:
67 Variant* activeArray(CallbackData* data);
69 class SystemParserCallback : public ParserCallback {
70 public:
71 virtual void onSection(const std::string &name, void *arg);
72 virtual void onLabel(const std::string &name, void *arg);
73 virtual void onEntry(const std::string &key, const std::string &value,
74 void *arg);
75 virtual void onPopEntry(const std::string &key, const std::string &value,
76 const std::string &offset, void *arg);
77 virtual void onConstant(std::string &result, const std::string &name);
78 private:
79 void makeArray(Map &hash, const std::string &offset,
80 const std::string &value);
83 enum Mode {
84 PHP_INI_NONE = 0,
85 // These 3 match zend
86 PHP_INI_USER = (1u << 0),
87 PHP_INI_PERDIR = (1u << 1),
88 PHP_INI_SYSTEM = (1u << 2),
90 PHP_INI_ONLY = (1u << 3),
91 PHP_INI_ALL = (1u << 4),
94 typedef std::function<bool(const std::string& value, void*p)> UpdateCallback;
95 typedef std::function<std::string(void* p)> GetCallback;
97 public:
98 static Variant FromString(const String& ini, const String& filename,
99 bool process_sections, int scanner_mode);
100 static Map FromStringAsMap(const std::string& ini,
101 const std::string& filename);
103 static bool Get(const std::string& name, std::string &value);
104 static bool Get(const String& name, String &value);
105 static bool Set(const String& name, const String& value);
106 static bool SetUser(const String& name, const String& value);
107 static Array GetAll(const String& extension, bool details);
109 static void Bind(const Extension* extension, const Mode mode,
110 const char *name, const char *value,
111 UpdateCallback updateCallback, GetCallback getCallback,
112 void *p = nullptr);
113 static void Bind(const Extension* extension, const Mode mode,
114 const char *name,
115 UpdateCallback updateCallback, GetCallback getCallback,
116 void *p = nullptr);
117 static void Bind(const Extension* extension, const Mode mode,
118 const char *name,
119 std::string *p);
120 static void Bind(const Extension* extension, const Mode mode,
121 const char *name, const char *value,
122 std::string *p);
123 static void Bind(const Extension* extension, const Mode mode,
124 const char *name,
125 String *p);
126 static void Bind(const Extension* extension, const Mode mode,
127 const char *name, const char *value,
128 String *p);
129 static void Bind(const Extension* extension, const Mode mode,
130 const char *name,
131 bool *p);
132 static void Bind(const Extension* extension, const Mode mode,
133 const char *name, const char *value,
134 bool *p);
135 static void Bind(const Extension* extension, const Mode mode,
136 const char *name,
137 int64_t *p);
138 static void Bind(const Extension* extension, const Mode mode,
139 const char *name, const char *value,
140 int64_t *p);
141 static void Unbind(const char *name);
143 static void SetGlobalDefault(const char *name, const char *value);
147 int64_t convert_bytes_to_long(const std::string& value);
149 #define ini_on_update_fail HPHP::IniSetting::UpdateCallback()
150 bool ini_on_update_bool(const std::string& value, void *p);
151 bool ini_on_update_long(const std::string& value, void *p);
152 bool ini_on_update_non_negative(const std::string& value, void *p);
153 bool ini_on_update_real(const std::string& value, void *p);
154 bool ini_on_update_stdstring(const std::string& value, void *p);
155 bool ini_on_update_string(const std::string& value, void *p);
157 std::string ini_get_bool(void *p);
158 std::string ini_get_bool_as_int(void *p);
159 std::string ini_get_long(void *p);
160 std::string ini_get_real(void *p);
161 std::string ini_get_string(void *p);
162 std::string ini_get_stdstring(void *p);
163 std::string ini_get_static_string_1(void *p);
165 ///////////////////////////////////////////////////////////////////////////////
168 #endif // incl_HPHP_INI_SETTING_H_