Closed mostafa-hisham closed 2 weeks ago
Yes
This happens because options_debug
is always added to the provides
array of the service provider, but there is an early bail-out in the register()
method, so it's creating the error.
The options_debug
value should be added to the provides
array only if there is a service registered, so instead of adding it directly to the array, it should be conditionally added in the boot()
method, like for the services.
Effort XS
Looks good to me
@mostafa-hisham I'm getting the error, this is after adding options_debug to boot()
. Any idea why this might be happening ?
Fatal error: Uncaught TypeError: WPRocket\RUCSSDebugTool\Admin\Jobs\Subscriber::__construct(): Argument #1 ($query) must be of type WP_Rocket\Engine\Optimization\RUCSS\Database\Queries\UsedCSS, string given in /var/www/html/wp-content/plugins/rucss/inc/Admin/Jobs/Subscriber.php on line 35 TypeError: WPRocket\RUCSSDebugTool\Admin\Jobs\Subscriber::__construct(): Argument #1 ($query) must be of type WP_Rocket\Engine\Optimization\RUCSS\Database\Queries\UsedCSS, string given in /var/www/html/wp-content/plugins/rucss/inc/Admin/Jobs/Subscriber.php on line 35 Call Stack: 0.0009 481856 1. {main}() /var/www/html/wp-admin/plugins.php:0 0.0015 488224 2. require_once('/var/www/html/wp-admin/admin.php') /var/www/html/wp-admin/plugins.php:10 0.0018 488736 3. require_once('/var/www/html/wp-load.php') /var/www/html/wp-admin/admin.php:34 0.0022 489544 4. require_once('/var/www/html/wp-config.php') /var/www/html/wp-load.php:50 0.0041 586456 5. require_once('/var/www/html/wp-settings.php') /var/www/html/wp-config.php:260 0.1486 2049176 6. do_action($hook_name = 'plugins_loaded') /var/www/html/wp-settings.php:555 0.1486 2049392 7. WP_Hook->do_action($args = [0 => '']) /var/www/html/wp-includes/plugin.php:517 0.1486 2049392 8. WP_Hook->apply_filters($value = '', $args = [0 => '']) /var/www/html/wp-includes/class-wp-hook.php:348 0.2084 2273848 9. rocket_init('') /var/www/html/wp-includes/class-wp-hook.php:324 0.4330 3541208 10. do_action($hook_name = 'wp_rocket_loaded') /var/www/html/wp-content/plugins/wp-rocket/inc/main.php:102 0.4330 3541424 11. WP_Hook->do_action($args = [0 => '']) /var/www/html/wp-includes/plugin.php:517 0.4330 3541424 12. WP_Hook->apply_filters($value = '', $args = [0 => '']) /var/www/html/wp-includes/class-wp-hook.php:348 0.4330 3541856 13. WPRocket\RUCSSDebugTool\init('') /var/www/html/wp-includes/class-wp-hook.php:324 0.4406 3585696 14. WP_Rocket\Dependencies\League\Container\Container->get($id = 'WPRocket\\RUCSSDebugTool\\Admin\\Jobs\\Subscriber') /var/www/html/wp-content/plugins/rucss/inc/main.php:27 0.4406 3585696 15. WP_Rocket\Dependencies\League\Container\Container->resolve($id = 'WPRocket\\RUCSSDebugTool\\Admin\\Jobs\\Subscriber', $new = ???) /var/www/html/wp-content/plugins/wp-rocket/inc/Dependencies/League/Container/Container.php:118 0.4412 3585696 16. WP_Rocket\Dependencies\League\Container\ReflectionContainer->get($id = 'WPRocket\\RUCSSDebugTool\\Admin\\Jobs\\Subscriber', $args = ???) /var/www/html/wp-content/plugins/wp-rocket/inc/Dependencies/League/Container/Container.php:203 0.4422 3586312 17. ReflectionClass->newInstanceArgs($args = [0 => 'rucss_used_css_query', 1 => class WPRocket\RUCSSDebugTool\Admin\Common\Renderer { protected $template_basepath = '/var/www/html/wp-content/plugins/rucss/configs/../templates/' }, 2 => class WP_Rocket\Logger\Logger { }]) /var/www/html/wp-content/plugins/rucss/vendor/wp-media/wp-rocket/inc/Dependencies/League/Container/ReflectionContainer.php:58 0.4422 3586440 18. WPRocket\RUCSSDebugTool\Admin\Jobs\Subscriber->__construct($query = 'rucss_used_css_query', $renderer = class WPRocket\RUCSSDebugTool\Admin\Common\Renderer { protected $template_basepath = '/var/www/html/wp-content/plugins/rucss/configs/../templates/' }, $logger = class WP_Rocket\Logger\Logger { }) /var/www/html/wp-content/plugins/rucss/vendor/wp-media/wp-rocket/inc/Dependencies/League/Container/ReflectionContainer.php:58
@Khadreal this means that the class WP_Rocket\Engine\Optimization\RUCSS\Database\Queries\UsedCSS
is not defined on the container.
@CrochetFeve0251 yes, but the class is defined. Could it be because this class WPRocket\RUCSSDebugTool\Admin\Jobs\Subscriber::class
is not defined in the configs/binding file
[Update]
I added WPRocket\RUCSSDebugTool\Admin\Jobs\Subscriber::class
to the container with the arguments and it doesn't throw any error.
@Khadreal I think there is something weird going on with the parameters given.
Some get
on the container have two parameters, and we are fetching the parameter before passing it to the definition, which is also necessary.
Will be tested by Service team: https://github.com/wp-media/rucss-debug-tool/pull/16
Before submitting an issue please check that you’ve completed the following steps:
Describe the bug After updating the container to V4, we cannot use
options_debug
in Rucss debug tool.we are getting this error
With @CrochetFeve0251 help we checked and in wp-rocket we are bailing out here and we don't serve it
To Reproduce Steps to reproduce the behavior:
Expected behavior We should use the
options_debug
like this$container->get('options_debug' ),
Screenshots