-
Notifications
You must be signed in to change notification settings - Fork 227
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Closes #7246 3.19 - Preconnect to external domains - Beacon insertion…
… part (#7301)
- Loading branch information
Showing
15 changed files
with
373 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace WP_Rocket\Engine\Common\PerformanceHints\Cron; | ||
|
||
trait CronTrait { | ||
/** | ||
* Performance Hints Deletion interval filter. | ||
* | ||
* @param string $filter_name The filter name. | ||
* | ||
* @return object | ||
*/ | ||
public function deletion_interval( string $filter_name ): object { | ||
/** | ||
* Filters the interval (in months) to determine when a performance data entry is considered 'old'. | ||
* Old performance entries are eligible for deletion. By default, a performance entry is considered old if it hasn't been accessed in the last month. | ||
* | ||
* @param int $delete_interval The interval in months after which a performance data entry is considered old. Default is 1 month. | ||
*/ | ||
$delete_interval = wpm_apply_filters_typed( 'integer', $filter_name, 1 ); | ||
if ( $delete_interval <= 0 ) { | ||
return $this->queries; | ||
} | ||
|
||
return $this->queries->set_cleanup_interval( $delete_interval ); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace WP_Rocket\Engine\Media\PreconnectExternalDomains; | ||
|
||
use WP_Rocket\Engine\Common\Context\ContextInterface; | ||
use WP_Rocket\Engine\Common\PerformanceHints\AJAX\ControllerInterface as AjaxControllerInterface; | ||
use WP_Rocket\Engine\Common\PerformanceHints\Cron\CronTrait; | ||
use WP_Rocket\Engine\Common\PerformanceHints\Database\Queries\QueriesInterface; | ||
use WP_Rocket\Engine\Common\PerformanceHints\Database\Table\TableInterface; | ||
use WP_Rocket\Engine\Common\PerformanceHints\FactoryInterface; | ||
use WP_Rocket\Engine\Common\PerformanceHints\Frontend\ControllerInterface as FrontendControllerInterface; | ||
|
||
class Factory implements FactoryInterface { | ||
use CronTrait; | ||
|
||
/** | ||
* Ajax Controller instance. | ||
* | ||
* @var AjaxControllerInterface | ||
*/ | ||
protected $ajax_controller; | ||
|
||
/** | ||
* Frontend Controller instance. | ||
* | ||
* @var FrontendControllerInterface | ||
*/ | ||
protected $frontend_controller; | ||
|
||
/** | ||
* Table instance. | ||
* | ||
* @var TableInterface | ||
*/ | ||
protected $table; | ||
|
||
/** | ||
* Queries instance. | ||
* | ||
* @var QueriesInterface | ||
*/ | ||
protected $queries; | ||
|
||
/** | ||
* Context instance. | ||
* | ||
* @var ContextInterface | ||
*/ | ||
protected $context; | ||
|
||
/** | ||
* Instantiate the class. | ||
* | ||
* @param QueriesInterface $queries Preconnect external domains Queries instance. | ||
* @param ContextInterface $context Preconnect external domains Context instance. | ||
* @param AjaxControllerInterface $ajax_controller Preconnect external domains AJAX Controller instance. | ||
* @param TableInterface $table Preconnect external domains Table instance. | ||
* @param FrontendControllerInterface $frontend_controller Preconnect external domains Frontend Controller instance. | ||
*/ | ||
public function __construct( | ||
QueriesInterface $queries, | ||
ContextInterface $context, | ||
AjaxControllerInterface $ajax_controller, | ||
TableInterface $table, | ||
FrontendControllerInterface $frontend_controller | ||
) { | ||
$this->context = $context; | ||
$this->queries = $queries; | ||
$this->table = $table; | ||
$this->ajax_controller = $ajax_controller; | ||
$this->frontend_controller = $frontend_controller; | ||
} | ||
|
||
/** | ||
* Provides an Ajax controller object. | ||
* | ||
* @return AjaxControllerInterface | ||
*/ | ||
public function get_ajax_controller(): AjaxControllerInterface { | ||
return $this->ajax_controller; | ||
} | ||
|
||
/** | ||
* Provides a Frontend controller object. | ||
* | ||
* @return FrontendControllerInterface | ||
*/ | ||
public function get_frontend_controller(): FrontendControllerInterface { | ||
return $this->frontend_controller; | ||
} | ||
|
||
/** | ||
* Provides a Table interface object. | ||
* | ||
* @return TableInterface | ||
*/ | ||
public function table(): TableInterface { | ||
return $this->table; | ||
} | ||
|
||
/** | ||
* Provides a Queries object. | ||
* | ||
* @return QueriesInterface | ||
*/ | ||
public function queries(): QueriesInterface { | ||
// Defines the interval for deletion and returns Queries object. | ||
return $this->deletion_interval( 'rocket_preconnect_external_domains_cleanup_interval' ); | ||
} | ||
|
||
/** | ||
* Provides Context object. | ||
* | ||
* @return ContextInterface | ||
*/ | ||
public function get_context(): ContextInterface { | ||
return $this->context; | ||
} | ||
} |
71 changes: 71 additions & 0 deletions
71
inc/Engine/Media/PreconnectExternalDomains/Frontend/Controller.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace WP_Rocket\Engine\Media\PreconnectExternalDomains\Frontend; | ||
|
||
use WP_Rocket\Admin\Options_Data; | ||
use WP_Rocket\Engine\Common\PerformanceHints\Frontend\ControllerInterface; | ||
use WP_Rocket\Engine\Media\PreconnectExternalDomains\Context\Context; | ||
use WP_Rocket\Engine\Media\PreconnectExternalDomains\Database\Queries\PreconnectExternalDomains as PreconnectDomains; | ||
|
||
class Controller implements ControllerInterface { | ||
/** | ||
* Options instance | ||
* | ||
* @var Options_Data | ||
*/ | ||
private $options; // @phpstan-ignore-line Use of this will come later. | ||
|
||
/** | ||
* Queries instance | ||
* | ||
* @var PreconnectDomains | ||
*/ | ||
private $query; // @phpstan-ignore-line Use of this will come later. | ||
|
||
/** | ||
* Context instance. | ||
* | ||
* @var Context | ||
*/ | ||
private $context; // @phpstan-ignore-line Use of this will come later. | ||
|
||
/** | ||
* Constructor | ||
* | ||
* @param Options_Data $options Options instance. | ||
* @param PreconnectDomains $query Queries instance. | ||
* @param Context $context Context instance. | ||
*/ | ||
public function __construct( Options_Data $options, PreconnectDomains $query, Context $context ) { | ||
$this->options = $options; | ||
$this->query = $query; | ||
$this->context = $context; | ||
} | ||
|
||
/** | ||
* Applies preconnect domains optimization. | ||
* | ||
* @param string $html HTML content. | ||
* @param object $row Database row. | ||
* @return string | ||
*/ | ||
public function optimize( string $html, $row ): string { | ||
if ( ! $row->has_preconnect_external_domains() ) { | ||
return $html; | ||
} | ||
|
||
return $html; | ||
} | ||
|
||
/** | ||
* Add custom data like the List of elements to be considered for optimization. | ||
* | ||
* @param array $data Array of data passed in beacon. | ||
* | ||
* @return array | ||
*/ | ||
public function add_custom_data( array $data ): array { | ||
return $data; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.