Completed
Push — master ( 7381e1...0d723c )
by Korvin
02:16
created

ServiceProvider   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 5

Importance

Changes 0
Metric Value
dl 0
loc 30
c 0
b 0
f 0
wmc 1
lcom 0
cbo 5
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A register() 0 14 1
1
<?php
2
3
namespace Buttress\Concrete\Client;
4
5
use Buttress\Concrete\Client\Adapter\Adapter;
6
use Buttress\Concrete\Client\Adapter\AdapterFactory;
7
use Buttress\Concrete\Client\Adapter\LegacyAdapter;
8
use Buttress\Concrete\Client\Adapter\ModernAdapter;
9
use Buttress\Concrete\Client\Connection\Connection;
10
use Buttress\Concrete\Locator\Site;
11
use League\Container\ServiceProvider\AbstractServiceProvider;
12
13
class ServiceProvider extends AbstractServiceProvider
14
{
15
16
    protected $provides = [
17
        Adapter::class,
18
        Connection::class
19
    ];
20
21
    /**
22
     * Use the register method to register items with the container via the
23
     * protected $this->container property or the `getContainer` method
24
     * from the ContainerAwareTrait.
25
     *
26
     * @return void
27
     */
28
    public function register()
29
    {
30
        $container = $this->getContainer();
31
32
        // Get the adapter instance from the factory
33
        $container->add(Adapter::class, function(AdapterFactory $factory, Site $site) {
34
            return $factory->fromSite($site);
35
        })->withArgument(AdapterFactory::class)->withArgument(Site::class);
36
37
        // Connect to concrete5
38
        $container->add(Connection::class, function(Concrete5 $client) {
39
            return $client->connect();
40
        })->withArgument(Concrete5::class);
41
    }
42
}
43