-
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.
:feat: Add factory class for service provider :closes: #7246
- Loading branch information
Showing
5 changed files
with
218 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
76 changes: 76 additions & 0 deletions
76
inc/Engine/Media/PreconnectExternalDomains/Database/Queries/PreconnectExternalDomains.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,76 @@ | ||
<?php | ||
declare(strict_types=1); | ||
namespace WP_Rocket\Engine\Media\PreconnectExternalDomains\Database\Queries; | ||
|
||
use WP_Rocket\Engine\Common\PerformanceHints\Database\Queries\AbstractQueries; | ||
use WP_Rocket\Engine\Common\PerformanceHints\Database\Queries\QueriesInterface; | ||
|
||
class PreconnectExternalDomains extends AbstractQueries implements QueriesInterface { | ||
|
||
/** | ||
* Name of the database table to query. | ||
* | ||
* @var string | ||
*/ | ||
protected $table_name = 'wpr_preconnect_external_domains'; | ||
|
||
/** | ||
* String used to alias the database table in MySQL statement. | ||
* | ||
* Keep this short, but descriptive. I.E. "tr" for term relationships. | ||
* | ||
* This is used to avoid collisions with JOINs. | ||
* | ||
* @var string | ||
*/ | ||
protected $table_alias = 'wpr_pre'; | ||
|
||
/** | ||
* Name of class used to setup the database schema. | ||
* | ||
* @var string | ||
*/ | ||
protected $table_schema = ''; | ||
|
||
/** Item ******************************************************************/ | ||
|
||
/** | ||
* Name for a single item. | ||
* | ||
* Use underscores between words. I.E. "term_relationship" | ||
* | ||
* This is used to automatically generate action hooks. | ||
* | ||
* @var string | ||
*/ | ||
protected $item_name = 'above_the_fold'; | ||
|
||
/** | ||
* Plural version for a group of items. | ||
* | ||
* Use underscores between words. I.E. "term_relationships" | ||
* | ||
* This is used to automatically generate action hooks. | ||
* | ||
* @var string | ||
*/ | ||
protected $item_name_plural = 'external_preconnect_domains'; | ||
|
||
/** | ||
* Name of class used to turn IDs into first-class objects. | ||
* | ||
* This is used when looping through return values to guarantee their shape. | ||
* | ||
* @var mixed | ||
*/ | ||
protected $item_shape = ''; | ||
|
||
/** | ||
* Delete all rows which were not accessed in the last month. | ||
* | ||
* @return bool|int | ||
*/ | ||
public function delete_old_rows() { | ||
return false; | ||
} | ||
} |
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,94 @@ | ||
<?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; | ||
|
||
|
||
/** | ||
* 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; | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
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,45 @@ | ||
<?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\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', | ||
]; | ||
|
||
/** | ||
* 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()->addShared( 'preconnect_factory', Factory::class ); | ||
} | ||
} |
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