|
11 | 11 | use function Takuya\Utils\assert_str_is_domain; |
12 | 12 | use League\Flysystem\WebDAV\WebDAVAdapter; |
13 | 13 | use League\Flysystem\Filesystem; |
| 14 | +use function Takuya\Utils\array_map_with_key; |
14 | 15 |
|
15 | 16 | class BacklogAPIClient { |
16 | 17 |
|
@@ -167,10 +168,29 @@ public function call_api( $method, $path, $query = null, $params=null) { |
167 | 168 |
|
168 | 169 | return $res->getBody()->getContents(); |
169 | 170 | } |
170 | | - protected function http_build_query($data,$numeric_prefix=false,$arg_separator=null,$encoding_type=PHP_QUERY_RFC3986){ |
171 | | - $str = http_build_query($data,$numeric_prefix,$arg_separator=null,$encoding_type); |
172 | | - $str = preg_replace('/%5B(?:[0-9]|[1-9][0-9]+)%5D=/', '%5B%5D=', $str); |
173 | | - return $str; |
| 171 | + protected function http_build_query($data,$numeric_prefix=false,$arg_separator=null,$encoding_type=PHP_QUERY_RFC3986) { |
| 172 | + // custom field は複数キーが許可される。 |
| 173 | + $cust_array = array_filter( $data, fn( $v, $k ) => preg_match( '/custom/', $k ) && is_array( $v ), |
| 174 | + ARRAY_FILTER_USE_BOTH ); |
| 175 | + if ( sizeof( $cust_array ) > 0 ) { |
| 176 | + $cf_list = '&'.join( '&', |
| 177 | + array_map_with_key( $cust_array, function( $k, $values ) { |
| 178 | + return join( '&', array_map( fn( $v ) => sprintf( "%s=%s", urldecode( $k ), urlencode( $v ) ), $values ) ); |
| 179 | + } ) ); |
| 180 | + }else{ |
| 181 | + $cf_list = ''; |
| 182 | + } |
| 183 | + |
| 184 | + // bool値が name=1 になるのを避けて、 name=true にする。 |
| 185 | + array_walk_recursive( $data, function( &$v ) { |
| 186 | + if ( is_bool( $v ) ) { |
| 187 | + $v = json_encode( $v ); |
| 188 | + } |
| 189 | + } ); |
| 190 | + // 配列が name[0]=value になるのを避けて、name[]=value にする |
| 191 | + $str = http_build_query( $data, $numeric_prefix, $arg_separator = null, $encoding_type ); |
| 192 | + $str = preg_replace( '/%5B(?:[0-9]|[1-9][0-9]+)%5D=/', '%5B%5D=', $str ); |
| 193 | + return $str.$cf_list; |
174 | 194 | } |
175 | 195 |
|
176 | 196 | protected function send_request( $method, $path, $opts ) { |
|
0 commit comments