예제 #1
0
 public function setup()
 {
     /***
      * The very basic paths
      */
     if (!defined('XAPP_BASEDIR')) {
         define("XAPP_BASEDIR", xapp_get_option(self::BASEDIR, $this));
     }
     if (!defined('XAPP_LIB')) {
         define("XAPP_LIB", XAPP_BASEDIR . DIRECTORY_SEPARATOR . "lib" . DIRECTORY_SEPARATOR);
     }
     /***
      * Load utils
      */
     if (!class_exists('XApp_Service_Entry_Utils')) {
         include_once XAPP_BASEDIR . 'XApp_Service_Entry_Utils.php';
     }
     /***
      * Get run-time configuration, there is 'debug' and 'release'. For both cases there are
      * different resources to load.
      */
     $XAPP_RUN_TIME_CONFIGURATION = XApp_Service_Utils::_getKey('rtConfig', XApp_Service_Entry_Utils::getRunTimeConfiguration());
     /***
      * Now include all xapp stuff
      */
     //pull in parts of xapp core framework
     XApp_Service_Entry_Utils::includeXAppCore();
     //pull in registry of xapp core framework
     XApp_Service_Entry_Utils::includeXAppRegistry();
     //pull in parts of xapp json framework
     XApp_Service_Entry_Utils::includeXAppJSONStoreClasses();
     //pull in json utils (to read client app's resource configuration
     XApp_Service_Entry_Utils::includeXAppJSONTools();
     //some debugging tools
     XApp_Service_Entry_Utils::includeXAppDebugTools();
     //pull in legacy client app renderer
     xapp_import('xapp.app.Renderer');
     self::loadCommons();
     //pull in xapp commander renderer
     /*include_once(XAPP_BASEDIR . DIRECTORY_SEPARATOR . 'app'. DIRECTORY_SEPARATOR . 'Commander.php');*/
     //pull in xapp resource renderer
     include_once XAPP_BASEDIR . '/Resource/Renderer.php';
     //pull in xapp resource renderer
     xapp_import('xapp.commander.Resource.Renderer');
     //pull in xapp resource renderer
     xapp_import('xapp.Resource.Renderer');
     //pull in xide resource Renderer
     xapp_import('xapp.xide.Resource.Renderer');
     //pull in xide resource Renderer
     //xapp_import('xapp.xcf.Resource.Renderer');
     //pull in cms related resource renderer
     include_once XAPP_LIB . DIRECTORY_SEPARATOR . xapp_get_option(self::RESOURCE_RENDERER_PREFIX, $this) . DIRECTORY_SEPARATOR . 'ResourceRenderer.php';
     /***
      * Prepare resource renderer
      */
     //clients resource config path
     $XAPP_RESOURCE_CONFIG_PATH = '' . xapp_get_option(self::APPDIR, $this) . DIRECTORY_SEPARATOR;
     $XAPP_RESOURCE_CONFIG = xapp_get_option(self::XAPP_RESOURCE_CONFIG, $this);
     if (strlen($XAPP_RESOURCE_CONFIG)) {
         if ($XAPP_RUN_TIME_CONFIGURATION === 'debug') {
             $XAPP_RESOURCE_CONFIG_PATH .= 'lib' . DIRECTORY_SEPARATOR . xapp_get_option(self::APP_NAME, $this) . DIRECTORY_SEPARATOR . $XAPP_RESOURCE_CONFIG . xapp_get_option(self::RESOURCE_CONFIG_SUFFIX, $this) . '.json';
         } else {
             if ($XAPP_RUN_TIME_CONFIGURATION === 'release') {
                 $XAPP_RESOURCE_CONFIG_PATH .= DIRECTORY_SEPARATOR . xapp_get_option(self::APP_FOLDER, $this) . DIRECTORY_SEPARATOR . xapp_get_option(self::APP_NAME, $this) . DIRECTORY_SEPARATOR . $XAPP_RESOURCE_CONFIG . xapp_get_option(self::RESOURCE_CONFIG_SUFFIX, $this) . '.json';
             }
         }
     } else {
         if ($XAPP_RUN_TIME_CONFIGURATION === 'debug') {
             $XAPP_RESOURCE_CONFIG_PATH .= 'lib' . DIRECTORY_SEPARATOR . xapp_get_option(self::APP_NAME, $this) . DIRECTORY_SEPARATOR . 'resources-' . $XAPP_RUN_TIME_CONFIGURATION . xapp_get_option(self::RESOURCE_CONFIG_SUFFIX, $this) . '.json';
         } else {
             if ($XAPP_RUN_TIME_CONFIGURATION === 'release') {
                 $XAPP_RESOURCE_CONFIG_PATH .= DIRECTORY_SEPARATOR . xapp_get_option(self::APP_FOLDER, $this) . DIRECTORY_SEPARATOR . xapp_get_option(self::APP_NAME, $this) . DIRECTORY_SEPARATOR . 'resources-' . $XAPP_RUN_TIME_CONFIGURATION . xapp_get_option(self::RESOURCE_CONFIG_SUFFIX, $this) . '.json';
             }
         }
     }
     //error_log('$XAPP_RESOURCE_CONFIG ' . $XAPP_RESOURCE_CONFIG . "   =  " . $XAPP_RESOURCE_CONFIG_PATH);
     if (!file_exists($XAPP_RESOURCE_CONFIG_PATH)) {
         $this->log('have no core resources, ' . $XAPP_RESOURCE_CONFIG_PATH . ' doesnt exists');
         return null;
     }
     $resources = (object) XApp_Utils_JSONUtils::read_json($XAPP_RESOURCE_CONFIG_PATH, 'json', false, true);
     $pluginResources = null;
     /***
      * Load plugin resources
      */
     if (xapp_get_option(self::ALLOW_PLUGINS, $this) && xapp_get_option(self::PLUGIN_DIRECTORY, $this) && xapp_get_option(self::PLUGIN_DIRECTORY, $this)) {
         //pull in xapp plugin manager
         include_once XAPP_BASEDIR . '/commander/PluginManager.php';
         //pull in xapp commander plugin base class
         include_once XAPP_BASEDIR . '/commander/Plugin.php';
         //pull in RPC interface
         if (!class_exists('Xapp_Rpc_Interface_Callable')) {
             //pull in xapp commander plugin base class
             include_once XAPP_BASEDIR . '/Rpc/Interface/Callable.php';
         }
         $xComPluginManager = new XApp_Commander_PluginManager();
         $loadedPlugins = null;
         $plugins = $xComPluginManager->loadPlugins(xapp_get_option(self::PLUGIN_DIRECTORY, $this), xapp_get_option(self::PLUGIN_DIRECTORY, $this), xapp_get_option(self::PLUGIN_MASK, $this));
         $pluginResources = $this->getPluginResources($plugins, $XAPP_RUN_TIME_CONFIGURATION, $XAPP_RESOURCE_CONFIG);
     }
     //error_log('flags ' . json_encode(xapp_get_option(self::FLAGS, $this)));
     //now merge into app resources, filtered
     if ($pluginResources) {
         foreach ($pluginResources as $pluginResourceItems) {
             foreach ($pluginResourceItems as $pluginResource) {
                 $prohibited = explode(',', xapp_get_option(self::PROHIBITED_PLUGINS, $this));
                 if (property_exists($pluginResource, 'type') && property_exists($pluginResource, 'name')) {
                     //is plugin item
                     if (in_array('X' . $pluginResource->name, $prohibited)) {
                         continue;
                     } else {
                         array_push($resources->items, $pluginResource);
                     }
                 } else {
                     array_push($resources->items, $pluginResource);
                 }
             }
         }
     }
     $resourceRendererOptions = array(XApp_Resource_Renderer::DOC_ROOT => xapp_get_option(self::DOC_ROOT, $this), XApp_Resource_Renderer::DOC_ROOT_PATH => xapp_get_option(self::APPDIR, $this), XApp_Resource_Renderer::RESOURCES_DATA => $resources, XApp_Resource_Renderer::RENDER_DELEGATE => xapp_get_option(self::RENDER_DELEGATE, $this));
     $clz = xapp_get_option(self::RESOURCE_RENDERER_CLZ, $this);
     $xappResourceRenderer = new $clz($resourceRendererOptions);
     $xappResourceRenderer->registerDefault();
     if (xapp_has_option(self::RELATIVE_VARIABLES)) {
         $rVariables = xapp_get_option(self::RELATIVE_VARIABLES, $this);
         if ($rVariables != null && count($rVariables)) {
             foreach ($rVariables as $variable => $value) {
                 $xappResourceRenderer->registerRelative($variable, $value);
             }
         }
     }
     $XAPP_DOJO_PACKAGES = '[]';
     $XAPP_DOJO_PACKAGE_LOCATION_PREFIX = $xappResourceRenderer->resolveRelative('%PLUGIN_PACKAGE_ROOT_URL%');
     $javascriptPlugins = $xappResourceRenderer->getJavascriptPlugins();
     if ($javascriptPlugins && count($javascriptPlugins)) {
         if (XApp_Service_Entry_Utils::isDebug()) {
             $dojoPackages = array();
             $dojoPackagesStr = '[';
             $pIdx = 0;
             foreach ($javascriptPlugins as $plugin) {
                 if (!is_object($plugin)) {
                     continue;
                 }
                 if ($pIdx > 0) {
                     $dojoPackagesStr .= ",";
                 }
                 $dojoPackagesStr .= "{name:" . "'" . $plugin->name . "',";
                 if (property_exists($plugin, 'packageLocation')) {
                     $dojoPackagesStr .= "location:" . "'" . $plugin->packageLocation . "'}";
                 } else {
                     $dojoPackagesStr .= "location:" . "'" . $XAPP_DOJO_PACKAGE_LOCATION_PREFIX . $plugin->name . '/client/' . "'}";
                 }
                 if ($pIdx < count($javascriptPlugins) - 1) {
                     $dojoPackagesStr .= ',';
                 }
             }
             $dojoPackagesStr .= ']';
             $XAPP_DOJO_PACKAGES = $dojoPackagesStr;
         } else {
             $packageSuffix = "";
             $dojoPackages = array();
             array_push($dojoPackages, array('name' => 'dojo', 'location' => 'dojo'));
             array_push($dojoPackages, array('name' => 'dojox', 'location' => 'dojox'));
             array_push($dojoPackages, array('name' => 'dijit', 'location' => 'dijit'));
             array_push($dojoPackages, array('name' => 'cbtree', 'location' => 'cbtree'));
             array_push($dojoPackages, array('name' => 'xfile', 'location' => 'xfile'));
             array_push($dojoPackages, array('name' => 'xide', 'location' => 'xide'));
             array_push($dojoPackages, array('name' => 'xwordpress', 'location' => 'xwordpress'));
             array_push($dojoPackages, array('name' => 'xbox', 'location' => 'xbox'));
             array_push($dojoPackages, array('name' => 'xjoomla', 'location' => 'xjoomla'));
             foreach ($javascriptPlugins as $plugin) {
                 if (is_object($plugin)) {
                     if (property_exists($plugin, 'packageSuffix')) {
                         $packageSuffix = $plugin->{'packageSuffix'};
                     }
                     $packageLocation = $XAPP_DOJO_PACKAGE_LOCATION_PREFIX . $plugin->name . '/client/';
                     if (strlen($packageSuffix)) {
                         $packageLocation .= $packageSuffix . '/';
                     }
                     if (property_exists($plugin, 'packageLocation')) {
                         $packageLocation = $plugin->packageLocation;
                     }
                     array_push($dojoPackages, array('name' => $plugin->name, 'location' => $packageLocation));
                 }
             }
             $XAPP_DOJO_PACKAGES = json_encode($dojoPackages);
         }
         /****
          * Render plugin resources
          */
         $javaScriptHeaderStr = '';
         $javaScriptHeaderStr .= 'var xappPluginResources=';
         $javaScriptHeaderStr .= json_encode($javascriptPlugins) . ';';
         $javaScriptHeaderStr .= '';
         $xappResourceRenderer->registerRelative('XAPP_PLUGIN_RESOURCES', json_encode($javascriptPlugins));
         //important: get the resource variables before adding 'head' otherwise it breaks the JSON structure!
         $resourceVariables = (array) $xappResourceRenderer->registryToKeyValues(xapp_get_option(XApp_Resource_Renderer::RELATIVE_REGISTRY_NAMESPACE, $xappResourceRenderer));
         $resourceVariables['HTML_HEADER'] = array();
         $resourceVariables['XAPP_PLUGIN_RESOURCES'] = $javascriptPlugins;
         $resourceVariables['DOJOPACKAGES'] = array();
         $resourceVariables['XFILE_CONFIG_MIXIN'] = array();
         $resourceVariables['RESOURCE_VARIABLES'] = array();
         $xappResourceRenderer->registerRelative('RESOURCE_VARIABLES', Xapp_Util_Json::prettify(json_encode($resourceVariables, true)), LOCK_EX);
     }
     $xappResourceRenderer->registerRelative('DOJOPACKAGES', $XAPP_DOJO_PACKAGES);
     $pConfigDefault = $xappResourceRenderer->resolveRelative('%PACKAGE_CONFIG%');
     if (!strlen($pConfigDefault)) {
         $pConfigDefault = 'run-release-debug';
     }
     //error_log('$pConfigDefault ' .$pConfigDefault);
     $xappResourceRenderer->registerRelative('PACKAGE_CONFIG', XApp_Service_Utils::_getKey('pConfig', $pConfigDefault));
     /****
      * Build XApp-App-Renderer - Config
      */
     $opt = array(XApp_App_Commander::DOC_ROOT_PATH => xapp_get_option(self::APPDIR, $this), XApp_App_Commander::DOC_ROOT => xapp_get_option(self::DOC_ROOT, $this), XApp_App_Commander::APP_NAME => xapp_get_option(self::APP_NAME, $this), XApp_App_Commander::APP_FOLDER => xapp_get_option(self::APP_FOLDER, $this), XApp_App_Commander::CONFIG_NAME => $XAPP_RUN_TIME_CONFIGURATION, XApp_App_Commander::SERVICE_URL => xapp_get_option(self::SERVICE, $this), XApp_App_Commander::RESOURCE_RENDERER => $xappResourceRenderer);
     $xappAppRenderer = new XApp_App_Commander($opt);
     $this->appRenderer = $xappAppRenderer;
     $this->resourceRenderer = $xappResourceRenderer;
     return $xappAppRenderer;
 }
