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 function parseProductionModel($app_version_id)
 {
     Log::writeInfo("Load production EventModel for appVersion: {$app_version_id}", $target = 'file');
     $event_handlers_model = new EventHandlersModel();
     try {
         $event_handlers_model->loadFromJson(PathBuilder::getProductionModel());
     } catch (Exeption $e) {
         Log::writeError("Can not parse Event Model from file: " . PathBuilder::getProductionModel() . " for appVersionId: " . $app_version_id, 'file');
     }
     return $event_handlers_model;
 }
 public static function load($argc, $argv)
 {
     Config::loadConfig();
     self::phpEnviromentInit();
     Log::init(GlobalState::$TYPE, Config::$CORE['logging_in_cloud_mode'], Config::$CORE['os_type']);
     Log::writeInfo("Start CodeRunner", $target = 'file');
     EventDefinitionHolder::getInstance()->load();
     if (GlobalState::$TYPE === 'LOCAL') {
         self::checkForInputKeys($argc, $argv);
         self::checkDefaultKeys();
         ClassManager::analyze(PathBuilder::getClasses());
         self::printGreeting();
     } else {
         self::checkInputKeysForCloud($argc, $argv);
     }
     $code_runner = new CodeRunner();
     $code_runner->loadMessageProcessor();
     $code_runner->start();
 }
예제 #5
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");
 }
 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);
 }