ServiceProvider.php
1.2 KB
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
<?php
namespace WP_Rocket\ThirdParty\Hostings;
use WP_Rocket\Dependencies\League\Container\ServiceProvider\AbstractServiceProvider;
use WP_Rocket\Dependencies\League\Container\ServiceProvider\BootableServiceProviderInterface;
use WP_Rocket\ThirdParty\Hostings\HostResolver;
use WP_Rocket\ThirdParty\Hostings\HostSubscriberFactory;
/**
* Hostings compatibility service provider
*
* @since 3.6.3
*/
class ServiceProvider extends AbstractServiceProvider implements BootableServiceProviderInterface {
/**
* Services provided
*
* @var array
*/
protected $provides = [];
/**
* Register the service in the provider array
*
* @return void
*/
public function boot() {
$hosting_service = HostResolver::get_host_service();
if ( ! empty( $hosting_service ) ) {
$this->provides[] = $hosting_service;
}
}
/**
* Registers the current hosting subscriber in the container
*
* @since 3.6.3
*
* @return void
*/
public function register() {
$hosting_service = HostResolver::get_host_service();
if ( ! empty( $hosting_service ) ) {
$this->getContainer()
->share( $hosting_service, ( new HostSubscriberFactory() )->get_subscriber() )
->addTag( 'hosting_subscriber' );
}
}
}