-
Notifications
You must be signed in to change notification settings - Fork 228
/
Copy pathServiceProvider.php
79 lines (67 loc) · 1.8 KB
/
ServiceProvider.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
<?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',
'options_debug',
];
/**
* 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' ) );
}
}
}