88 if ($request->hasValue(
'data')) {
89 $data = $request->getValue(
'data');
90 foreach($data as $key => $value) {
91 if (!is_array($value)) {
93 array(
'invalidParameters' => array(
'data.'.$key))));
100 array(
'missingParameters' => array(
'data'))));
116 $data = $request->getValue(
'data');
117 $actions = array_keys($data);
118 $numActions =
sizeof($actions);
119 $exceptions = array();
121 for($i=0; $i<$numActions; $i++) {
122 $actionId = $actions[$i];
123 if ($logger->isDebugEnabled()) {
124 $logger->debug(
"processing action: ".$actionId.
":\n".
StringUtil::getDump($data[$actionId]));
127 $this->replaceVariables($data[$actionId]);
130 $actionData = $data[$actionId];
131 $context = isset($actionData[
'context']) ? $actionData[
'context'] :
'';
132 $action = isset($actionData[
'action']) ? $actionData[
'action'] :
'';
135 $params = isset($actionData[
'params']) ? $actionData[
'params'] : $actionData;
137 $requestPart->setContext($context);
138 $requestPart->setAction($action);
139 $requestPart->setValues($params);
140 $requestPart->setFormat(
'null');
141 $requestPart->setResponseFormat(
'null');
152 $results[$actionId] = $responsePart != null ? $responsePart->getValues() : array();
154 if ($logger->isDebugEnabled()) {
155 $logger->debug($results);
158 foreach ($exceptions as $ex) {
161 $response->setValue(
'data', $results);
162 $response->setAction(
'ok');
170 private function replaceVariables(&$data) {
172 $keys = array_keys($data);
173 for($i=0; $i<
sizeof($keys); $i++) {
175 $value = $data[$key];
178 $newKey = $this->replaceVariablesString($key);
179 $newValue = $this->replaceVariablesString($value);
182 if ($key != $newKey || $value != $newValue) {
183 if ($logger->isDebugEnabled()) {
184 if ($key != $newKey) {
185 $logger->debug(
"Replace $key by $newKey");
187 if ($value != $newValue) {
188 $logger->debug(
"Replace $value by $newValue");
192 $data[$newKey] = $newValue;
203 private function replaceVariablesString($value) {
204 if (!is_string($value)) {
207 preg_match_all(
'/\{([^\{]+)\}/', $value, $variableMatches);
208 $variables = $variableMatches[1];
209 foreach($variables as $variable) {
210 preg_match(
'/^([^:]+)[:]*(.*)$/', $variable, $matches);
211 if (
sizeof($matches > 0)) {
212 $variableName = $matches[1];
213 $parameters = $matches[2];
217 if ($variableName ==
'last_created_oid') {
219 if ($persistenceFacade->isKnownType($type)) {
220 $oid = $persistenceFacade->getLastCreatedOID($type);
221 $value = preg_replace(
"/{".$variable.
"}/", $oid, $value);
226 if ($persistenceFacade->isKnownType($variableName)) {
227 $type = $variableName;
228 $oid = $persistenceFacade->getLastCreatedOID($type);
getRequest()
Get the Request instance.
Controller is the base class of all controllers.
MultipleActionController executes multiple actions by passing them do the appropriate controllers and...
static getInstance($name, $dynamicConfiguration=array())
static fromException(\Exception $ex)
Factory method for transforming an exception into an ApplicationError instance.
static get($code, $data=null)
Factory method for retrieving a predefind error instance.
getLogger()
Get the Logger instance.
getActionMapper()
Get the ActionMapper instance.
getResponse()
Get the Response instance.
getPersistenceFacade()
Get the PersistenceFacade instance.
static getDump($var)
Get the dump of a variable as string.