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 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: " . $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 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;
 }
 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 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 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 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');
 }
Esempio n. 11
0
 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");
     }
 }
 private function processAnalyze($provider_name, $provider_data, $class, $event_handlers_model)
 {
     Log::writeInfo("Processing analyzing class: " . $class['class_name'], $target = 'file');
     //ReflectionUtil::includeFile( $class['path'] );
     //ClassManager::addAsIncluded( $class['path'] );
     $reflection = new ReflectionClass("\\" . $class['namespace'] . "\\" . $class['class_name']);
     $methods = $reflection->getMethods(ReflectionMethod::IS_PUBLIC);
     $target = $this->getTarget($class);
     $timer_definition = self::$event_definition_holder->getDefinitionByName("TIMER", 'execute');
     $timer_id = $timer_definition['id'];
     $custom_handler_definition = self::$event_definition_holder->getDefinitionByName("CUSTOM", 'handleEvent');
     $custom_handler_id = $custom_handler_definition['id'];
     foreach ($methods as $method) {
         $definition = self::$event_definition_holder->getDefinitionByName($provider_name, $method->name);
         if ($definition == null) {
             continue;
         }
         $handler = new EventHandler();
         $handler->setId($definition['id']);
         $handler->setTarget($target);
         $handler->setAsync($this->getAsync($method->name, $class));
         $handler->setTimer($definition['id'] == $timer_id ? true : false);
         $handler->setProvider('\\' . $class['namespace'] . '\\' . $class['class_name']);
         if ($handler->isTimer()) {
             $handler->setTarget($this->getTimer($class));
             $handler->setAsync(true);
             if (!$this->isValidTimer($handler)) {
                 continue;
             }
         }
         if ($handler->getId() == $custom_handler_id) {
             $handler->setTarget($this->getCustomEventName($class));
             if ($handler->getTarget() == null) {
                 throw new CodeRunnerException("Asset is not present for custom event handler: " . $class['class_name']);
             }
         }
         if (Config::$CORE['provider'][$provider_name]['asset'] && $handler->getTarget() == null) {
             throw new CodeRunnerException("Asset is not present for handler: " . $class['class_name']);
         }
         $event_handlers_model->addHandler($handler);
     }
 }
Esempio n. 13
0
 public static function analyze()
 {
     Log::writeInfo("ClassManager start analyze classes", "file");
     $all_files = new RecursiveIteratorIterator(new RecursiveDirectoryIterator(PathBuilder::getClasses()));
     $php_files = new RegexIterator($all_files, '/\\.php$/');
     $classes_namespaces = [];
     foreach ($php_files as $php_file) {
         $class_info = [];
         //$class_info["parent_class"] = self::getParentClass( file_get_contents( $php_file->getRealPath() ) );
         $class_info['namespace'] = str_replace("/", "\\", trim(dirname(substr($php_file->getRealPath(), strlen(PathBuilder::getClasses()))), "/"));
         $class_info['class_name'] = basename($php_file->getRealPath(), ".php");
         $class_info['path'] = $php_file->getRealPath();
         self::putToHolder($class_info);
         $classes_namespaces[$class_info['namespace']] = pathinfo($class_info["path"])["dirname"];
         //key = namespace key = path to folder;
         Backendless::mapTableToClass($class_info['class_name'], $class_info['namespace'] . "\\" . $class_info['class_name']);
         // set mapping for SDK.
     }
     foreach ($classes_namespaces as $namespace => $path) {
         Autoload::addNamespace($namespace, $path);
         // add autoloading for user classes
     }
     Log::writeInfo("ClassManager finished analyze classes", "file");
 }
Esempio n. 14
0
 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;
     }
 }
Esempio n. 16
0
 public function doBuild()
 {
     $this->event_handlers_model = EventModelParser::getInstance()->parseDebugModel();
     Log::writeInfo("Build successfully: " . $this->event_handlers_model);
     GlobalState::$STATE = "BUILD";
 }
 private static function checkDefaultKeys()
 {
     if (!preg_match("/" . self::$VALID_PATTERN . "/", Config::$APPLICATION_ID, $matches) || !preg_match("/" . self::$VALID_PATTERN . "/", Config::$SECRET_KEY, $matches) || Config::$APP_VERSION == null) {
         echo "\n";
         Log::writeWarn("ApplicationID SecretKey application version is not set one or all values.", $target = 'console');
         Log::writeInfo("Try run again with specified ApplicationID SecretKey and application version as script arguments " . "or edit it in config file [root_folder]" . DS . "config.php", $target = 'console');
         Log::writeInfo("NOTE: Run script pattern <ScriptName> [ApplicationID] [SecretKey] [AppVersion]", $target = 'console');
         if (!preg_match("/" . self::$VALID_PATTERN . "/", Config::$APPLICATION_ID, $matches)) {
             echo "\n";
             Log::writeWarn("Don't set or wrong application ID value.", $target = 'console');
             Log::writeInfo("Please enter application ID and press [Enter]:!<new>", $target = 'console');
             Config::$APPLICATION_ID = trim(fgets(STDIN));
             while (!preg_match("/" . self::$VALID_PATTERN . "/", Config::$APPLICATION_ID, $matches)) {
                 Log::writeError("The value is invalid, please try again:!<new>", $target = 'console');
                 Config::$APPLICATION_ID = trim(fgets(STDIN));
             }
         }
         if (!preg_match("/" . self::$VALID_PATTERN . "/", Config::$SECRET_KEY, $matches)) {
             echo "\n";
             Log::writeWarn("Don't set or wrong CodeRunner secret key value.", $target = 'console');
             Log::writeInfo("Please enter CodeRunner secret key and press [Enter]:!<new>", $target = 'console');
             Config::$SECRET_KEY = trim(fgets(STDIN));
             while (!preg_match("/" . self::$VALID_PATTERN . "/", Config::$SECRET_KEY, $matches)) {
                 Log::writeError("The value is invalid, please try again:!<new>", $target = 'console');
                 Config::$SECRET_KEY = trim(fgets(STDIN));
             }
         }
         if (Config::$APP_VERSION == null) {
             echo "\n";
             Log::writeWarn("Don't set or wrong application version value.", $target = 'console');
             Log::writeInfo("Please enter application version and press [Enter]:!<new>", $target = 'console');
             Config::$APP_VERSION = trim(fgets(STDIN));
             while (Config::$APP_VERSION == null) {
                 Log::writeError("The value is invalid, please try again:!<new>", $target = 'console');
                 Config::$APP_VERSION = trim(fgets(STDIN));
             }
         }
         Config::$need_save_keys = true;
     }
 }
Esempio n. 18
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");
Esempio n. 19
0
 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 );
 }