public function adaptBeforeExecuting($definition, $rmi, $arguments) { if ($definition['provider'] !== 'Data') { return $arguments; } if ($definition['name'] == 'beforeFindById' || $definition['name'] == 'afterFindById') { if (isset($arguments[2])) { $objects = $arguments[2]; if ($objects != null && count($objects) == 0) { $arguments[2] = ''; } } } else { if ($definition['name'] == 'beforeLoadRelations' || $definition['name'] == 'afterLoadRelations') { if (isset($arguments[3])) { $objects = $arguments[3]; if ($objects != null && count($objects) == 0) { $arguments[3] = ''; } } } } // convert data to ExecutionResult class foreach ($arguments as $arg_index => $arg_val) { if (isset($arg_val["___jsonclass"])) { if ($arg_val["___jsonclass"] == "com.backendless.servercode.ExecutionResult") { $execution_result = new ExecutionResult(); $execution_result->setException($arguments[$arg_index]["exception"]); $execution_result->setResult($arguments[$arg_index]["result"]); $arguments[$arg_index] = $execution_result; } } } $generic_index = $definition['generic_index']; // int 1 if ($generic_index == null) { return $arguments; } $arguments[0] = new RunnerContext($arguments[0]); $declared_properties = $arguments[$generic_index]; if ($rmi->getTarget() === self::$ALL_CONTEXT) { $arguments[$generic_index] = $declared_properties; return $arguments; } // model creation and fill data to properties $arguments[1] = ClassManager::getClassInstanceByName($declared_properties['___class']); ReflectionUtil::fillClassProperties($arguments[1], $declared_properties); //check extra data in declared_properties $model_prop = (new ReflectionClass(ClassManager::getFullClassName($declared_properties['___class'])))->getProperties(); $missing_properties = $declared_properties; foreach ($model_prop as $property) { $property->setAccessible(true); if (array_key_exists($property->name, $declared_properties)) { unset($missing_properties[$property->name]); } } $arguments[0]->setMissingProperties($missing_properties); return $arguments; }
public function runImpl() { Log::writeInfo("Called invocation task: " . $this->rmi, $target = 'file'); if ($this->rmi == null || $this->event_handler == null) { Log::writeInfo("Something is null in InvocationTask..."); return; } $invocation_result = new InvocationResult(); try { $this->initSdk(); $definition = self::$event_definition_holder->getDefinitionById($this->rmi->getEventId()); $arguments = self::$argument_adapter_list->beforeExecuting($definition, $this->rmi, $this->rmi->getDecodedArguments()); if ($definition['name'] == 'handleEvent') { // Object context = arguments[ 0 ]; // Class runnerContextClass = classLoader.loadClass( RunnerContext.class.getName() ); // List<String> userRoleList = (List<String>) runnerContextClass.getMethod( "getUserRole" ).invoke( context ); // // String[] userRoles = userRoleList == null ? null : userRoleList.toArray( new String[ userRoleList.size() ] ); // String userId = (String) runnerContextClass.getMethod( "getUserId" ).invoke( context ); // AccessValidator.validateAccess( clazz, userRoles, userId ); } $instance_class_name = $this->event_handler->getProvider(); $method = self::findMethod($instance_class_name, $definition, count($arguments)); // bootstrap onEnter action $backendless_globals = ClassManager::getClassInstanceByName('BackendlessGlobals'); $backendless_globals->onEnter($instance_class_name, $method, $arguments); // end bootstrap onEnter action // switch sdk from rest mode to bl Backendless::switchOnBlMode(); $reflection_method = new ReflectionMethod($instance_class_name, $method); $result = $arguments; // invokeArgs pass $arguments as link and we get changed data after invoke $returned_result = $reflection_method->invokeArgs(new $instance_class_name(), $result); if ($returned_result !== null) { $result = $returned_result; } // bootstrap onExit action $backendless_globals->onExit($instance_class_name, $method, $result); // end bootstrap onExit action if ($this->rmi->isAsync()) { return; } $arguments = self::$argument_adapter_list->afterExecuting($definition, $this->rmi, $arguments, $result); if (is_a($arguments[0], "\\backendless\\core\\servercode\\RunnerContext")) { $arguments[0] = $arguments[0]->getConvertedToArray(); } $invocation_result->setArguments($arguments); ResponderProcessor::sendResult($this->rmi->getId(), $invocation_result); } catch (Exception $e) { Log::writeError($e->getMessage()); $this->handleException($e, $invocation_result); } catch (BackendlessException $e) { Log::writeError("In Backendless SDK occurred error with message: \"" . $e->getMessage() . "\""); $this->handleException($e, $invocation_result); } catch (ExceptionWrapper $e) { Log::writeError($e->getMessage()); $this->handleException($e, $invocation_result); } }