1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Oliverde8\Component\PhpEtl\Builder\Factories; |
4
|
|
|
|
5
|
|
|
use Oliverde8\Component\PhpEtl\ChainOperation\ChainOperationInterface; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* Class AbstractFactory |
9
|
|
|
* |
10
|
|
|
* @author de Cramer Oliver<[email protected]> |
11
|
|
|
* @copyright 2018 Oliverde8 |
12
|
|
|
* @package Oliverde8\Component\PhpEtl\Builder\Factories |
13
|
|
|
*/ |
14
|
|
|
abstract class AbstractFactory |
15
|
|
|
{ |
16
|
|
|
/** @var string The operation type */ |
17
|
|
|
protected $operation; |
18
|
|
|
|
19
|
|
|
/** @var string Class to built */ |
20
|
|
|
protected $class; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* AbstractFactory constructor. |
24
|
|
|
* |
25
|
|
|
* @param string $operation |
26
|
|
|
* @param string $class |
27
|
|
|
*/ |
28
|
|
|
public function __construct($operation, $class) |
29
|
|
|
{ |
30
|
|
|
$this->operation = $operation; |
31
|
|
|
$this->class = $class; |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* Validate and Build an operation of a certain type with the options. |
36
|
|
|
* |
37
|
|
|
* @param String $operation |
38
|
|
|
* @param array $options |
39
|
|
|
* |
40
|
|
|
* @return ChainOperationInterface |
41
|
|
|
*/ |
42
|
|
|
public function getOperation($operation, $options) |
43
|
|
|
{ |
44
|
|
|
$this->validateOptions($this, $options); |
45
|
|
|
return $this->build($operation, $options); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* Build an operation of a certain type with the options. |
50
|
|
|
* |
51
|
|
|
* @param String $operation |
52
|
|
|
* @param array $options |
53
|
|
|
* |
54
|
|
|
* @return ChainOperationInterface |
55
|
|
|
*/ |
56
|
|
|
abstract protected function build($type, $options); |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* Create the operation object. |
60
|
|
|
* |
61
|
|
|
* @param array ...$arguments |
62
|
|
|
* |
63
|
|
|
* @return ChainOperationInterface |
64
|
|
|
*/ |
65
|
|
|
protected function create(...$arguments) |
66
|
|
|
{ |
67
|
|
|
$class = $this->class; |
68
|
|
|
return new $class(...$arguments); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* Validate the options. |
73
|
|
|
* |
74
|
|
|
* @param $operation |
75
|
|
|
* @param $options |
76
|
|
|
*/ |
77
|
|
|
protected function validateOptions($operation, $options) |
|
|
|
|
78
|
|
|
{ |
79
|
|
|
// Does nothing for not. TODO validation. |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* Check if the factory supports this operation declaration. |
84
|
|
|
* |
85
|
|
|
* @param $operation |
86
|
|
|
* @param $options |
87
|
|
|
* |
88
|
|
|
* @return bool |
89
|
|
|
*/ |
90
|
|
|
public function supports($operation, $options) |
|
|
|
|
91
|
|
|
{ |
92
|
|
|
return $this->operation == $operation; |
93
|
|
|
} |
94
|
|
|
} |
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.