1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Coco\SourceWatcher\Core; |
4
|
|
|
|
5
|
|
|
use Coco\SourceWatcher\Core\IO\Inputs\Input; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* Class SourceWatcher |
9
|
|
|
* @package Coco\SourceWatcher\Core |
10
|
|
|
*/ |
11
|
|
|
class SourceWatcher |
12
|
|
|
{ |
13
|
|
|
private StepLoader $stepLoader; |
14
|
|
|
|
15
|
|
|
private Pipeline $pipeline; |
16
|
|
|
|
17
|
|
|
public function __construct () |
18
|
|
|
{ |
19
|
|
|
$this->stepLoader = new StepLoader(); |
20
|
|
|
$this->pipeline = new Pipeline(); |
21
|
|
|
} |
22
|
|
|
|
23
|
|
|
public function extract ( string $extractorName, Input $input, array $options = [] ) : SourceWatcher |
24
|
|
|
{ |
25
|
|
|
try { |
26
|
|
|
$extractor = $this->stepLoader->getStep( Extractor::class, $extractorName ); |
27
|
|
|
$extractor->setInput( $input ); |
|
|
|
|
28
|
|
|
$extractor->options( $options ); |
29
|
|
|
|
30
|
|
|
$this->pipeline->setExtractor( $extractor ); |
|
|
|
|
31
|
|
|
} catch ( SourceWatcherException $sourceWatcherException ) { |
|
|
|
|
32
|
|
|
|
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
return $this; |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
public function transform ( string $transformerName, array $options = [] ) : SourceWatcher |
39
|
|
|
{ |
40
|
|
|
try { |
41
|
|
|
$transformer = $this->stepLoader->getStep( Transformer::class, $transformerName ); |
42
|
|
|
$transformer->options( $options ); |
43
|
|
|
|
44
|
|
|
$this->pipeline->pipe( $transformer ); |
|
|
|
|
45
|
|
|
} catch ( SourceWatcherException $sourceWatcherException ) { |
|
|
|
|
46
|
|
|
|
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
return $this; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
public function load ( string $loaderName, $output, $options = [] ) : SourceWatcher |
53
|
|
|
{ |
54
|
|
|
try { |
55
|
|
|
$loader = $this->stepLoader->getStep( Loader::class, $loaderName ); |
56
|
|
|
$loader->setOutput( $output ); |
|
|
|
|
57
|
|
|
$loader->options( $options ); |
58
|
|
|
|
59
|
|
|
$this->pipeline->pipe( $loader ); |
|
|
|
|
60
|
|
|
} catch ( SourceWatcherException $sourceWatcherException ) { |
|
|
|
|
61
|
|
|
|
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
return $this; |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
public function run () : void |
68
|
|
|
{ |
69
|
|
|
$this->pipeline->execute(); |
70
|
|
|
} |
71
|
|
|
} |
72
|
|
|
|