@@ -55,6 +55,15 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_git2_config_get, 0,0,1)
55
55
ZEND_ARG_INFO (0 , get )
56
56
ZEND_END_ARG_INFO ()
57
57
58
+ ZEND_BEGIN_ARG_INFO_EX (arginfo_git2_config_store , 0 ,0 ,2 )
59
+ ZEND_ARG_INFO (0 , key )
60
+ ZEND_ARG_INFO (0 , value )
61
+ ZEND_END_ARG_INFO ()
62
+
63
+ ZEND_BEGIN_ARG_INFO_EX (arginfo_git2_config_delete , 0 ,0 ,1 )
64
+ ZEND_ARG_INFO (0 , key )
65
+ ZEND_END_ARG_INFO ()
66
+
58
67
typedef struct {
59
68
zval * result ;
60
69
git_config * config ;
@@ -151,6 +160,32 @@ static int php_git2_config_foreach(const char *var_name, const char *value, void
151
160
return GIT_SUCCESS ;
152
161
}
153
162
163
+ static int php_git2_config_reload (zval * object , unsigned short dtor TSRMLS_DC )
164
+ {
165
+ zval * entry ;
166
+ php_git2_config_foreach_t payload ;
167
+ php_git2_config * m_config ;
168
+ int error = 0 ;
169
+
170
+ m_config = PHP_GIT2_GET_OBJECT (php_git2_config , object );
171
+ entry = zend_read_property (git2_config_class_entry , object ,"configs" ,sizeof ("configs" )- 1 , 1 TSRMLS_CC );
172
+ if (entry != NULL ) {
173
+ zval_ptr_dtor (& entry );
174
+ entry = NULL ;
175
+ }
176
+
177
+ MAKE_STD_ZVAL (entry );
178
+ array_init (entry );
179
+
180
+ payload .config = m_config -> config ;
181
+ payload .result = entry ;
182
+ error = git_config_foreach (m_config -> config ,& php_git2_config_foreach ,& payload );
183
+ add_property_zval (object , "configs" , entry );
184
+ if (dtor == 1 ) {
185
+ zval_ptr_dtor (& entry );
186
+ }
187
+ }
188
+
154
189
/*
155
190
{{{ proto: Git2\Config::__construct(string $path)
156
191
*/
@@ -174,15 +209,11 @@ PHP_METHOD(git2_config, __construct)
174
209
m_config = PHP_GIT2_GET_OBJECT (php_git2_config , getThis ());
175
210
m_config -> config = config ;
176
211
177
- /* @todo: think solution */
178
- MAKE_STD_ZVAL (config_array );
179
- array_init (config_array );
180
-
181
- payload .config = config ;
182
- payload .result = config_array ;
183
- error = git_config_foreach (config ,& php_git2_config_foreach ,& payload );
184
- add_property_zval (getThis (), "configs" , config_array );
185
- zval_ptr_dtor (& config_array );
212
+ php_git2_config_reload (getThis (), 1 TSRMLS_CC );
213
+ /**
214
+ * @todo: support global config
215
+ * php_array_merge(HashTable *dest, HashTable *src, int recursive TSRMLS_DC);
216
+ */
186
217
}
187
218
/* }}} */
188
219
@@ -213,9 +244,80 @@ PHP_METHOD(git2_config, get)
213
244
/* }}} */
214
245
215
246
247
+ /*
248
+ {{{ proto: Git2\Config::store(string $key, mixed $value)
249
+ */
250
+ PHP_METHOD (git2_config , store )
251
+ {
252
+ char * key ;
253
+ int error , key_len = 0 ;
254
+ zval * result , * value , * entry ;
255
+ php_git2_config * m_config ;
256
+ php_git2_config_foreach_t payload ;
257
+
258
+ if (zend_parse_parameters (ZEND_NUM_ARGS () TSRMLS_CC ,
259
+ "sz" , & key , & key_len , & value ) == FAILURE ) {
260
+ return ;
261
+ }
262
+
263
+ if (key_len < 1 ) {
264
+ RETURN_FALSE ;
265
+ }
266
+
267
+ m_config = PHP_GIT2_GET_OBJECT (php_git2_config , getThis ());
268
+
269
+ switch (Z_TYPE_P (value )) {
270
+ case IS_STRING :
271
+ error = git_config_set_string (m_config -> config , key , Z_STRVAL_P (value ));
272
+ break ;
273
+ case IS_BOOL :
274
+ error = git_config_set_bool (m_config -> config , key , Z_BVAL_P (value ));
275
+ break ;
276
+ case IS_LONG :
277
+ error = git_config_set_int32 (m_config -> config , key , Z_LVAL_P (value ));
278
+ break ;
279
+ default :
280
+ zend_throw_exception_ex (spl_ce_InvalidArgumentException , 0 TSRMLS_CC ,
281
+ "Git2\\Config::store must pass string or bool or long value" );
282
+ RETURN_FALSE ;
283
+ }
284
+
285
+ php_git2_config_reload (getThis (),0 TSRMLS_CC );
286
+ }
287
+ /* }}} */
288
+
289
+
290
+ /*
291
+ {{{ proto: Git2\Config::delete(string $key)
292
+ */
293
+ PHP_METHOD (git2_config , delete )
294
+ {
295
+ char * key ;
296
+ int error , key_len = 0 ;
297
+ zval * result , * entry ;
298
+ php_git2_config * m_config ;
299
+ php_git2_config_foreach_t payload ;
300
+
301
+ if (zend_parse_parameters (ZEND_NUM_ARGS () TSRMLS_CC ,
302
+ "s" , & key , & key_len ) == FAILURE ) {
303
+ return ;
304
+ }
305
+
306
+ if (key_len < 1 ) {
307
+ RETURN_FALSE ;
308
+ }
309
+
310
+ m_config = PHP_GIT2_GET_OBJECT (php_git2_config , getThis ());
311
+ git_config_delete (m_config -> config , key );
312
+ php_git2_config_reload (getThis (), 0 TSRMLS_CC );
313
+ }
314
+ /* }}} */
315
+
216
316
static zend_function_entry php_git2_config_methods [] = {
217
317
PHP_ME (git2_config , __construct , arginfo_git2_config___construct , ZEND_ACC_PUBLIC )
218
318
PHP_ME (git2_config , get , arginfo_git2_config_get , ZEND_ACC_PUBLIC )
319
+ PHP_ME (git2_config , store , arginfo_git2_config_store , ZEND_ACC_PUBLIC )
320
+ PHP_ME (git2_config , delete , arginfo_git2_config_delete , ZEND_ACC_PUBLIC )
219
321
{NULL ,NULL ,NULL }
220
322
};
221
323
0 commit comments