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 InvalidArgumentException; |
13
|
|
|
use NextFlow\Core\Action\AbstractAction; |
14
|
|
|
use NextFlow\Core\Node\NodeInterface; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* A base final class for pop actions. |
18
|
|
|
*/ |
19
|
|
|
abstract class AbstractPopAction extends AbstractAction |
20
|
|
|
{ |
21
|
|
|
/** The output action socket. */ |
22
|
|
|
const SOCKET_OUTPUT = 'out'; |
23
|
|
|
|
24
|
|
|
/** The array variable socket. */ |
25
|
|
|
const SOCKET_ARRAY = 'array'; |
26
|
|
|
|
27
|
|
|
/** The data variable socket. */ |
28
|
|
|
const SOCKET_DATA = 'data'; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* Initializes a new instance of this class. |
32
|
|
|
*/ |
33
|
|
|
public function __construct() |
34
|
|
|
{ |
35
|
|
|
parent::__construct(); |
36
|
|
|
|
37
|
|
|
$this->createSocket(self::SOCKET_OUTPUT); |
38
|
|
|
$this->createSocket(self::SOCKET_ARRAY); |
39
|
|
|
$this->createSocket(self::SOCKET_DATA); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* Executes the node's logic. |
44
|
|
|
*/ |
45
|
|
|
public function execute() |
46
|
|
|
{ |
47
|
|
|
$array = $this->getSocket(self::SOCKET_ARRAY)->getNode(0); |
48
|
|
|
if ($array === null) { |
49
|
|
|
throw new InvalidArgumentException('No array variable provided.'); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
$poppedValue = $this->executePop($array); |
53
|
|
|
|
54
|
|
|
$dataSocket = $this->getSocket(self::SOCKET_DATA); |
55
|
|
|
if ($dataSocket->hasNodes()) { |
56
|
|
|
$dataSocket->getNode(0)->setValue($poppedValue); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
$this->activate(self::SOCKET_OUTPUT); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* Executes the pop logic. |
64
|
|
|
* |
65
|
|
|
* @param NodeInterface $node The node to pop data from. |
66
|
|
|
* @return mixed |
67
|
|
|
*/ |
68
|
|
|
abstract protected function executePop(NodeInterface $node); |
69
|
|
|
} |
70
|
|
|
|