public function runImpl()
 {
     Log::writeInfo("Called invocation task: " . $this->rsi, $target = 'file');
     if ($this->rsi == null) {
         Log::writeInfo("Something is null in InvocationActionTask...");
         return;
     }
     try {
         if (GlobalState::$TYPE == 'CLOUD') {
             $xml_path = realpath(PathBuilder::getHostedService($this->rsi->getAppVersionId(), $this->rsi->getRelativePath()) . DS . "..") . DS . $this->rsi->getAppVersionId() . ".xml";
             HostedModelHolder::setXMLModel(file_get_contents($xml_path));
             // load xml from file to holder
         }
         $this->initSdk();
         $instance_class_name = $this->rsi->getClassName();
         $arguments = $this->rsi->getArguments();
         $hosted_mapper = new HostedMapper();
         $hosted_mapper->prepareArguments($arguments, $this->rsi->getMethod());
         if ($hosted_mapper->isError()) {
             Log::writeError($hosted_mapper->getError()['msg']);
             return ResponderProcessor::sendResult($this->rsi->getId(), $hosted_mapper->getError());
         }
         $reflection_method = new ReflectionMethod($this->rsi->getClassName(), $this->rsi->getMethod());
         $hosted_instance = new $instance_class_name();
         $this->setConfiguration($hosted_instance, $this->rsi->getConfiguration());
         $result = $reflection_method->invokeArgs($hosted_instance, $arguments);
         $invocation_result = new InvocationResult();
         $hosted_mapper->prepareResult($result);
         $invocation_result->setArguments($result);
         ResponderProcessor::sendResult($this->rsi->getId(), $invocation_result);
     } catch (Exception $e) {
         Log::writeError($e->getMessage());
     }
 }
 public function runImpl()
 {
     Log::writeInfo("Called invocation task task: " . $this->rai, $target = 'file');
     if ($this->rai == null) {
         Log::writeInfo("Something is null in InvocationActionTask...");
         return;
     }
     try {
         $path_to_hosted = PathBuilder::getHostedService($this->rai->getAppVersionId(), $this->rai->getRelativePath());
         $parser = HostedServiceParser::getInstance()->parseModelRAI($path_to_hosted, $this->rai->getId());
         if ($parser->isError()) {
             Log::writeError($parser->getError()['msg']);
             return ResponderProcessor::sendResult($this->rai->getId(), $parser->getError());
         }
         $runtime = ['path' => $path_to_hosted, 'endpointURL' => Config::$CORE['hosted_service']['endpoint_url'], 'serverRootURL' => Config::$CORE['hosted_service']['server_root_url'], 'serverPort' => Config::$CORE['hosted_service']['server_port'], 'serverName' => Config::$CORE['hosted_service']['server_name'], 'codeFormatType' => Config::$CORE['hosted_service']['code_format_type'], "generationMode" => Config::$CORE['hosted_service']['generation_mode'], 'randomUUID' => mt_rand(100000000, PHP_INT_MAX)];
         $xml_manager = new XmlManager();
         $invocation_result = new InvocationResult();
         $invocation_result->setArguments(["xml" => $xml_manager->buildXml($parser->getParsedData(), $runtime), "config" => $parser->getConfigListAsArray()]);
         //            $xml = $xml_manager->buildXml( $hosted_parser->getParsedData(), $runtime );
         //            file_put_contents("../repo/e3bd3a54-9a07-6160-ff70-a824a9610800/servercode/services/E3BD3A54-9A07-6160-FF70-A824A9610800.xml", $xml);
         //            echo $xml; return;
         ResponderProcessor::sendResult($this->rai->getId(), $invocation_result);
     } catch (Exception $e) {
         Log::writeError($e->getMessage());
     }
 }
 public static function getHostedService($app_version_id, $relative_path = null)
 {
     // only for CLOUD mode
     $repo_path = rtrim(Config::$REPO_PATH, "/");
     $path = realpath(getcwd() . DS . $repo_path) . DS . strtolower($app_version_id) . DS . $relative_path . DS . strtolower($app_version_id);
     Log::writeInfo("Build path to hosted code : " . $path, "file");
     return $path;
 }
 private function __construct()
 {
     try {
         $this->redis = new Predis(["scheme" => "tcp", "host" => Config::$REDIS_HOST, "port" => Config::$REDIS_PORT]);
         // Log::writeInfo("Successfully connected to Redis", $target = 'file');
     } catch (Exception $e) {
         Log::writeError("Couldn't connected to Redis", $target = 'file');
     }
 }
 public function onMessageReceived($msg)
 {
     $rmi = new RequestMethodInvocation($msg);
     if (GlobalState::$TYPE == 'CLOUD' && time() * 1000 - $rmi->getTimestamp() > $this->timeout) {
         Log::writeError("RMI ignored by timeout" . $rmi, $target = 'file');
         return;
     }
     $code_executor = $this->executor_holder->getCodeExecutor($rmi->getApplicationId(), $rmi->getAppVersionId());
     $code_executor->invoke($rmi);
 }
 public static function execute($invocation_task)
 {
     if (GlobalState::$TYPE == "LOCAL") {
         $invocation_task->setTimeout(self::$DEBUG_TIMEOUT);
     }
     try {
         $invocation_task->runImpl();
     } catch (Exception $e) {
         Log::writeError("Failed task execution", $e->getMessage());
     }
 }
 private static function readDefinition($definition_name)
 {
     $definition_path = BP . DS . implode(DS, Config::$CORE['definition_source_path']) . DS . $definition_name . ".php";
     $readed_definition = false;
     if (file_exists($definition_path)) {
         $readed_definition = (include $definition_path);
     } else {
         Log::writeError('Can\'t read definition file.', $target = 'file');
     }
     return $readed_definition;
 }
 public function invokeAction($rai)
 {
     switch ($rai->getActionType()) {
         case 'PARSE_CUSTOM_SERVICE_FROM_JAR':
             $invocation_task = new HostedServiceParseTask($rai);
             $invocation_task->runImpl();
             break;
         default:
             Log::writeError("Can't define action type of received RequestActionInvocation", $target = "all");
     }
 }
 public function parseModelRAI($repo_path)
 {
     Log::writeInfo("RAI parsing hosted user code.");
     if (!file_exists($repo_path)) {
         $msg = "Seems, that the class location is wrong. Please, check it and run CodeRunner again.";
         Log::writeError($msg, $target = "console");
         throw new CodeRunnerException($msg);
     }
     $parser = new HostedReflectionUtil($repo_path);
     $parser->parseFolderWithCustomCode();
     return $parser;
 }
 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 {
         $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
         $reflection_method->invokeArgs(new $instance_class_name(), $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());
     } catch (BackendlessException $e) {
         Log::writeError("In Backendless SDK occurred error with message: \"" . $e->getMessage() . "\"");
         exit;
     }
 }
 public function run()
 {
     $http_request = new HttpRequest();
     $target = Config::$CORE['processing_driverHostPort'] . '/getRequest?' . 'coderunnerId=' . Config::$CORE['processing_coderunnerId'] . '' . '&requestId=' . Config::$CORE['processing_requestId'] . '&lang=PHP';
     $http_request->setTargetUrl($target)->setHeader('Content-type', 'application/json')->request('', 'GET');
     if ($http_request->getResponseCode() == 200) {
         Log::writeInfo("Data received from java driver" . $http_request->getResponce(), $target = 'file');
         $this->dispatcher->onMessageReceived($http_request->getResponce());
     } else {
         $msg = "CodeRunner get task fail, HTTP response code: " . $http_request->getResponseCode() . " response status: " . $http_request->getResponseStatus();
         Log::writeError($msg, $target = 'file');
         throw new CodeRunnerException($msg);
     }
 }
 public function publish($code_zip_path)
 {
     $target = Config::$SERVER_URL . Config::$CORE['publish_code'] . "/" . Config::$CORE['lang'];
     $http_request = new HttpRequest();
     $multipart_boundary = "------BackendlessFormBoundary" . md5(uniqid()) . microtime(true);
     $file_contents = file_get_contents($code_zip_path);
     $content = "--" . $multipart_boundary . "\r\n" . "Content-Disposition: form-data; name=\"code\"; filename=\"" . basename($code_zip_path) . "\"\r\n" . "Content-Type: application/zip\r\n\r\n" . $file_contents . "\r\n";
     $content .= "--" . $multipart_boundary . "--\r\n";
     $http_request->setTargetUrl($target)->setHeader(self::$APP_ID_KEY, Config::$APPLICATION_ID)->setHeader(self::$SECRET_KEY, Config::$SECRET_KEY)->setHeader(self::$VERSION, Config::$APP_VERSION)->setHeader('Content-type', ' multipart/form-data; boundary=' . $multipart_boundary)->request($content);
     if ($http_request->getResponseCode() != 200) {
         $msg = "Deploying code failed, HTTP response code: " . $http_request->getResponseCode() . " response status: " . $http_request->getResponseStatus();
         Log::writeError($msg);
         throw new CodeRunnerException($msg);
     }
 }
 public function run()
 {
     $http_request = new HttpRequest();
     $target = Config::$CORE['processing_driverHostPort'] . '/getRequest?' . 'coderunnerId=' . Config::$CORE['processing_coderunnerId'] . '' . '&requestId=' . Config::$CORE['processing_requestId'] . '&lang=PHP';
     $http_request->setTargetUrl($target)->setHeader('Content-type', 'application/json')->request('', 'GET');
     if ($http_request->getResponseCode() == 200) {
         Log::writeInfo("Data received from java driver" . $http_request->getResponce(), $target = 'file');
         $this->dispatcher->onMessageReceived($http_request->getResponce());
         //$example =  '{"___jsonclass":"com.backendless.coderunner.commons.protocol.RequestMethodInvocation","appVersionId":"TEST-7379B69C-D7FE-C34C-FF50-C08463D8A400","relativePath":"files/servercode/PHP/v1","async":false,"eventId":100.0,"arguments":[91.0,123.0,34.0,95.0,95.0,95.0,106.0,115.0,111.0,110.0,99.0,108.0,97.0,115.0,115.0,34.0,58.0,34.0,99.0,111.0,109.0,46.0,98.0,97.0,99.0,107.0,101.0,110.0,100.0,108.0,101.0,115.0,115.0,46.0,115.0,101.0,114.0,118.0,101.0,114.0,99.0,111.0,100.0,101.0,46.0,82.0,117.0,110.0,110.0,101.0,114.0,67.0,111.0,110.0,116.0,101.0,120.0,116.0,34.0,44.0,34.0,100.0,101.0,118.0,105.0,99.0,101.0,84.0,121.0,112.0,101.0,34.0,58.0,34.0,82.0,69.0,83.0,84.0,34.0,44.0,34.0,117.0,115.0,101.0,114.0,84.0,111.0,107.0,101.0,110.0,34.0,58.0,110.0,117.0,108.0,108.0,44.0,34.0,112.0,114.0,101.0,109.0,97.0,116.0,117.0,114.0,101.0,82.0,101.0,115.0,117.0,108.0,116.0,34.0,58.0,110.0,117.0,108.0,108.0,44.0,34.0,109.0,105.0,115.0,115.0,105.0,110.0,103.0,80.0,114.0,111.0,112.0,101.0,114.0,116.0,105.0,101.0,115.0,34.0,58.0,110.0,117.0,108.0,108.0,44.0,34.0,97.0,112.0,112.0,73.0,100.0,34.0,58.0,34.0,69.0,51.0,66.0,68.0,51.0,65.0,53.0,52.0,45.0,57.0,65.0,48.0,55.0,45.0,54.0,49.0,54.0,48.0,45.0,70.0,70.0,55.0,48.0,45.0,65.0,56.0,50.0,52.0,65.0,57.0,54.0,49.0,48.0,56.0,48.0,48.0,34.0,44.0,34.0,117.0,115.0,101.0,114.0,82.0,111.0,108.0,101.0,34.0,58.0,91.0,34.0,78.0,111.0,116.0,65.0,117.0,116.0,104.0,101.0,110.0,116.0,105.0,99.0,97.0,116.0,101.0,100.0,85.0,115.0,101.0,114.0,34.0,93.0,44.0,34.0,117.0,115.0,101.0,114.0,73.0,100.0,34.0,58.0,110.0,117.0,108.0,108.0,125.0,44.0,123.0,34.0,95.0,95.0,95.0,106.0,115.0,111.0,110.0,99.0,108.0,97.0,115.0,115.0,34.0,58.0,34.0,79.0,114.0,100.0,101.0,114.0,34.0,44.0,34.0,95.0,95.0,95.0,99.0,108.0,97.0,115.0,115.0,34.0,58.0,34.0,79.0,114.0,100.0,101.0,114.0,34.0,44.0,34.0,99.0,117.0,115.0,116.0,111.0,109.0,101.0,114.0,110.0,97.0,109.0,101.0,34.0,58.0,34.0,66.0,111.0,98.0,34.0,125.0,93.0],"id":"6C5F633C-C792-EE69-FF35-E877B21A2200","applicationId":"E3BD3A54-9A07-6160-FF70-A824A9610800","timeout":5000.0,"target":"Order","timestamp":1.439825950904E12}';
         //$example = '{"___jsonclass":"com.backendless.coderunner.commons.protocol.RequestMethodInvocation","appVersionId":"0B60E43E-B0DC-EBCF-FF95-37AFBA84FE00","async":false,"eventId":100.0,"relativePath":"servercode/PHP/v1","arguments":[91.0,123.0,34.0,95.0,95.0,95.0,106.0,115.0,111.0,110.0,99.0,108.0,97.0,115.0,115.0,34.0,58.0,34.0,99.0,111.0,109.0,46.0,98.0,97.0,99.0,107.0,101.0,110.0,100.0,108.0,101.0,115.0,115.0,46.0,115.0,101.0,114.0,118.0,101.0,114.0,99.0,111.0,100.0,101.0,46.0,82.0,117.0,110.0,110.0,101.0,114.0,67.0,111.0,110.0,116.0,101.0,120.0,116.0,34.0,44.0,34.0,100.0,101.0,118.0,105.0,99.0,101.0,84.0,121.0,112.0,101.0,34.0,58.0,34.0,82.0,69.0,83.0,84.0,34.0,44.0,34.0,117.0,115.0,101.0,114.0,84.0,111.0,107.0,101.0,110.0,34.0,58.0,34.0,55.0,67.0,53.0,70.0,54.0,51.0,50.0,50.0,45.0,55.0,50.0,55.0,55.0,45.0,48.0,53.0,56.0,50.0,45.0,70.0,70.0,56.0,65.0,45.0,70.0,51.0,48.0,65.0,57.0,70.0,66.0,69.0,65.0,52.0,48.0,48.0,34.0,44.0,34.0,112.0,114.0,101.0,109.0,97.0,116.0,117.0,114.0,101.0,82.0,101.0,115.0,117.0,108.0,116.0,34.0,58.0,110.0,117.0,108.0,108.0,44.0,34.0,109.0,105.0,115.0,115.0,105.0,110.0,103.0,80.0,114.0,111.0,112.0,101.0,114.0,116.0,105.0,101.0,115.0,34.0,58.0,110.0,117.0,108.0,108.0,44.0,34.0,97.0,112.0,112.0,73.0,100.0,34.0,58.0,34.0,50.0,69.0,54.0,53.0,70.0,66.0,69.0,52.0,45.0,70.0,68.0,56.0,51.0,45.0,49.0,68.0,54.0,65.0,45.0,70.0,70.0,69.0,53.0,45.0,66.0,50.0,54.0,48.0,52.0,65.0,50.0,49.0,50.0,50.0,48.0,48.0,34.0,44.0,34.0,117.0,115.0,101.0,114.0,82.0,111.0,108.0,101.0,34.0,58.0,91.0,34.0,65.0,117.0,116.0,104.0,101.0,110.0,116.0,105.0,99.0,97.0,116.0,101.0,100.0,85.0,115.0,101.0,114.0,34.0,93.0,44.0,34.0,117.0,115.0,101.0,114.0,73.0,100.0,34.0,58.0,34.0,69.0,55.0,54.0,51.0,56.0,53.0,56.0,52.0,45.0,51.0,51.0,69.0,56.0,45.0,48.0,70.0,68.0,50.0,45.0,70.0,70.0,49.0,53.0,45.0,51.0,54.0,57.0,66.0,50.0,52.0,51.0,50.0,49.0,50.0,48.0,48.0,34.0,125.0,44.0,123.0,34.0,95.0,95.0,95.0,106.0,115.0,111.0,110.0,99.0,108.0,97.0,115.0,115.0,34.0,58.0,34.0,79.0,114.0,100.0,101.0,114.0,34.0,44.0,34.0,95.0,95.0,95.0,99.0,108.0,97.0,115.0,115.0,34.0,58.0,34.0,79.0,114.0,100.0,101.0,114.0,34.0,125.0,93.0],"id":"7B82E87C-9643-5132-FF31-D0952702EB00","applicationId":"2E65FBE4-FD83-1D6A-FFE5-B2604A212200","lang":"PHP","timeout":5000.0,"target":"Order","timestamp":1.441703027359E12}';
         //$this->dispatcher->onMessageReceived( $example );
     } else {
         $msg = "CodeRunner get task fail, HTTP response code: " . $http_request->getResponseCode() . " response status: " . $http_request->getResponseStatus();
         Log::writeError($msg, $target = 'file');
         throw new CodeRunnerException($msg);
     }
 }
 public function run()
 {
     try {
         $predis = self::$redis_manager->getRedis();
         $result = $predis->blpop([$this->getChannel()], 1);
         if ($result == null) {
             return;
         } elseif ($result[1] == Config::$CORE['local_shutdown_code']) {
             exit(0);
         }
         $this->dispatcher->onMessageReceived($result[1]);
     } catch (ConnectionException $e) {
         Log::writeError($e->getMessage());
     } catch (Exception $e) {
         Log::writeError($e->getMessage());
     }
 }
 public function cloudRun()
 {
     $result = array_shift(self::$results_queue);
     if ($result === null) {
         return;
     }
     $http_request = new HttpRequest();
     $target = Config::$CORE['processing_driverHostPort'] . '/sendResult?' . 'coderunnerId=' . Config::$CORE['processing_coderunnerId'] . '' . '&requestId=' . Config::$CORE['processing_requestId'] . '' . '&lang=PHP';
     $result_data = json_encode($result['result']->getConvertedToArray());
     $http_request->setTargetUrl($target)->setHeader('Content-type', 'application/json')->request($result_data, 'POST');
     Log::writeInfo("Data sent to java driver" . $result_data, $target = 'file');
     if ($http_request->getResponseCode() !== 200) {
         $msg = "CodeRunner set task result fail, HTTP response code: " . $http_request->getResponseCode() . " response status: " . $http_request->getResponseStatus();
         Log::writeError($msg, $target = 'file');
     } else {
         Log::writeInfo("Invocation result put to driver", "file");
     }
 }
 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);
 }
 public function load()
 {
     $data = DefinitionReader::getDefinition('Data');
     foreach ($data as $name => $propertys) {
         $this->holder[$propertys['id']] = ['name' => $name, 'provider' => 'Data', 'generic_index' => $propertys['index']];
         $this->name_holder["DATA" . "_" . $name] = $propertys;
     }
     $data = DefinitionReader::getDefinition('User');
     foreach ($data as $name => $propertys) {
         $this->holder[$propertys['id']] = ['name' => $name, 'provider' => 'User', 'generic_index' => $propertys['index']];
         $this->name_holder["USER" . "_" . $name] = $propertys;
     }
     $data = DefinitionReader::getDefinition('Timer');
     foreach ($data as $name => $propertys) {
         $this->holder[$propertys['id']] = ['name' => $name, 'provider' => 'Timer', 'generic_index' => $propertys['index']];
         $this->name_holder["TIMER" . "_" . $name] = $propertys;
     }
     $data = DefinitionReader::getDefinition('Custom');
     foreach ($data as $name => $propertys) {
         $this->holder[$propertys['id']] = ['name' => $name, 'provider' => 'Custom', 'generic_index' => $propertys['index']];
         $this->name_holder["CUSTOM" . "_" . $name] = $propertys;
     }
     $data = DefinitionReader::getDefinition('File');
     foreach ($data as $name => $propertys) {
         $this->holder[$propertys['id']] = ['name' => $name, 'provider' => 'File', 'generic_index' => $propertys['index']];
         $this->name_holder["FILE" . "_" . $name] = $propertys;
     }
     $data = DefinitionReader::getDefinition('Geo');
     foreach ($data as $name => $propertys) {
         $this->holder[$propertys['id']] = ['name' => $name, 'provider' => 'Geo', 'generic_index' => $propertys['index']];
         $this->name_holder["GEO" . "_" . $name] = $propertys;
     }
     $data = DefinitionReader::getDefinition('Media');
     foreach ($data as $name => $propertys) {
         $this->holder[$propertys['id']] = ['name' => $name, 'provider' => 'Media', 'generic_index' => $propertys['index']];
         $this->name_holder["MEDIA" . "_" . $name] = $propertys;
     }
     $data = DefinitionReader::getDefinition('Messaging');
     foreach ($data as $name => $propertys) {
         $this->holder[$propertys['id']] = ['name' => $name, 'provider' => 'Messaging', 'generic_index' => $propertys['index']];
         $this->name_holder["MESSAGING" . "_" . $name] = $propertys;
     }
     Log::writeInfo("Loaded " . count($this->holder) . " event handler definitions", $target = 'file');
 }
 protected function analyzeResponce()
 {
     if ($this->getResponseCode() != 200) {
         Log::writeError("Fail HTTP request to: {$this->target_url}  Response code: " . $this->getResponseCode() . " Response status: " . $this->getResponseStatus() . " Response body: \"" . $this->getResponce() . "\"", "file");
         $msg = '';
         if ($this->isJson($this->getResponce())) {
             $json_array = json_decode($this->getResponce(), true);
             if (isset($json_array["code"])) {
                 $msg = "Code: " . $json_array["code"] . " ";
             }
             $msg = "Message: " . $json_array['message'];
         } else {
             $msg = $this->getResponce();
         }
         Log::writeError("Server response: \"" . $msg . "\"");
     } else {
         Log::writeInfo("Success HTTP request to: {$this->target_url}", "file");
     }
 }
 public function doBuild()
 {
     $this->event_handlers_model = EventModelParser::getInstance()->parseDebugModel();
     Log::writeInfo("Build successfully event model: " . $this->event_handlers_model);
     //$this->hosted_model = HostedServiceParser::getInstance()->parseDebugModel();
     //        HostedModelHolder::setModel( $this->hosted_model );
     //        HostedModelHolder::setXMLModel( $this->hosted_model->getXML() );
     //        Log::writeInfo( "Build successfully hosted model: " . $this->hosted_model );
 }
 public function doBuild()
 {
     $this->event_handlers_model = EventModelParser::getInstance()->parseDebugModel();
     Log::writeInfo("Build successfully: " . $this->event_handlers_model);
     GlobalState::$STATE = "BUILD";
 }
 private function isValidTimer($handler)
 {
     $current_time = time() * 1000;
     $timer_info = json_decode(str_replace("'", "\"", $handler->getTarget()), true);
     if (isset($timer_info["expire"])) {
         if ($timer_info["expire"] < $current_time) {
             $masg = "Timer '" . $timer_info["timername"] . "' already expired";
             Log::writeError($msg);
             throw new CodeRunnerException($msg);
         }
     }
     if ($timer_info["startDate"] < $current_time) {
         if ($timer_info["frequency"]["schedule"] == "once") {
             Log::writeError("Timer's '" . $timer_info['timername'] . "' start time is in the past, unable to run the timer.");
             return false;
         }
         Log::writeWarn("Timer's '" . $timer_info['timername'] . "' start time is in the past. The timer will run accordingly to the schedule.");
     }
     return true;
 }
 protected static function buildPathToProductionResources()
 {
     $repo_path = rtrim(Config::$REPO_PATH, "/");
     self::$production_resources_path = realpath(getcwd() . DS . $repo_path) . DS . strtolower(Config::$TASK_APPLICATION_ID) . DS . Config::$RELATIVE_PATH;
     Log::writeInfo("Build path to production resources : " . self::$production_resources_path, "file");
 }
 protected function parseFile($path)
 {
     $code = file_get_contents($path);
     $matches_class = '';
     //check if exist any class in file
     if (preg_match('/^(.*?)?class(\\s)+(.*?)(\\s)?(\\n*?)?(\\s*){$/m', $code, $matches_class)) {
         $class_description = [];
         $tmp_class_name = explode(" ", $matches_class[3]);
         $class_description["name"] = array_shift($tmp_class_name);
         $class_description["path"] = $path;
         $file_name = basename($path, ".php");
         if ($file_name != $class_description["name"]) {
             $this->parsing_error["code"] = 3;
             $this->parsing_error["msg"] = "File {$file_name}.php contains a class " . $class_description["name"] . " that does not match with file name";
             Log::writeError("Hosted Service: Not found implementation for '" . Config::$CORE["hosted_interface_name"] . "'", 'file');
         }
         //parse namespace
         $namespace = [];
         preg_match("/^.*namespace\\s(.*?);.*\$/m", $code, $namespace);
         if (isset($namespace[1])) {
             $class_description["namespace"] = $namespace[1];
         } else {
             $class_description["namespace"] = null;
         }
         $matches_implementation = [];
         //check if interface implementation
         if (preg_match('/^.*implements(\\s*)(.*?)(' . $this->base_interface_name . ')(.*)$/m', $matches_class[3], $matches_implementation)) {
             if ($this->is_exist_interface == true) {
                 throw new CodeRunnerException("Multiple services has been found. Currently only one service per project is allowed. Please make sure there is only service in the project and try again.");
             }
             $this->is_exist_interface = true;
             $this->interface_implementation_info = $class_description;
             return null;
         } else {
             return $class_description;
         }
     } else {
         Log::writeInfo("Hosted Service persing: skip file " . $path, 'file');
         return null;
     }
 }
 protected static function putToHolder($class_info)
 {
     if (!isset(self::$classes_holder[$class_info['class_name']])) {
         self::$classes_holder[$class_info['class_name']] = $class_info;
     } else {
         Log::writeError("Folder with user classes contains duplicate declaration of class : \"" . $class_info['class_name'] . "\".");
         exit;
     }
 }
 private function initEventModel()
 {
     Log::write("Init event model for appVersionId : " . $this->app_version_id, $target = "file");
     $this->event_handlers_model = EventModelParser::getInstance()->parseProductionModel($this->app_version_id);
 }
 public static function phpEnviromentInit()
 {
     if (GlobalState::$TYPE === 'LOCAL') {
         //for LOCAL use user time zone or UTC if not set
         $timezone = @date_default_timezone_get();
         // if not set default timezone set as UTC
         if ($timezone == 'UTC') {
             date_default_timezone_set('UTC');
         }
     } else {
         date_default_timezone_set('UTC');
         // for CLOUDE use UTC
     }
     // check if available openssl for use https
     if (!extension_loaded("openssl")) {
         Log::writeWarn('PHP module "openssl" not installed or not switch on in php.ini file', $target = 'file');
         Config::setServerUrl(preg_replace('/^http:\\/\\/|https:\\/\\/(.*)$/', 'http://${1}', Config::$SERVER_URL));
         Log::writeWarn('All https requests to ' . Config::$SERVER_URL . 'changed on http requests', $target = 'file');
     }
 }
Beispiel #27
0
<?php

//enable the display of errors
error_reporting(E_ALL);
ini_set('display_errors', true);
use backendless\core\lib\Autoload;
use backendless\core\RedisManager;
use backendless\core\Config;
use backendless\core\lib\Log;
use backendless\core\CodeRunnerLoader;
// define short constants
define('DS', DIRECTORY_SEPARATOR);
define('BP', dirname(dirname(__FILE__)));
//include file with backendkess autoloader
include "lib" . DS . "Autoload.php";
//include file with predis autoloader
include "lib" . DS . "predis" . DS . "autoload.php";
// initialize app autoloading
Autoload::register();
Autoload::addNamespace('backendless\\core', BP . DS . 'core');
Config::loadConfig();
CodeRunnerLoader::phpEnviromentInit();
Log::init("LOCAL", false, Config::$CORE['os_type']);
$predis = RedisManager::getInstance()->getRedis();
$predis->rpush(Config::$APPLICATION_ID, Config::$CORE['local_shutdown_code']);
$predis->expire(Config::$APPLICATION_ID, 5);
echo "\n";
Log::writeInfo("CodeRunner Backendless debugging utility stopped!\n", $target = "console");