Skip to content

Commit

Permalink
Add preload font factory -- :closes: #7246
Browse files Browse the repository at this point in the history
  • Loading branch information
Khadreal committed Feb 11, 2025
1 parent ef601f2 commit 653c3c4
Show file tree
Hide file tree
Showing 3 changed files with 128 additions and 0 deletions.
1 change: 1 addition & 0 deletions inc/Engine/Common/PerformanceHints/ServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ public function register(): void {
$factory_array = [
$this->getContainer()->get( 'atf_factory' ),
$this->getContainer()->get( 'lrc_factory' ),
$this->getContainer()->get( 'preload_fonts_factory' ),
];

foreach ( $factory_array as $factory ) {
Expand Down
116 changes: 116 additions & 0 deletions inc/Engine/Media/PreloadFonts/Factory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
<?php
declare(strict_types=1);

namespace WP_Rocket\Engine\Media\PreloadFonts;

use WP_Rocket\Engine\Common\Context\ContextInterface;
use WP_Rocket\Engine\Common\PerformanceHints\AJAX\ControllerInterface as AjaxControllerInterface;
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 {
/**
* 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 ContextInterface $context LRC Context instance.
* @param TableInterface $table LRC Table instance.
* @param QueriesInterface $queries LRC Queries instance.
* @param AjaxControllerInterface $ajax_controller LRC AJAX Controller instance.
* @param FrontendControllerInterface $frontend_controller LRC Frontend Controller instance.
*/
public function __construct(
ContextInterface $context,
TableInterface $table,
QueriesInterface $queries,
AjaxControllerInterface $ajax_controller,
FrontendControllerInterface $frontend_controller
) {
$this->context = $context;
$this->table = $table;
$this->queries = $queries;
$this->ajax_controller = $ajax_controller;
$this->frontend_controller = $frontend_controller;
}

/**
* Ajax controller object.
*
* @return AjaxControllerInterface
*/
public function get_ajax_controller(): AjaxControllerInterface {
return $this->ajax_controller;
}

/**
* Frontend controller object.
*
* @return FrontendControllerInterface
*/
public function get_frontend_controller(): FrontendControllerInterface {
return $this->frontend_controller;
}

/**
* Provides a Table object.
*
* @return TableInterface
*/
public function table(): TableInterface {
return $this->table;
}

/**
* Provide Queries object.
*
* @return QueriesInterface
*/
public function queries(): QueriesInterface {
return $this->queries;
}

/**
* Provide context interface.
*
* @return ContextInterface
*/
public function get_context(): ContextInterface {
return $this->context;
}
}
11 changes: 11 additions & 0 deletions inc/Engine/Media/PreloadFonts/ServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,5 +63,16 @@ public function register(): void {
);

$this->getContainer()->addShared( 'preload_fonts_frontend_subscriber', FrontendSubscriber::class );

$this->getContainer()->addShared( 'preload_fonts_factory', Factory::class )
->addArguments(
[
$this->getContainer()->get( 'preload_fonts_ajax_controller' ),
'',
$this->getContainer()->get( 'preload_fonts_table' ),
$this->getContainer()->get( 'preload_fonts_query' ),
$this->getContainer()->get( 'preload_fonts_context' ),
]
);
}
}

0 comments on commit 653c3c4

Please sign in to comment.