Completed
Push — master ( c291b9...165178 )
by Ron
01:19
created

SqliteBuilder::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
namespace Kir\Services\Cmd\Dispatcher\Builder;
3
4
use Ioc\MethodInvoker;
5
use Kir\Services\Cmd\Dispatcher\AttributeRepositories\SqliteAttributeRepository;
6
use Kir\Services\Cmd\Dispatcher\Dispatchers\DefaultDispatcher;
7
use PDO;
8
9
class SqliteBuilder {
10
	/** @var string */
11
	private $filename;
12
	/** @var MethodInvoker|null */
13
	private $methodInvoker;
14
	
15
	/**
16
	 * @param string $filename
17
	 */
18
	public function __construct(string $filename) {
19
		$this->filename = $filename;
20
	}
21
	
22
	/**
23
	 * This can be used to enable automatic provisioning of DI objects when service methods are called. (Autowiring)
24
	 *
25
	 * @param MethodInvoker|null $methodInvoker
26
	 * @return $this
27
	 */
28
	public function setMethodInvoker(MethodInvoker $methodInvoker = null): self {
29
		$this->methodInvoker = $methodInvoker;
30
		return $this;
31
	}
32
	
33
	/**
34
	 * @return DefaultDispatcher
35
	 */
36
	public function build(): DefaultDispatcher {
37
		$pdo = new PDO(sprintf('sqlite:%s', $this->filename));
38
		$repos = new SqliteAttributeRepository($pdo);
39
		return new DefaultDispatcher($repos, $this->methodInvoker);
40
	}
41
}