예제 #2
0
 public function init()
 {
     $flags = xapp_get_option(self::FLAGS, $this);
     self::$_instance = $this;
     /***
      * The very basic paths
      */
     if (!defined('XAPP_BASEDIR')) {
         define("XAPP_BASEDIR", xapp_get_option(self::BASEDIR, $this));
     }
     if (!defined('XAPP_LIB')) {
         define("XAPP_LIB", XAPP_BASEDIR . DIRECTORY_SEPARATOR . "lib" . DIRECTORY_SEPARATOR);
     }
     /***
      * Load utils
      */
     if (!class_exists('XApp_Service_Entry_Utils')) {
         include_once XAPP_BASEDIR . 'XApp_Service_Entry_Utils.php';
     }
     /***
      * Get run-time configuration, there is 'debug' and 'release'. For both cases there are
      * different resources to load.
      */
     $XAPP_RUN_TIME_CONFIGURATION = XApp_Service_Entry_Utils::getRunTimeConfiguration();
     /***
      * Load dependencies
      */
     $this->loadDependencies(xapp_get_option(self::FLAGS, $this));
     //some debugging tools
     XApp_Service_Entry_Utils::includeXAppDebugTools();
     $plugins = null;
     $pluginResources = null;
     $xComPluginManager = null;
     $logger = null;
     $loggingFlags = xapp_has_option(self::LOGGING_FLAGS, $this) ? xapp_get_option(self::LOGGING_FLAGS, $this) : array();
     /***
      * Setup Logger
      */
     if (in_array(XAPP_BOOTSTRAP_SETUP_LOGGER, $flags) && xapp_has_option(self::LOGGING_CONF, $this)) {
         $logger = $this->setupLogger(xapp_get_option(self::LOGGING_CONF));
         xapp_set_option(self::LOGGER, $logger, $this);
         if (!function_exists('xp_log')) {
             function xp_log($message)
             {
                 $bootstrap = XApp_Bootstrap::instance();
                 $log = xapp_get_option(XApp_Bootstrap::LOGGER, $bootstrap);
                 $log->log($message);
             }
         }
     } else {
         if (!function_exists('xp_log')) {
             //fake logger
             function xp_log($message)
             {
             }
         }
     }
     /***
      * Setup XApp-PHP
      */
     if (in_array(XAPP_BOOTSTRAP_SETUP_XAPP, $flags)) {
         $this->setupXApp(xapp_has_option(self::XAPP_CONF, $this) ? xapp_get_option(self::XAPP_CONF, $this) : null);
     }
     /***
      * Setup RPC Server
      */
     if (in_array(XAPP_BOOTSTRAP_SETUP_RPC, $flags)) {
         $this->setupRPC();
     }
     $storeService = null;
     /***
      * Setup storage
      */
     if (in_array(XAPP_BOOTSTRAP_SETUP_STORE, $flags) && xapp_has_option(self::STORE_CONF, $this)) {
         $storeService = $this->setupStore(xapp_get_option(self::STORE_CONF, $this));
         //$this->testStore($storeService);
         xapp_set_option(self::STORE, $storeService, $this);
     }
     /***
      * Prepare resource renderer
      */
     if (in_array(XAPP_BOOTSTRAP_LOAD_CLIENT_RESOURCES, $flags)) {
         //clients resource config path
         $XAPP_RESOURCE_CONFIG_PATH = '' . xapp_get_option(self::APPDIR, $this) . DIRECTORY_SEPARATOR;
         if ($XAPP_RUN_TIME_CONFIGURATION === 'debug') {
             $XAPP_RESOURCE_CONFIG_PATH .= 'lib' . DIRECTORY_SEPARATOR . xapp_get_option(self::APP_NAME, $this) . DIRECTORY_SEPARATOR . 'resources-' . $XAPP_RUN_TIME_CONFIGURATION . xapp_get_option(self::RESOURCE_CONFIG_SUFFIX, $this) . '.json';
         } else {
             if ($XAPP_RUN_TIME_CONFIGURATION === 'release') {
                 $XAPP_RESOURCE_CONFIG_PATH .= DIRECTORY_SEPARATOR . xapp_get_option(self::APP_FOLDER, $this) . DIRECTORY_SEPARATOR . xapp_get_option(self::APP_NAME, $this) . DIRECTORY_SEPARATOR . 'resources-' . $XAPP_RUN_TIME_CONFIGURATION . xapp_get_option(self::RESOURCE_CONFIG_SUFFIX, $this) . '.json';
             }
         }
     }
     /***
      * Load plugin resources
      */
     if (in_array(XAPP_BOOTSTRAP_LOAD_PLUGIN_RESOURCES, $flags) || in_array(XAPP_BOOTSTRAP_REGISTER_SERVER_PLUGINS, $flags)) {
         if (xapp_get_option(self::ALLOW_PLUGINS, $this) && xapp_get_option(self::PLUGIN_DIRECTORY, $this) && xapp_get_option(self::PLUGIN_DIRECTORY, $this)) {
             if (!$xComPluginManager) {
                 $xComPluginManager = new XApp_Commander_PluginManager();
             }
             $pluginResources = $xComPluginManager->getPluginResources(xapp_get_option(self::PLUGIN_DIRECTORY, $this), xapp_get_option(self::PLUGIN_DIRECTORY, $this), xapp_get_option(self::PLUGIN_MASK, $this));
         }
     }
     /***
      * Get plugins
      */
     if (in_array(XAPP_BOOTSTRAP_REGISTER_SERVER_PLUGINS, $flags)) {
         if (xapp_get_option(self::ALLOW_PLUGINS, $this) && xapp_get_option(self::PLUGIN_DIRECTORY, $this) && xapp_get_option(self::PLUGIN_DIRECTORY, $this)) {
             if (!$xComPluginManager) {
                 $xComPluginManager = new XApp_Commander_PluginManager();
             }
             $plugins = $xComPluginManager->getPlugins(xapp_get_option(self::PLUGIN_DIRECTORY, $this), xapp_get_option(self::PLUGIN_MASK, $this));
         } else {
         }
     }
     $pluginInstances = array();
     /***
      * Register server plugins
      */
     if ($xComPluginManager !== null && count($plugins) && xapp_get_option(self::RPC_SERVER, $this) && in_array(XAPP_BOOTSTRAP_REGISTER_SERVER_PLUGINS, $flags)) {
         switch (XApp_Service_Entry_Utils::getServiceType()) {
             /***
              * JSON-RPC-2.0 call. In this case we are only loading the plugin which has been specified in the RPC call('service')
              */
             case XApp_Service_Entry_Utils::SMD_CALL:
                 /***
                  * Load the plugin by its service class name. A RPC POST request looks like this :
                  * {
                  * "id": 0,
                  * "method": "Xapp_FileService.rename",
                  * "params": {
                  * "path": "./tmp/wp-mail.php",
                  * "newFileName": "wp-mail.php2"
                  * },
                  * "jsonrpc": "2.0"
                  * }
                  *
                  * In case we go over JSONP, the url looks like this :
                  *
                  * http://0.0.0.0/zoo254/components/com_xas/xapp/index.php?service=XLESS.test&id=4&callback=as
                  *
                  */
                 $method = XApp_Service_Entry_Utils::getSMDMethod();
                 $serviceClass = null;
                 if ($method != null && strpos($method, '.') != -1) {
                     $methodSplitted = explode('.', $method);
                     if ($methodSplitted && count($methodSplitted) == 2) {
                         $serviceClass = $methodSplitted[0];
                     }
                 }
                 if ($serviceClass) {
                     if (in_array(XAPP_LOG_PLUGIN_CREATION, $loggingFlags)) {
                         $this->log('Calling service class::' . $serviceClass);
                     }
                     foreach ($plugins as $pluginConfig) {
                         //load only when not prohibited
                         $prohibited = explode(',', xapp_get_option(self::PROHIBITED_PLUGINS, $this));
                         if (!in_array($serviceClass, $prohibited)) {
                             if ($pluginConfig !== null && is_object($pluginConfig)) {
                                 //pull in if not done yet
                                 if (!class_exists($pluginConfig->name)) {
                                     $pluginPath = xapp_get_option(self::PLUGIN_DIRECTORY, $this) . DIRECTORY_SEPARATOR . $pluginConfig->location . DIRECTORY_SEPARATOR . $pluginConfig->name . '.php';
                                     if (in_array(XAPP_LOG_PLUGIN_CREATION, $loggingFlags)) {
                                         $this->log('loading plugin ' . $pluginConfig->name . ' at ' . $pluginPath);
                                     }
                                     if (file_exists($pluginPath)) {
                                         include_once $pluginPath;
                                     } else {
                                         continue;
                                     }
                                 }
                                 //create instance
                                 if (class_exists($serviceClass)) {
                                     $plugin = $xComPluginManager->createPluginInstance($pluginConfig->name, true, array(), array(), xapp_get_options(), $pluginConfig);
                                     if ($plugin != null) {
                                         xapp_get_option(self::RPC_SERVER)->register($plugin, array('_load'));
                                         array_push($pluginInstances, $plugin);
                                         //share logger
                                         if (in_array(XAPP_LOG_SHARED_LOGGER_PLUGINS, $loggingFlags) && $logger) {
                                             $plugin->_setLogger($logger);
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
                 break;
                 /***
                  * JSON-RPC-2.0 Service Introspection. That means we expose all plugins as Dojo SMD! You can see the full RPC class by opening http://localhost/joomla251/administrator/index.php?option=com_xappcommander&view=rpc
                  */
             /***
              * JSON-RPC-2.0 Service Introspection. That means we expose all plugins as Dojo SMD! You can see the full RPC class by opening http://localhost/joomla251/administrator/index.php?option=com_xappcommander&view=rpc
              */
             case XApp_Service_Entry_Utils::SMD_GET:
                 foreach ($plugins as $pluginConfig) {
                     /***
                      * Skip black listed plugins
                      */
                     $prohibited = explode(',', xapp_get_option(self::PROHIBITED_PLUGINS, $this));
                     if (in_array($pluginConfig->name, $prohibited)) {
                         continue;
                     }
                     //show only if the plugins wants to be exposed!
                     if (property_exists($pluginConfig, 'showSMD') && $pluginConfig->showSMD == true) {
                         if (!class_exists($pluginConfig->name)) {
                             $pluginPath = xapp_get_option(self::PLUGIN_DIRECTORY, $this) . DIRECTORY_SEPARATOR . $pluginConfig->location . DIRECTORY_SEPARATOR . $pluginConfig->name . '.php';
                             if (in_array(XAPP_LOG_PLUGIN_CREATION, $loggingFlags)) {
                                 $this->log('loading plugin ' . $pluginConfig->name . ' at ' . $pluginPath);
                             }
                             if (file_exists($pluginPath)) {
                                 include_once $pluginPath;
                             } else {
                                 continue;
                             }
                         }
                         //now register as RPC class
                         if (class_exists($pluginConfig->name)) {
                             xapp_get_option(self::RPC_SERVER)->register($pluginConfig->name);
                         }
                     }
                 }
                 break;
         }
     }
     $xappFileService = null;
     /***
      * Setup file service
      */
     if (in_array(XAPP_BOOTSTRAP_SETUP_XFILE, $flags) && xapp_get_option(self::RPC_SERVER, $this) && xapp_has_option(self::XFILE_CONF, $this)) {
         $opt = xapp_get_option(self::XFILE_CONF, $this);
         $xappFileService = new Xapp_FileService($opt);
         $xappFileService::$rootDirectory = xapp_get_option(Xapp_FileService::REPOSITORY_ROOT, xapp_get_option(self::XFILE_CONF));
         xapp_get_option(self::RPC_SERVER)->register($xappFileService);
     }
     if ($xappFileService !== null && count($pluginInstances)) {
         foreach ($pluginInstances as $plugin) {
             $plugin->xfile = $xappFileService;
         }
     }
     /***
      * Setup store service
      */
     if ($storeService) {
         xapp_get_option(self::RPC_SERVER)->register($storeService);
     }
     /***
      * More services
      */
     if (in_array(XAPP_BOOTSTRAP_SETUP_SERVICES, $flags) && xapp_has_option(self::SERIVCE_CONF, $this) && xapp_get_option(self::RPC_SERVER, $this)) {
         //pull in registry of xapp core framework
         XApp_Service_Entry_Utils::includeXAppRegistry();
         $this->registerServices(xapp_get_option(self::SERIVCE_CONF), xapp_get_option(self::RPC_SERVER));
     }
     /***
      * Setup gateway
      */
     if (in_array(XAPP_BOOTSTRAP_SETUP_GATEWAY, $flags) && xapp_get_option(self::RPC_SERVER, $this)) {
         try {
             $needsSigning = false;
             $opt = xapp_has_option(self::GATEWAY_CONF) ? xapp_get_option(self::GATEWAY_CONF) : array();
             /***
              * Raise security and demand that the client did sign its request
              */
             $signServiceTypes = xapp_get_option(self::SIGNED_SERVICE_TYPES, $this);
             if (in_array(XApp_Service_Entry_Utils::getServiceType(), $signServiceTypes)) {
                 $needsSigning = true;
                 //set signed
                 $opt[Xapp_Rpc_Gateway::SIGNED_REQUEST] = true;
                 //complete configuration
                 if (!array_key_exists(Xapp_Rpc_Gateway::SIGNED_REQUEST_METHOD, $opt)) {
                     $opt[Xapp_Rpc_Gateway::SIGNED_REQUEST_METHOD] = 'user';
                 }
                 if (!array_key_exists(Xapp_Rpc_Gateway::SIGNED_REQUEST_USER_PARAM, $opt)) {
                     $opt[Xapp_Rpc_Gateway::SIGNED_REQUEST_USER_PARAM] = 'user';
                 }
                 //complete configuration
             }
             $this->setGatewayOptionArray(Xapp_Rpc_Gateway::ALLOW_IP, $opt);
             $this->setGatewayOptionArray(Xapp_Rpc_Gateway::DENY_IP, $opt);
             $this->setGatewayOptionArray(Xapp_Rpc_Gateway::ALLOW_HOST, $opt);
             $this->setGatewayOptionArray(Xapp_Rpc_Gateway::DENY_HOST, $opt);
             /***
              * Create the gateway
              */
             $gateway = Xapp_Rpc_Gateway::instance(xapp_get_option(self::RPC_SERVER, $this), $opt);
             /***
              * Set the API key for signed requests
              */
             if ($needsSigning) {
                 $gateway->addKey(xapp_get_option(self::SIGNING_KEY, $this), xapp_get_option(self::SIGNING_TOKEN, $this));
             }
             //$gateway->run();
             xapp_set_option(self::GATEWAY, $gateway, $this);
         } catch (Exception $e) {
             Xapp_Rpc_Server_Json::dump($e);
         }
     }
     return $this;
 }
예제 #3
0
 /**
  * Xapp_Singleton interface impl.
  *
  * static singleton method to create static instance of driver with optional third parameter
  * xapp options array or object
  *
  * @error 15501
  * @param null|mixed $options expects optional xapp option array or object
  * @return Xapp_Commander_Plugin
  */
 public static function instance($options = null)
 {
     if (self::$_instance === null) {
         self::$_instance = new self($options);
         self::$_instance->setup();
     }
     return self::$_instance;
 }