1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* AppserverIo\Routlt\Results\ResultTrait |
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\Results; |
22
|
|
|
|
23
|
|
|
use AppserverIo\Routlt\ActionInterface; |
24
|
|
|
use AppserverIo\Routlt\Description\ResultDescriptorInterface; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* Trait providing basic result functionality. |
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
|
|
|
trait ResultTrait |
36
|
|
|
{ |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* The action result name. |
40
|
|
|
* |
41
|
|
|
* @var string |
42
|
|
|
*/ |
43
|
|
|
protected $name; |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* The action result type. |
47
|
|
|
* |
48
|
|
|
* @var string |
49
|
|
|
*/ |
50
|
|
|
protected $type; |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* The action result value. |
54
|
|
|
* |
55
|
|
|
* @var array |
56
|
|
|
*/ |
57
|
|
|
protected $result; |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* The HTTP response code that has to be send. |
61
|
|
|
* |
62
|
|
|
* @var string |
63
|
|
|
*/ |
64
|
|
|
protected $code = 200; |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* Initializes the instance with the configured result value. |
68
|
|
|
* |
69
|
|
|
* @param \AppserverIo\Routlt\Description\\ResultDescriptorInterface $resultDescriptor The result descriptor instance |
70
|
|
|
*/ |
71
|
|
|
public function __construct(ResultDescriptorInterface $resultDescriptor) |
72
|
|
|
{ |
73
|
|
|
$this->name = $resultDescriptor->getName(); |
74
|
|
|
$this->type = $resultDescriptor->getType(); |
75
|
|
|
$this->code = $resultDescriptor->getCode(); |
|
|
|
|
76
|
|
|
$this->result = $resultDescriptor->getResult(); |
|
|
|
|
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* Returns the action result name. |
81
|
|
|
* |
82
|
|
|
* @return string The action result name |
83
|
|
|
*/ |
84
|
|
|
public function getName() |
85
|
|
|
{ |
86
|
|
|
return $this->name; |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* Returns the action result type. |
91
|
|
|
* |
92
|
|
|
* @return string The action result type |
93
|
|
|
*/ |
94
|
|
|
public function getType() |
95
|
|
|
{ |
96
|
|
|
return $this->type; |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* Returns the action result value. |
101
|
|
|
* |
102
|
|
|
* @return string The action result value |
103
|
|
|
*/ |
104
|
|
|
public function getResult() |
105
|
|
|
{ |
106
|
|
|
return $this->result; |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
/** |
110
|
|
|
* Returns the HTTP response code that has to be send. |
111
|
|
|
* |
112
|
|
|
* @return integer The HTTP response code |
113
|
|
|
*/ |
114
|
|
|
public function getCode() |
115
|
|
|
{ |
116
|
|
|
return $this->code; |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
/** |
120
|
|
|
* Sets the actual action instance. |
121
|
|
|
* |
122
|
|
|
* @param \AppserverIo\Routlt\ActionInterface $action The action instance |
123
|
|
|
* |
124
|
|
|
* @return void |
125
|
|
|
*/ |
126
|
|
|
public function setAction(ActionInterface $action) |
127
|
|
|
{ |
128
|
|
|
$this->action = $action; |
|
|
|
|
129
|
|
|
} |
130
|
|
|
|
131
|
|
|
/** |
132
|
|
|
* Returns the action instance. |
133
|
|
|
* |
134
|
|
|
* @return \AppserverIo\Routlt\ActionInterface The action instance |
135
|
|
|
*/ |
136
|
|
|
public function getAction() |
137
|
|
|
{ |
138
|
|
|
return $this->action; |
139
|
|
|
} |
140
|
|
|
} |
141
|
|
|
|
This check looks for assignments to scalar types that may be of the wrong type.
To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.