1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* This file is part of graze/data-flow |
4
|
|
|
* |
5
|
|
|
* Copyright (c) 2016 Nature Delivered Ltd. <https://www.graze.com> |
6
|
|
|
* |
7
|
|
|
* For the full copyright and license information, please view the LICENSE |
8
|
|
|
* file that was distributed with this source code. |
9
|
|
|
* |
10
|
|
|
* @license https://github.com/graze/data-flow/blob/master/LICENSE.md |
11
|
|
|
* @link https://github.com/graze/data-flow |
12
|
|
|
*/ |
13
|
|
|
|
14
|
|
|
namespace Graze\DataFlow\Flow\File; |
15
|
|
|
|
16
|
|
|
use Graze\DataFile\Node\LocalFile; |
17
|
|
|
use Graze\DataFlow\Flow\InvokeTrait; |
18
|
|
|
use Graze\DataFlow\FlowInterface; |
19
|
|
|
use Graze\DataNode\NodeInterface; |
20
|
|
|
use InvalidArgumentException; |
21
|
|
|
|
22
|
|
|
class ReplaceText extends \Graze\DataFile\Modify\ReplaceText implements FlowInterface |
23
|
|
|
{ |
24
|
|
|
use InvokeTrait; |
25
|
|
|
/** |
26
|
|
|
* @var |
27
|
|
|
*/ |
28
|
|
|
private $from; |
29
|
|
|
/** |
30
|
|
|
* @var |
31
|
|
|
*/ |
32
|
|
|
private $to; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* ReplaceText constructor. |
36
|
|
|
* |
37
|
|
|
* @param string|string[] $from The text to be replaced |
38
|
|
|
* @param string|string[] $to The new text |
39
|
|
|
* @param array $options |
40
|
|
|
*/ |
41
|
4 |
|
public function __construct($from, $to, array $options = []) |
42
|
|
|
{ |
43
|
4 |
|
$this->from = $from; |
44
|
4 |
|
$this->to = $to; |
45
|
4 |
|
$this->options = $options; |
46
|
4 |
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* Run a 'flow' through the handler |
50
|
|
|
* |
51
|
|
|
* @param NodeInterface $node |
52
|
|
|
* |
53
|
|
|
* @return LocalFile |
54
|
|
|
*/ |
55
|
4 |
|
public function flow(NodeInterface $node) |
56
|
|
|
{ |
57
|
4 |
|
if (!($node instanceof LocalFile)) { |
58
|
1 |
|
throw new InvalidArgumentException("Node: $node should be an instance of LocalFile"); |
59
|
|
|
} |
60
|
|
|
|
61
|
3 |
|
return $this->replaceText($node, $this->from, $this->to, $this->options); |
62
|
|
|
} |
63
|
|
|
} |
64
|
|
|
|