-
Notifications
You must be signed in to change notification settings - Fork 228
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
215 additions
and
0 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
46 changes: 46 additions & 0 deletions
46
inc/Engine/Media/PreconnectExternalDomains/Context/Context.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,46 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace WP_Rocket\Engine\Media\PreconnectExternalDomains\Context; | ||
|
||
use WP_Rocket\Admin\Options_Data; | ||
use WP_Rocket\Engine\Common\Context\ContextInterface; | ||
|
||
class Context implements ContextInterface { | ||
|
||
/** | ||
* Options instance | ||
* | ||
* @var Options_Data | ||
*/ | ||
private $options; | ||
|
||
|
||
/** | ||
* Constructor | ||
* | ||
* @param Options_Data $options Options instance. | ||
*/ | ||
public function __construct( Options_Data $options ) { | ||
$this->options = $options; | ||
} | ||
|
||
/** | ||
* Determine if the action is allowed. | ||
* | ||
* @param array $data Data to pass to the context. | ||
* @return bool | ||
*/ | ||
public function is_allowed( array $data = [] ): bool { | ||
if ( $this->options->get( 'wp_rocket_no_licence', 0 ) ) { | ||
return false; | ||
} | ||
|
||
/** | ||
* Filters to manage above the fold optimization | ||
* | ||
* @param bool $allow True to allow, false otherwise. | ||
*/ | ||
return wpm_apply_filters_typed( 'boolean', 'rocket_preconnect_external_domains_optimization', true ); | ||
} | ||
} |
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,104 @@ | ||
<?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\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 QueriesInterface $queries Preconnect external domains Queries instance. | ||
* @param ContextInterface $context Preconnect external domains Context instance. | ||
*/ | ||
public function __construct( QueriesInterface $queries, ContextInterface $context ) { | ||
$this->context = $context; | ||
$this->queries = $queries; | ||
} | ||
|
||
/** | ||
* 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 { | ||
return $this->queries; | ||
} | ||
|
||
/** | ||
* Provides Context object. | ||
* | ||
* @return ContextInterface | ||
*/ | ||
public function get_context(): ContextInterface { | ||
return $this->context; | ||
} | ||
} |
58 changes: 58 additions & 0 deletions
58
inc/Engine/Media/PreconnectExternalDomains/ServiceProvider.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,58 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace WP_Rocket\Engine\Media\PreconnectExternalDomains; | ||
|
||
use WP_Rocket\Dependencies\League\Container\ServiceProvider\AbstractServiceProvider; | ||
use WP_Rocket\Engine\Media\PreconnectExternalDomains\Context\Context; | ||
use WP_Rocket\Engine\Media\PreconnectExternalDomains\Database\Queries\PreconnectExternalDomains as Query; | ||
|
||
class ServiceProvider extends AbstractServiceProvider { | ||
/** | ||
* The provides array is a way to let the container | ||
* know that a service is provided by this service | ||
* provider. Every service that is registered via | ||
* this service provider must have an alias added | ||
* to this array or it will be ignored. | ||
* | ||
* @var array | ||
*/ | ||
protected $provides = [ | ||
'preconnect_factory', | ||
'preconnect_query', | ||
'preconnect_context', | ||
]; | ||
|
||
/** | ||
* Check if the service provider provides a specific service. | ||
* | ||
* @param string $id The id of the service. | ||
* | ||
* @return bool | ||
*/ | ||
public function provides( string $id ): bool { | ||
return in_array( $id, $this->provides, true ); | ||
} | ||
|
||
|
||
/** | ||
* Registers the classes in the container | ||
* | ||
* @return void | ||
*/ | ||
public function register(): void { | ||
$this->getContainer()->add( 'preconnect_query', Query::class ); | ||
$this->getContainer()->add( 'preconnect_context', Context::class ) | ||
->addArgument( | ||
$this->getContainer()->get( 'options' ) | ||
); | ||
|
||
$this->getContainer()->addShared( 'preconnect_factory', Factory::class ) | ||
->addArguments( | ||
[ | ||
$this->getContainer()->get( 'preconnect_query' ), | ||
$this->getContainer()->get( 'preconnect_context' ), | ||
] | ||
); | ||
} | ||
} |
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