| 1 |
<?php |
| 2 |
|
| 3 |
|
| 4 |
namespace JFB_Components\Rest_Api; |
| 5 |
|
| 6 |
// If this file is called directly, abort. |
| 7 |
if ( ! defined( 'WPINC' ) ) { |
| 8 |
die; |
| 9 |
} |
| 10 |
|
| 11 |
class Rest_Response extends \WP_REST_Response { |
| 12 |
|
| 13 |
public function get_custom_header_prefix(): string { |
| 14 |
return 'X-JFB-'; |
| 15 |
} |
| 16 |
|
| 17 |
public function set_headers_merge( array $headers ) { |
| 18 |
if ( ! is_array( $this->headers ) ) { |
| 19 |
$this->set_headers( array() ); |
| 20 |
} |
| 21 |
|
| 22 |
$this->set_headers( array_merge( $this->headers, $headers ) ); |
| 23 |
} |
| 24 |
|
| 25 |
public function set_headers_custom( $headers ) { |
| 26 |
$prefix = $this->get_custom_header_prefix(); |
| 27 |
$prepared = array(); |
| 28 |
|
| 29 |
foreach ( $headers as $name => $value ) { |
| 30 |
$prepared[ $prefix . $name ] = $value; |
| 31 |
} |
| 32 |
|
| 33 |
$this->set_headers_merge( $prepared ); |
| 34 |
} |
| 35 |
} |
| 36 |
|