-
Notifications
You must be signed in to change notification settings - Fork 227
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixes #6865 Container V4 service provider error about providing (options_debug) service #6902
Fixes #6865 Container V4 service provider error about providing (options_debug) service #6902
Conversation
Coverage summary from CodacySee diff coverage on Codacy
Coverage variation details
Coverage variation is the difference between the coverage for the head and common ancestor commits of the pull request branch: Diff coverage details
Diff coverage is the percentage of lines that are covered by tests out of the coverable lines that the pull request added or modified: See your quality gate settings Change summary preferencesCodacy stopped sending the deprecated coverage status on June 5th, 2024. Learn more Footnotes
|
hmmm I don't really get the solution provided on this branch as it doesn't seem to match what was said during grooming. Instead, doing this would fix the issue and match the grooming: <?php
namespace WP_Rocket\Engine\Debug;
use WP_Rocket\Dependencies\League\Container\ServiceProvider\{AbstractServiceProvider, BootableServiceProviderInterface};
use WP_Rocket\Admin\Options_Data;
/**
* Service provider for Debug
*/
class ServiceProvider extends AbstractServiceProvider implements BootableServiceProviderInterface {
/**
* Array of services provided by this service provider
*
* @var array
*/
protected $provides = [
'debug_subscriber',
];
/**
* Array of available debug services.
*
* @var array
*/
protected $services = [];
/**
* 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 );
}
/**
* Register the service in the provider array
*
* @return void
*/
public function boot(): void {
$this->services = $this->getContainer()->get( 'debug_resolver' )->get_services();
if ( empty( $this->services ) ) {
return;
}
$this->provides []= 'options_debug';
foreach ( $this->services as $service ) {
$this->provides[] = $service['service'];
}
}
/**
* Registers items with the container
*
* @return void
*/
public function register(): void {
$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' ) );
}
}
} |
@Khadreal |
…-container-v4-service-provider
I just pushed the change showed by @mostafa-hisham. |
Tested with the RUCSS Debug tool and working fine. |
Description
Fixes #6865
Documentation
User documentation
No impact.
Technical documentation
Add
options_debug
directly to theboot
method since it doesn't have a service registered.Type of change
Detailed scenario
Check issue #6865 for detailed scenario
Documentation
Fix service provider error for container without a registered service
Mandatory Checklist
Code validation
Documentation
Code style