| 1 |
<?php |
| 2 |
/** |
| 3 |
* A class for storing the current context for a request in WordPress. |
| 4 |
* |
| 5 |
* @since 0.1.0 |
| 6 |
* |
| 7 |
* @package SolidWP\Performance |
| 8 |
*/ |
| 9 |
|
| 10 |
namespace SolidWP\Performance\Page_Cache; |
| 11 |
|
| 12 |
use SolidWP\Performance\Http\Request; |
| 13 |
|
| 14 |
/** |
| 15 |
* A class for storing the current context for a request in WordPress. |
| 16 |
* |
| 17 |
* @since 0.1.0 |
| 18 |
* |
| 19 |
* @package SolidWP\Performance |
| 20 |
*/ |
| 21 |
class WP_Context { |
| 22 |
/** |
| 23 |
* The current request. |
| 24 |
* |
| 25 |
* @since 0.1.0 |
| 26 |
* |
| 27 |
* @var Request |
| 28 |
*/ |
| 29 |
private Request $request; |
| 30 |
|
| 31 |
/** |
| 32 |
* The current post. |
| 33 |
* |
| 34 |
* @since 0.1.0 |
| 35 |
* |
| 36 |
* @var int |
| 37 |
*/ |
| 38 |
private int $post_id; |
| 39 |
|
| 40 |
/** |
| 41 |
* The class constructor. |
| 42 |
* |
| 43 |
* @since 0.1.0 |
| 44 |
* |
| 45 |
* @param Request $request A request instance. |
| 46 |
* @param int $post_id The ID of the current post. |
| 47 |
*/ |
| 48 |
public function __construct( Request $request, int $post_id = 0 ) { |
| 49 |
$this->request = $request; |
| 50 |
$this->post_id = $post_id; |
| 51 |
} |
| 52 |
|
| 53 |
/** |
| 54 |
* Gets the current request URI. |
| 55 |
* |
| 56 |
* @since 0.1.0 |
| 57 |
* |
| 58 |
* @return string |
| 59 |
*/ |
| 60 |
public function get_request(): Request { |
| 61 |
return $this->request; |
| 62 |
} |
| 63 |
|
| 64 |
/** |
| 65 |
* Gets the current post ID. |
| 66 |
* |
| 67 |
* @since 0.1.0 |
| 68 |
* |
| 69 |
* @return int |
| 70 |
*/ |
| 71 |
public function get_post_id(): int { |
| 72 |
return $this->post_id; |
| 73 |
} |
| 74 |
} |
| 75 |
|