@@ 31-65 (lines=35) @@ | ||
28 | * iconv -l |
|
29 | * ``` |
|
30 | */ |
|
31 | class ConvertEncoding extends \Graze\DataFile\Modify\Encoding\ConvertEncoding implements FlowInterface |
|
32 | { |
|
33 | use InvokeTrait; |
|
34 | ||
35 | /** |
|
36 | * @var string |
|
37 | */ |
|
38 | private $encoding; |
|
39 | ||
40 | /** |
|
41 | * @param string $encoding Encoding as defined by iconv |
|
42 | * @param array $options -postfix <string> (Default: toEncoding) |
|
43 | * -keepOldFile <bool> (Default: true) |
|
44 | */ |
|
45 | public function __construct($encoding, array $options = []) |
|
46 | { |
|
47 | $this->encoding = $encoding; |
|
48 | $this->options = $options; |
|
49 | } |
|
50 | ||
51 | /** |
|
52 | * @param NodeInterface $node |
|
53 | * |
|
54 | * @return NodeInterface |
|
55 | * @throws InvalidArgumentException |
|
56 | */ |
|
57 | public function flow(NodeInterface $node) |
|
58 | { |
|
59 | if (!($node instanceof LocalFile)) { |
|
60 | throw new InvalidArgumentException("Node: $node should be an instance of LocalFile"); |
|
61 | } |
|
62 | ||
63 | return $this->toEncoding($node, $this->encoding, $this->options); |
|
64 | } |
|
65 | } |
|
66 |
@@ 22-53 (lines=32) @@ | ||
19 | use Graze\DataNode\NodeInterface; |
|
20 | use InvalidArgumentException; |
|
21 | ||
22 | class Head extends \Graze\DataFile\Modify\Head implements FlowInterface |
|
23 | { |
|
24 | use InvokeTrait; |
|
25 | ||
26 | /** |
|
27 | * @param string $lines Number of lines to tail (accepts +/- modifiers) |
|
28 | * @param array $options List of options: |
|
29 | * -postfix <string> (Default: tail) |
|
30 | * -keepOldFile <bool> (Default: true) |
|
31 | */ |
|
32 | public function __construct($lines, array $options = []) |
|
33 | { |
|
34 | $this->lines = $lines; |
|
35 | $this->options = $options; |
|
36 | } |
|
37 | ||
38 | /** |
|
39 | * Run a 'flow' through the handler |
|
40 | * |
|
41 | * @param NodeInterface $node |
|
42 | * |
|
43 | * @return LocalFile |
|
44 | */ |
|
45 | public function flow(NodeInterface $node) |
|
46 | { |
|
47 | if (!($node instanceof LocalFile)) { |
|
48 | throw new InvalidArgumentException("Node: $node should be an instance of LocalFile"); |
|
49 | } |
|
50 | ||
51 | return $this->head($node, $this->lines, $this->options); |
|
52 | } |
|
53 | } |
|
54 |
@@ 23-59 (lines=37) @@ | ||
20 | use Graze\DataFlow\FlowInterface; |
|
21 | use Graze\DataNode\NodeInterface; |
|
22 | ||
23 | class Merge extends MergeFiles implements FlowInterface |
|
24 | { |
|
25 | use InvokeTrait; |
|
26 | ||
27 | /** |
|
28 | * @var FileNodeInterface |
|
29 | */ |
|
30 | private $file; |
|
31 | ||
32 | /** |
|
33 | * @param FileNodeInterface $file |
|
34 | * @param array $options |
|
35 | */ |
|
36 | public function __construct( |
|
37 | FileNodeInterface $file, |
|
38 | array $options = [] |
|
39 | ) { |
|
40 | $this->file = $file; |
|
41 | $this->options = $options; |
|
42 | } |
|
43 | ||
44 | /** |
|
45 | * Add files from a local Directory |
|
46 | * |
|
47 | * @param NodeInterface $node |
|
48 | * |
|
49 | * @return FileNodeInterface |
|
50 | */ |
|
51 | public function flow(NodeInterface $node) |
|
52 | { |
|
53 | if (!($node instanceof FileNodeCollectionInterface)) { |
|
54 | throw new \InvalidArgumentException("The supplied $node is not a FileNodeCollectionInterface"); |
|
55 | } |
|
56 | ||
57 | return $this->contract($node, $this->file, $this->options); |
|
58 | } |
|
59 | } |
|
60 |
@@ 22-53 (lines=32) @@ | ||
19 | use Graze\DataNode\NodeInterface; |
|
20 | use InvalidArgumentException; |
|
21 | ||
22 | class Tail extends \Graze\DataFile\Modify\Tail implements FlowInterface |
|
23 | { |
|
24 | use InvokeTrait; |
|
25 | ||
26 | /** |
|
27 | * @param string $lines Number of lines to head (accepts +/- modifiers) |
|
28 | * @param array $options List of options: |
|
29 | * -postfix <string> (Default: tail) |
|
30 | * -keepOldFile <bool> (Default: true) |
|
31 | */ |
|
32 | public function __construct($lines, array $options = []) |
|
33 | { |
|
34 | $this->lines = $lines; |
|
35 | $this->options = $options; |
|
36 | } |
|
37 | ||
38 | /** |
|
39 | * Run a 'flow' through the handler |
|
40 | * |
|
41 | * @param NodeInterface $node |
|
42 | * |
|
43 | * @return LocalFile |
|
44 | */ |
|
45 | public function flow(NodeInterface $node) |
|
46 | { |
|
47 | if (!($node instanceof LocalFile)) { |
|
48 | throw new InvalidArgumentException("Node: $node should be an instance of LocalFile"); |
|
49 | } |
|
50 | ||
51 | return $this->tail($node, $this->lines, $this->options); |
|
52 | } |
|
53 | } |
|
54 |