|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace kalanis\kw_mapper\Search\Connector; |
|
4
|
|
|
|
|
5
|
|
|
|
|
6
|
|
|
use kalanis\kw_mapper\MapperException; |
|
7
|
|
|
use kalanis\kw_mapper\Mappers; |
|
8
|
|
|
use kalanis\kw_mapper\Records\ARecord; |
|
9
|
|
|
|
|
10
|
|
|
|
|
11
|
|
|
/** |
|
12
|
|
|
* Class Factory |
|
13
|
|
|
* @package kalanis\kw_mapper\Search |
|
14
|
|
|
* Complex searching - factory for access correct connecting classes |
|
15
|
|
|
*/ |
|
16
|
|
|
class Factory |
|
17
|
|
|
{ |
|
18
|
31 |
|
public static function getInstance(): self |
|
19
|
|
|
{ |
|
20
|
31 |
|
return new self(); |
|
21
|
|
|
} |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* @param ARecord $record |
|
25
|
|
|
* @param ARecord[] $initialRecords |
|
26
|
|
|
* @throws MapperException |
|
27
|
|
|
* @return AConnector |
|
28
|
|
|
*/ |
|
29
|
31 |
|
public function getConnector(ARecord $record, array $initialRecords = []): AConnector |
|
30
|
|
|
{ |
|
31
|
31 |
|
$mapper = $record->getMapper(); |
|
32
|
31 |
|
if ($mapper instanceof Mappers\Database\ADatabase) { |
|
33
|
10 |
|
return new Database($record); |
|
34
|
21 |
|
} elseif ($mapper instanceof Mappers\Database\ALdap) { |
|
35
|
|
|
// @codeCoverageIgnoreStart |
|
36
|
|
|
return new Ldap($record); |
|
37
|
|
|
// @codeCoverageIgnoreEnd |
|
38
|
21 |
|
} elseif ($mapper instanceof Mappers\Database\WinRegistry) { |
|
39
|
|
|
// @codeCoverageIgnoreStart |
|
40
|
|
|
return new WinRegistry($record); |
|
41
|
|
|
// @codeCoverageIgnoreEnd |
|
42
|
21 |
|
} elseif ($mapper instanceof Mappers\File\ATable) { |
|
43
|
18 |
|
return new FileTable($record); |
|
44
|
3 |
|
} elseif ($mapper instanceof Mappers\APreset) { |
|
45
|
1 |
|
return new FileTable($record); |
|
46
|
2 |
|
} elseif (!empty($initialRecords)) { |
|
47
|
1 |
|
$records = new Records($record); |
|
48
|
1 |
|
$records->setInitialRecords($initialRecords); |
|
49
|
1 |
|
return $records; |
|
50
|
|
|
} else { |
|
51
|
1 |
|
throw new MapperException('Invalid mapper for Search.'); |
|
52
|
|
|
} |
|
53
|
|
|
} |
|
54
|
|
|
} |
|
55
|
|
|
|