@@ -60,6 +60,52 @@ typedef struct{
6060 git_config * config ;
6161} php_git2_config_foreach_t ;
6262
63+ static int php_git2_config_resolve (zval * * result , const char * var_name , zval * m_config )
64+ {
65+ TSRMLS_FETCH ();
66+ HashTable * hash ;
67+ zval * entry , * tmp_result , * * target_offset ;
68+ char * current_key , * tmp_value , * savedptr , * k ;
69+ int error = 0 ;
70+
71+ entry = zend_read_property (git2_config_class_entry , m_config ,"configs" ,sizeof ("configs" )- 1 , 0 TSRMLS_CC );
72+
73+ tmp_value = estrdup (var_name );
74+ current_key = php_strtok_r (tmp_value , "." , & savedptr );
75+ while (current_key != NULL ) {
76+ k = current_key ;
77+ current_key = php_strtok_r (NULL , "." , & savedptr );
78+
79+ if (current_key != NULL && k != NULL ) {
80+ if (zend_hash_exists (Z_ARRVAL_P (entry ), k , strlen (k )+ 1 )) {
81+ if (zend_hash_find (Z_ARRVAL_P (entry ), k , strlen (k )+ 1 , (void * * )& target_offset ) == SUCCESS ) {
82+ entry = * target_offset ;
83+ }
84+ } else {
85+ target_offset = NULL ;
86+ }
87+ } else {
88+ if (k != NULL ) {
89+ if (zend_hash_find (Z_ARRVAL_P (entry ), k , strlen (k )+ 1 , (void * * )& target_offset ) != SUCCESS ) {
90+ target_offset = NULL ;
91+ }
92+ }
93+ }
94+ }
95+ efree (tmp_value );
96+
97+ if (target_offset != NULL ) {
98+ MAKE_STD_ZVAL (tmp_result );
99+ ZVAL_ZVAL (tmp_result , * target_offset ,1 ,0 );
100+ } else {
101+ MAKE_STD_ZVAL (tmp_result );
102+ ZVAL_NULL (tmp_result );
103+ }
104+ * result = tmp_result ;
105+
106+ return error ;
107+ }
108+
63109static int php_git2_config_foreach (const char * var_name , const char * value , void * payload )
64110{
65111 HashTable * hash ;
@@ -150,15 +196,19 @@ PHP_METHOD(git2_config, get)
150196 int error , key_len = 0 ;
151197 const char * value ;
152198 php_git2_config * m_config ;
199+ zval * result ;
153200
154201 if (zend_parse_parameters (ZEND_NUM_ARGS () TSRMLS_CC ,
155202 "s" , & key , & key_len ) == FAILURE ) {
156203 return ;
157204 }
158205
159- m_config = PHP_GIT2_GET_OBJECT (php_git2_config , getThis ());
160- error = git_config_get_string (m_config -> config , key , & value );
161- RETVAL_STRING (value , 1 );
206+ if (key_len < 1 ) {
207+ RETURN_FALSE ;
208+ }
209+
210+ php_git2_config_resolve (& result , (const char * )key , getThis ());
211+ RETVAL_ZVAL (result ,0 ,1 );
162212}
163213/* }}} */
164214
0 commit comments