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);
     }
 }
 public static function load($argc, $argv)
 {
     Config::loadConfig();
     self::phpEnviromentInit();
     Log::init(Config::$CORE['os_type'], GlobalState::$TYPE, Config::$CORE['logging_in_cloud_mode']);
     Log::writeInfo("Start CodeRunner.", $target = 'file');
     EventDefinitionHolder::getInstance()->load();
     if (GlobalState::$TYPE === 'LOCAL') {
         self::checkForInputKeys($argc, $argv);
         self::checkDefaultKeys();
         ClassManager::analyze();
         self::printGreeting();
     } else {
         self::checkInputKeysForCloud($argc, $argv);
     }
     $code_runner = new CodeRunner();
     $code_runner->loadMessageProcessor();
     $code_runner->start();
 }
 public function __construct($msg)
 {
     parent::__construct();
     $msg_as_array = json_decode($msg, true);
     $this->id = $msg_as_array['id'];
     $this->application_id = $msg_as_array['applicationId'];
     $this->app_version_id = $msg_as_array['appVersionId'];
     $this->event_id = $msg_as_array['eventId'];
     $this->arguments = $msg_as_array['arguments'];
     $this->target = $msg_as_array['target'];
     $this->timeout = $msg_as_array['timeout'];
     $this->async = $msg_as_array['async'];
     $this->decoded_arguments = null;
     if (GlobalState::$TYPE === 'CLOUD') {
         $this->relative_path = $msg_as_array['relativePath'];
         Config::$RELATIVE_PATH = $msg_as_array['relativePath'];
         Config::$TASK_APPLICATION_ID = $msg_as_array['applicationId'];
         ClassManager::analyze();
     }
 }
 protected function RequestServiceInvocation($msg)
 {
     /// invoke hosted servise action
     $rsi = new RequestServiceInvocation($msg);
     Log::writeInfo("Received RSI:" . $rsi, $target = 'file');
     if (GlobalState::$TYPE == 'CLOUD' && time() * 1000 - $rsi->getTimestamp() > $this->timeout) {
         Log::writeError("RSI ignored by timeout" . $rsi, $target = 'file');
         return;
     }
     if (GlobalState::$TYPE === 'CLOUD') {
         Config::$RELATIVE_PATH = $msg['relativePath'];
         Config::$TASK_APPLICATION_ID = $msg['applicationId'];
         //ClassManager::analyze( PathBuilder::getClasses() );
         ClassManager::analyze(PathBuilder::getHostedService($rsi->getAppVersionId(), $rsi->getRelativePath()));
     }
     $executor = $this->executor_holder->getCodeExecutor($rsi->getApplicationId(), $rsi->getAppVersionId());
     $executor->invokeService($rsi);
 }