-
Notifications
You must be signed in to change notification settings - Fork 226
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
103 changed files
with
5,727 additions
and
3,767 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
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,59 @@ | ||
<?php | ||
|
||
namespace WP_Rocket\Engine\Debug; | ||
|
||
use WP_Rocket\Event_Management\Subscriber_Interface; | ||
|
||
class DebugSubscriber implements Subscriber_Interface { | ||
|
||
/** | ||
* Returns an array of events this listens to | ||
* | ||
* @return array | ||
*/ | ||
public static function get_subscribed_events(): array { | ||
return [ | ||
'wp_rocket_first_install' => 'on_first_install', | ||
'wp_rocket_upgrade' => [ 'on_upgrade', 10, 2 ], | ||
]; | ||
} | ||
|
||
/** | ||
* Adds the debug option on first install. | ||
* | ||
* @return void | ||
*/ | ||
public function on_first_install(): void { | ||
$this->add_debug_options(); | ||
} | ||
|
||
/** | ||
* Adds the debug option on upgrade. | ||
* | ||
* @param string $new_version New plugin version. | ||
* @param string $old_version Previous plugin version. | ||
* | ||
* @return void | ||
*/ | ||
public function on_upgrade( $new_version, $old_version ): void { | ||
if ( version_compare( $old_version, '3.16', '>=' ) ) { | ||
return; | ||
} | ||
|
||
$this->add_debug_options(); | ||
} | ||
|
||
/** | ||
* Adds the debug option. | ||
* | ||
* @return boolean | ||
*/ | ||
private function add_debug_options(): bool { | ||
return add_option( | ||
'wp_rocket_debug', | ||
[ | ||
'last_rucss_job_added' => '', | ||
] | ||
); | ||
} | ||
} |
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,134 @@ | ||
<?php | ||
|
||
namespace WP_Rocket\Engine\Debug\RUCSS; | ||
|
||
use WP_Rocket\Admin\{Options, Options_Data}; | ||
use WP_Rocket\Event_Management\Subscriber_Interface; | ||
use WP_Rocket\Logger\Logger; | ||
|
||
class Subscriber implements Subscriber_Interface { | ||
|
||
/** | ||
* Plugin options instance. | ||
* | ||
* @var Options_Data | ||
*/ | ||
protected $options; | ||
|
||
/** | ||
* Options instance. | ||
* | ||
* @var Options | ||
*/ | ||
private $options_api; | ||
|
||
/** | ||
* Instantiate the class | ||
* | ||
* @param Options_Data $options Options instance. | ||
* @param Options $options_api Options instance. | ||
*/ | ||
public function __construct( Options_Data $options, Options $options_api ) { | ||
$this->options = $options; | ||
$this->options_api = $options_api; | ||
} | ||
|
||
/** | ||
* Returns an array of events this listens to | ||
* | ||
* @return array | ||
*/ | ||
public static function get_subscribed_events(): array { | ||
return [ | ||
'rocket_last_rucss_job_added_time' => [ 'log_last_added_job_time', 10, 2 ], | ||
'rocket_rucss_process_pending_jobs_start' => [ 'log_process_pending_job_start_time', 10, 1 ], | ||
'rocket_rucss_process_pending_jobs_end' => [ 'log_process_pending_job_end_time', 10, 1 ], | ||
'rocket_rucss_check_job_status_end' => [ 'log_check_job_status_end', 10, 1 ], | ||
'rocket_rucss_process_on_submit_jobs_start' => [ 'log_process_on_submit_start', 10, 1 ], | ||
'rocket_rucss_process_on_submit_jobs_end' => [ 'log_process_on_submit_end', 10, 1 ], | ||
]; | ||
} | ||
|
||
/** | ||
* Saves the last time a new job was added to rucss table. | ||
* | ||
* @param mixed $is_success New job status: ID of inserted row if successfully added; false otherwise. | ||
* @param string $timestamp Current timestamp. | ||
* @return void | ||
*/ | ||
public function log_last_added_job_time( $is_success, $timestamp ) { | ||
if ( Logger::debug_enabled() ) { | ||
if ( ! $is_success ) { | ||
return; | ||
} | ||
|
||
$this->options->set( 'last_rucss_job_added', $timestamp ); | ||
$this->options_api->set( 'debug', $this->options->get_options() ); | ||
} | ||
} | ||
|
||
/** | ||
* Saves the time when the process pending jobs started. | ||
* | ||
* @param string $timestamp Current timestamp. | ||
* @return void | ||
*/ | ||
public function log_process_pending_job_start_time( $timestamp ) { | ||
if ( Logger::debug_enabled() ) { | ||
$this->options->set( 'rucss_process_pending_jobs_start', $timestamp ); | ||
$this->options_api->set( 'debug', $this->options->get_options() ); | ||
} | ||
} | ||
|
||
/** | ||
* Saves the time when the process pending jobs ended. | ||
* | ||
* @param string $timestamp Current timestamp. | ||
* @return void | ||
*/ | ||
public function log_process_pending_job_end_time( $timestamp ) { | ||
if ( Logger::debug_enabled() ) { | ||
$this->options->set( 'rucss_process_pending_jobs_end', $timestamp ); | ||
$this->options_api->set( 'debug', $this->options->get_options() ); | ||
} | ||
} | ||
|
||
/** | ||
* Saves the time when the check job status ended. | ||
* | ||
* @param string $timestamp Current timestamp. | ||
* @return void | ||
*/ | ||
public function log_check_job_status_end( $timestamp ) { | ||
if ( Logger::debug_enabled() ) { | ||
$this->options->set( 'rucss_check_job_status_end', $timestamp ); | ||
$this->options_api->set( 'debug', $this->options->get_options() ); | ||
} | ||
} | ||
|
||
/** | ||
* Saves the time when the process on submit jobs started. | ||
* | ||
* @param string $timestamp Current timestamp. | ||
* @return void | ||
*/ | ||
public function log_process_on_submit_start( $timestamp ) { | ||
if ( Logger::debug_enabled() ) { | ||
$this->options->set( 'rucss_process_on_submit_jobs_start', $timestamp ); | ||
$this->options_api->set( 'debug', $this->options->get_options() ); | ||
} | ||
} | ||
|
||
/** | ||
* Saves the time when the process on submit jobs ended. | ||
* | ||
* @param string $timestamp Current timestamp. | ||
* @return void | ||
*/ | ||
public function log_process_on_submit_end( $timestamp ) { | ||
if ( Logger::debug_enabled() ) { | ||
$this->options->set( 'rucss_process_on_submit_jobs_end', $timestamp ); | ||
$this->options_api->set( 'debug', $this->options->get_options() ); | ||
} | ||
} | ||
} |
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,62 @@ | ||
<?php | ||
|
||
namespace WP_Rocket\Engine\Debug; | ||
|
||
use WP_Rocket\Admin\Options_Data; | ||
|
||
/** | ||
* Resolver. | ||
*/ | ||
class Resolver { | ||
|
||
/** | ||
* Array of WP Rocket Options. | ||
* | ||
* @var array | ||
*/ | ||
private $options_services = [ | ||
'remove_unused_css' => [ | ||
'service' => 'rucss_debug_subscriber', | ||
'class' => 'WP_Rocket\Engine\Debug\RUCSS\Subscriber', | ||
], | ||
]; | ||
|
||
/** | ||
* Debug options instance. | ||
* | ||
* @var Options_Data | ||
*/ | ||
private $options; | ||
|
||
/** | ||
* Instantiate the class. | ||
* | ||
* @param Options_Data $options Options instance. | ||
*/ | ||
public function __construct( Options_Data $options ) { | ||
$this->options = $options; | ||
} | ||
|
||
/** | ||
* Ships an array of available services. | ||
* | ||
* @return array Array of services. | ||
*/ | ||
public function get_services(): array { | ||
$set_services = []; | ||
|
||
if ( empty( $this->options_services ) ) { | ||
return []; | ||
} | ||
|
||
foreach ( $this->options_services as $option => $services ) { | ||
if ( ! (bool) $this->options->get( $option, 0 ) ) { | ||
continue; | ||
} | ||
|
||
$set_services[] = $services; | ||
} | ||
|
||
return $set_services; | ||
} | ||
} |
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,72 @@ | ||
<?php | ||
namespace WP_Rocket\Engine\Debug; | ||
|
||
use WP_Rocket\Dependencies\League\Container\ServiceProvider\AbstractServiceProvider; | ||
use WP_Rocket\Dependencies\League\Container\ServiceProvider\BootableServiceProviderInterface; | ||
use WP_Rocket\Admin\Options_Data; | ||
use WP_Rocket\Engine\Debug\Resolver; | ||
|
||
/** | ||
* Service provider for Debug | ||
*/ | ||
class ServiceProvider extends AbstractServiceProvider implements BootableServiceProviderInterface { | ||
|
||
/** | ||
* 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 = [ | ||
'debug_subscriber', | ||
]; | ||
|
||
/** | ||
* Array of available debug services. | ||
* | ||
* @var array | ||
*/ | ||
protected $services; | ||
|
||
/** | ||
* Register the service in the provider array | ||
* | ||
* @return void | ||
*/ | ||
public function boot() { | ||
$this->services = $this->getContainer()->get( 'debug_resolver' )->get_services(); | ||
|
||
if ( empty( $this->services ) ) { | ||
return; | ||
} | ||
|
||
foreach ( $this->services as $service ) { | ||
$this->provides[] = $service['service']; | ||
} | ||
} | ||
|
||
/** | ||
* Registers items with the container | ||
* | ||
* @return void | ||
*/ | ||
public function register() { | ||
$this->container->add( 'debug_subscriber', DebugSubscriber::class ); | ||
|
||
if ( empty( $this->services ) ) { | ||
return; | ||
} | ||
|
||
$this->container->add( 'options_debug', Options_Data::class ) | ||
->addArgument( $this->container->get( 'options_api' )->get( 'debug', [] ) ); | ||
|
||
foreach ( $this->services as $service ) { | ||
$this->getContainer()->add( $service['service'], $service['class'] ) | ||
->addArgument( $this->getContainer()->get( 'options_debug' ) ) | ||
->addArgument( $this->getContainer()->get( 'options_api' ) ); | ||
} | ||
} | ||
} |
Oops, something went wrong.