|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* NextFlow (http://github.com/nextflow) |
|
4
|
|
|
* |
|
5
|
|
|
* @link http://github.com/nextflow/nextflow-php for the canonical source repository |
|
6
|
|
|
* @copyright Copyright (c) 2014-2016 NextFlow (http://github.com/nextflow) |
|
7
|
|
|
* @license https://raw.github.com/nextflow/nextflow-php/master/LICENSE MIT |
|
8
|
|
|
*/ |
|
9
|
|
|
|
|
10
|
|
|
namespace NextFlow\Arrays\Action; |
|
11
|
|
|
|
|
12
|
|
|
use NextFlow\Core\Action\AbstractAction; |
|
13
|
|
|
use NextFlow\Core\Node\NodeInterface; |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* A base final class for push actions. |
|
17
|
|
|
*/ |
|
18
|
|
|
abstract class AbstractPushAction extends AbstractAction |
|
19
|
|
|
{ |
|
20
|
|
|
/** The output action socket. */ |
|
21
|
|
|
const SOCKET_OUTPUT = 'out'; |
|
22
|
|
|
|
|
23
|
|
|
/** The array variable socket. */ |
|
24
|
|
|
const SOCKET_ARRAY = 'array'; |
|
25
|
|
|
|
|
26
|
|
|
/** The data variable socket. */ |
|
27
|
|
|
const SOCKET_DATA = 'data'; |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* Initializes a new instance of this class. |
|
31
|
|
|
*/ |
|
32
|
|
|
public function __construct() |
|
33
|
|
|
{ |
|
34
|
|
|
parent::__construct(); |
|
35
|
|
|
|
|
36
|
|
|
$this->createSocket(self::SOCKET_OUTPUT); |
|
37
|
|
|
$this->createSocket(self::SOCKET_ARRAY); |
|
38
|
|
|
$this->createSocket(self::SOCKET_DATA); |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* Executes the node's logic. |
|
43
|
|
|
*/ |
|
44
|
|
|
public function execute() |
|
45
|
|
|
{ |
|
46
|
|
|
$array = $this->getSocket(self::SOCKET_ARRAY)->getNode(0); |
|
47
|
|
|
if ($array === null) { |
|
48
|
|
|
throw new \InvalidArgumentException('No array variable provided.'); |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
$data = $this->getSocket(self::SOCKET_DATA)->getNode(0); |
|
52
|
|
|
if ($data === null) { |
|
53
|
|
|
throw new \InvalidArgumentException('No array variable provided.'); |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
$this->executePush($array, $data->getValue()); |
|
57
|
|
|
|
|
58
|
|
|
$this->activate(self::SOCKET_OUTPUT); |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
/** |
|
62
|
|
|
* Executes the push logic. |
|
63
|
|
|
* |
|
64
|
|
|
* @param NodeInterface $node The node to push data to. |
|
65
|
|
|
* @param mixed $value The value to push. |
|
66
|
|
|
*/ |
|
67
|
|
|
abstract protected function executePush(NodeInterface $node, $value); |
|
68
|
|
|
} |
|
69
|
|
|
|