-
Notifications
You must be signed in to change notification settings - Fork 135
Fire actions before and after Optimization Detective processes a document #1919
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
abdefc0
64d63da
3b0f696
f7da494
51feaad
0ad7f79
8bcfc13
a57391d
6abee9c
09d7af7
0d8cb65
38a4c6b
5d12ef7
5da134c
53a91a2
a01d760
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
<?php | ||
/** | ||
* Optimization Detective: OD_Template_Optimization_Context class | ||
* | ||
* @package optimization-detective | ||
* @since n.e.x.t | ||
*/ | ||
|
||
// @codeCoverageIgnoreStart | ||
if ( ! defined( 'ABSPATH' ) ) { | ||
exit; // Exit if accessed directly. | ||
} | ||
// @codeCoverageIgnoreEnd | ||
|
||
/** | ||
* Context for optimizing a template. | ||
* | ||
* @since n.e.x.t | ||
* | ||
* @property-read OD_URL_Metric_Group_Collection $url_metric_group_collection URL Metric group collection. | ||
* @property-read positive-int|null $url_metrics_id ID for the od_url_metrics post which provided the URL Metrics in the collection. | ||
* @property-read array<string, mixed> $normalized_query_vars Normalized query vars. | ||
* @property-read non-empty-string $url_metrics_slug Slug for the od_url_metrics post. | ||
* @property-read OD_Link_Collection $link_collection Link collection. | ||
*/ | ||
final class OD_Template_Optimization_Context { | ||
|
||
/** | ||
* URL Metric group collection. | ||
* | ||
* @since n.e.x.t | ||
* @var OD_URL_Metric_Group_Collection | ||
*/ | ||
private $url_metric_group_collection; | ||
|
||
/** | ||
* ID for the od_url_metrics post which provided the URL Metrics in the collection. | ||
* | ||
* May be null if no post has been created yet. | ||
* | ||
* @since n.e.x.t | ||
* @var positive-int|null | ||
*/ | ||
private $url_metrics_id; | ||
|
||
/** | ||
* Normalized query vars. | ||
* | ||
* @since n.e.x.t | ||
* @var array<string, mixed> | ||
*/ | ||
private $normalized_query_vars; | ||
|
||
/** | ||
* Slug for the od_url_metrics post. | ||
* | ||
* @since n.e.x.t | ||
* @var non-empty-string | ||
*/ | ||
private $url_metrics_slug; | ||
|
||
/** | ||
* Link collection. | ||
* | ||
* @since n.e.x.t | ||
* @var OD_Link_Collection | ||
*/ | ||
private $link_collection; | ||
|
||
/** | ||
* Constructor. | ||
* | ||
* @since n.e.x.t | ||
* @access private | ||
* | ||
* @param OD_URL_Metric_Group_Collection $url_metric_group_collection URL Metric group collection. | ||
* @param OD_Link_Collection $link_collection Link collection. | ||
* @param array<string, mixed> $normalized_query_vars Normalized query vars. | ||
* @param non-empty-string $url_metrics_slug Slug for the od_url_metrics post. | ||
* @param positive-int|null $url_metrics_id ID for the od_url_metrics post which provided the URL Metrics in the collection. May be null if no post has been created yet. | ||
*/ | ||
public function __construct( OD_URL_Metric_Group_Collection $url_metric_group_collection, OD_Link_Collection $link_collection, array $normalized_query_vars, string $url_metrics_slug, ?int $url_metrics_id ) { | ||
$this->url_metric_group_collection = $url_metric_group_collection; | ||
$this->link_collection = $link_collection; | ||
$this->normalized_query_vars = $normalized_query_vars; | ||
$this->url_metrics_slug = $url_metrics_slug; | ||
$this->url_metrics_id = $url_metrics_id; | ||
} | ||
|
||
/** | ||
* Gets a property. | ||
* | ||
* @since n.e.x.t | ||
* | ||
* @param string $name Property name. | ||
* @return mixed Property value. | ||
* | ||
* @throws Error When property is unknown. | ||
*/ | ||
public function __get( string $name ) { | ||
// Note: There is intentionally not a 'processor' case to expose $this->processor. | ||
switch ( $name ) { | ||
case 'url_metrics_id': | ||
return $this->url_metrics_id; | ||
case 'url_metric_group_collection': | ||
return $this->url_metric_group_collection; | ||
case 'normalized_query_vars': | ||
return $this->normalized_query_vars; | ||
case 'url_metrics_slug': | ||
return $this->url_metrics_slug; | ||
case 'link_collection': | ||
return $this->link_collection; | ||
default: | ||
throw new Error( | ||
esc_html( | ||
sprintf( | ||
/* translators: %s is class member variable name */ | ||
__( 'Unknown property %s.', 'optimization-detective' ), | ||
__CLASS__ . '::$' . $name | ||
) | ||
) | ||
); | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See #1921