-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathExecutionChain.php
93 lines (85 loc) · 2.6 KB
/
ExecutionChain.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
<?php
/*
* This file has its roots as part of the Mojavi package which was
* Copyright (c) 2003 Sean Kerr. It has been incorporated into this
* derivative work under the terms of the LGPL V2.1.
* (http://www.gnu.org/licenses/lgpl-2.1.html)
*/
namespace Xmf\Xadr;
use Xmf\Xadr\Exceptions\RecursiveForwardException;
/**
* ExecutionChain is a list of actions to be performed
* The Controller establishes the ExecutionChain, while the
* ExecutionFilter processes the chain.
*
* The Execution chain allows access to the state of all executed
* actions resulting from a request.
*
* @category Xmf\Xadr\ExecutionChain
* @package Xmf
* @author Richard Griffith <[email protected]>
* @author Sean Kerr <[email protected]>
* @copyright 2013-2015 XOOPS Project (http://xoops.org)
* @copyright 2003 Sean Kerr
* @license GNU GPL 2 or later (http://www.gnu.org/licenses/gpl-2.0.html)
* @link http://xoops.org
*/
class ExecutionChain extends \SplStack
{
/**
* An indexed array of executed actions.
*
* @var array
*/
protected $chain;
/**
* Create a new ExecutionChain instance.
*/
public function __construct()
{
$this->chain = array();
}
/**
* Add an action request to the chain.
*
* @param string $unitName A unit name.
* @param string $actionName An action name.
* @param Action|null $action An Action instance.
*
* @return void
*
* @throws RecursiveForwardException
*/
public function addRequest($unitName, $actionName, $action)
{
//$this->setIteratorMode(\SplDoublyLinkedList::IT_MODE_LIFO | \SplDoublyLinkedList::IT_MODE_KEEP);
foreach ($this as $stackReq) {
if ($stackReq['unit_name'] == $unitName && $stackReq['action_name'] == $actionName) {
$error = 'Recursive forward on unit ' . $unitName . ', action ' . $actionName;
throw new RecursiveForwardException($error);
}
}
$req = array(
'unit_name' => $unitName,
'action_name' => $actionName,
'action' => $action,
'microtime' => microtime(true)
);
$this->push($req);
}
/**
* Retrieve the last Action instance
*
* @return Action|null The Action instance of last stack entry, or null if the stack is empty
*/
public function getAction()
{
try {
$req = $this->top();
$action = $req['action'];
} catch (\RuntimeException $e) {
$action = null;
}
return $action;
}
}