1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* AppserverIo\Routlt\Description\WorkflowInterceptor |
5
|
|
|
* |
6
|
|
|
* NOTICE OF LICENSE |
7
|
|
|
* |
8
|
|
|
* This source file is subject to the Open Software License (OSL 3.0) |
9
|
|
|
* that is available through the world-wide-web at this URL: |
10
|
|
|
* http://opensource.org/licenses/osl-3.0.php |
11
|
|
|
* |
12
|
|
|
* PHP version 5 |
13
|
|
|
* |
14
|
|
|
* @author Tim Wagner <[email protected]> |
15
|
|
|
* @copyright 2015 TechDivision GmbH <[email protected]> |
16
|
|
|
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) |
17
|
|
|
* @link http://github.com/appserver-io/routlt |
18
|
|
|
* @link http://www.appserver.io |
19
|
|
|
*/ |
20
|
|
|
|
21
|
|
|
namespace AppserverIo\Routlt\Interceptors; |
22
|
|
|
|
23
|
|
|
use AppserverIo\Routlt\ActionInterface; |
24
|
|
|
use AppserverIo\Routlt\Util\Validateable; |
25
|
|
|
use AppserverIo\Routlt\Util\ValidationAware; |
26
|
|
|
use AppserverIo\Psr\MetaobjectProtocol\Aop\MethodInvocationInterface; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @author Tim Wagner <[email protected]> |
30
|
|
|
* @copyright 2015 TechDivision GmbH <[email protected]> |
31
|
|
|
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) |
32
|
|
|
* @link http://github.com/appserver-io/routlt |
33
|
|
|
* @link http://www.appserver.io |
34
|
|
|
*/ |
35
|
|
|
class WorkflowInterceptor extends AbstractInterceptor |
36
|
|
|
{ |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* Method that implements the interceptors functionality. |
40
|
|
|
* |
41
|
|
|
* @param \AppserverIo\Psr\MetaobjectProtocol\Aop\MethodInvocationInterface $methodInvocation Initially invoked method |
42
|
|
|
* |
43
|
|
|
* @return string|null The action result |
44
|
|
|
*/ |
45
|
3 |
|
protected function execute(MethodInvocationInterface $methodInvocation) |
46
|
|
|
{ |
47
|
|
|
|
48
|
|
|
try { |
49
|
|
|
// proceed invocation chain |
50
|
3 |
|
$result = $methodInvocation->proceed(); |
51
|
|
|
|
52
|
|
|
// get the action, methods and servlet request |
53
|
3 |
|
$action = $this->getAction(); |
54
|
|
|
|
55
|
|
|
// query whether we want to validate |
56
|
2 |
|
if ($action instanceof Validateable) { |
57
|
2 |
|
$action->validate(); |
58
|
2 |
|
} |
59
|
|
|
|
60
|
|
|
// query whether the action is validation aware |
61
|
2 |
|
if ($action instanceof ValidationAware) { |
62
|
|
|
// query whether the action has errors or not |
63
|
2 |
|
if ($action->hasErrors()) { |
64
|
|
|
// attach the action errors to the servlet request |
65
|
1 |
|
$this->getServletRequest()->setAttribute('error.messages', $action->getErrors()); |
|
|
|
|
66
|
|
|
// return a failure |
67
|
1 |
|
$result = ActionInterface::FAILURE; |
68
|
1 |
|
} |
69
|
2 |
|
} |
70
|
|
|
|
71
|
3 |
|
} catch (\Exception $e) { |
72
|
|
|
// if not add an error message |
73
|
1 |
|
$this->getServletRequest()->setAttribute('error.messages', array('critical' => $e->getMessage())); |
|
|
|
|
74
|
|
|
// action invocation has failed |
75
|
1 |
|
$result = ActionInterface::FAILURE; |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
// return the result |
79
|
3 |
|
return $result; |
80
|
|
|
} |
81
|
|
|
} |
82
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.