2 +----------------------------------------------------------------------+
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"
24 ///////////////////////////////////////////////////////////////////////////////
30 static const Extension
* CORE
;
35 typedef folly::dynamic Map
;
37 class ParserCallback
{
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
,
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
);
51 void makeArray(Variant
&hash
, const std::string
&offset
,
52 const std::string
&value
);
54 class SectionParserCallback
: public ParserCallback
{
57 Variant active_section
;
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
,
64 virtual void onPopEntry(const std::string
&key
, const std::string
&value
,
65 const std::string
&offset
, void *arg
);
67 Variant
* activeArray(CallbackData
* data
);
69 class SystemParserCallback
: public ParserCallback
{
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
,
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
);
79 void makeArray(Map
&hash
, const std::string
&offset
,
80 const std::string
&value
);
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
;
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
,
113 static void Bind(const Extension
* extension
, const Mode mode
,
115 UpdateCallback updateCallback
, GetCallback getCallback
,
117 static void Bind(const Extension
* extension
, const Mode mode
,
120 static void Bind(const Extension
* extension
, const Mode mode
,
121 const char *name
, const char *value
,
123 static void Bind(const Extension
* extension
, const Mode mode
,
126 static void Bind(const Extension
* extension
, const Mode mode
,
127 const char *name
, const char *value
,
129 static void Bind(const Extension
* extension
, const Mode mode
,
132 static void Bind(const Extension
* extension
, const Mode mode
,
133 const char *name
, const char *value
,
135 static void Bind(const Extension
* extension
, const Mode mode
,
138 static void Bind(const Extension
* extension
, const Mode mode
,
139 const char *name
, const char *value
,
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_