src/Application.php
public static function remoteAppCall($appId, \Closure $callback, \Closure $filterConfigCallback = null) {

        if ($callback === null || !$callback instanceof \Closure) {
            throw new InvalidParamException("Invalid param: `callback`.");
        }

        if ($appId !== Yii::$app->id && isset(Yii::$app->params[static::$remoteAppConfigs])) {

            if (!isset(Yii::$app->params[static::$remoteAppConfigs][$appId])) {
                throw new InvalidParamException("Invalid param: `appId`.");
            }
            if (!is_array(Yii::$app->params[static::$remoteAppConfigs][$appId])) {
                throw new InvalidConfigException("Invalid config: Yii::$app->params[" . static::$remoteAppConfigs . "][$appId].");
            }
            if (isset(Yii::$app->params[static::$remoteAppConfigs][$appId]['class'])) {
                $appClass = Yii::$app->params[static::$remoteAppConfigs][$appId]['class'];
                unset(Yii::$app->params[static::$remoteAppConfigs][$appId]['class']);
            } else {
                $appClass = get_called_class();
            }

            // Save the original app to a temp app.
            $yiiApp = Yii::$app;
            ///[1.0.1 (fix:bug:i18n is invalid after Application::remoteAppCall('app-frontend'))]
            $yiiAliases = Yii::$aliases;

            // Create empty config array.
            $config = [];

            // Assemble configuration for the current app.
            foreach (Yii::$app->params[static::$remoteAppConfigs][$appId] as $configPath) {
                // Merge every new configuration with the old config array.
                $config = ArrayHelper::merge($config, require (Yii::getAlias($configPath)));
            }

            // Call filter config callback function
            if ($filterConfigCallback !== null || $filterConfigCallback instanceof \Closure) {
                $config = call_user_func($filterConfigCallback, $config);
            }

            // Create a new app using the config array.
            $app = new $appClass($config); ///[v0.12.1 (UGD# replace component/application into yongtiger/appliaction)]

            // Call callback function by using the new app
            call_user_func($callback, $app);

            // Dump the new app
            unset($app);

            // Switch back to the original app.
            Yii::$app = $yiiApp;
            ///[1.0.1 (fix:bug:i18n is invalid after Application::remoteAppCall('app-frontend'))]
            Yii::$aliases = $yiiAliases;    

            // Dump the temp app
            unset($yiiApp, $yiiAliases);    ///[1.0.1 (fix:bug:i18n is invalid after Application::remoteAppCall('app-frontend'))]
            
        } else {
            call_user_func($callback, Yii::$app);
        }
    }
public static function remoteAppCall($appId, \Closure $callback, \Closure $filterConfigCallback = null) {

        if ($callback === null || !$callback instanceof \Closure) {
            throw new InvalidParamException("Invalid param: `callback`.");
        }

        if ($appId !== Yii::$app->id && isset(Yii::$app->params[static::$remoteAppConfigs])) {

            if (!isset(Yii::$app->params[static::$remoteAppConfigs][$appId])) {
                throw new InvalidParamException("Invalid param: `appId`.");
            }
            if (!is_array(Yii::$app->params[static::$remoteAppConfigs][$appId])) {
                throw new InvalidConfigException("Invalid config: Yii::$app->params[" . static::$remoteAppConfigs . "][$appId].");
            }
            if (isset(Yii::$app->params[static::$remoteAppConfigs][$appId]['class'])) {
                $appClass = Yii::$app->params[static::$remoteAppConfigs][$appId]['class'];
                unset(Yii::$app->params[static::$remoteAppConfigs][$appId]['class']);
            } else {
                $appClass = get_called_class();
            }

            // Save the original app to a temp app.
            $yiiApp = Yii::$app;
            ///[1.0.1 (fix:bug:i18n is invalid after Application::remoteAppCall('app-frontend'))]
            $yiiAliases = Yii::$aliases;

            // Create empty config array.
            $config = [];

            // Assemble configuration for the current app.
            foreach (Yii::$app->params[static::$remoteAppConfigs][$appId] as $configPath) {
                // Merge every new configuration with the old config array.
                $config = ArrayHelper::merge($config, require (Yii::getAlias($configPath)));
            }

            // Call filter config callback function
            if ($filterConfigCallback !== null || $filterConfigCallback instanceof \Closure) {
                $config = call_user_func($filterConfigCallback, $config);
            }

            // Create a new app using the config array.
            $app = new $appClass($config); ///[v0.12.1 (UGD# replace component/application into yongtiger/appliaction)]

            // Call callback function by using the new app
            call_user_func($callback, $app);

            // Dump the new app
            unset($app);

            // Switch back to the original app.
            Yii::$app = $yiiApp;
            ///[1.0.1 (fix:bug:i18n is invalid after Application::remoteAppCall('app-frontend'))]
            Yii::$aliases = $yiiAliases;    

            // Dump the temp app
            unset($yiiApp, $yiiAliases);    ///[1.0.1 (fix:bug:i18n is invalid after Application::remoteAppCall('app-frontend'))]
            
        } else {
            call_user_func($callback, Yii::$app);
        }
    }
public static function remoteAppCall ( $ appId , \ Closure $ callback , \ Closure $ filterConfigCallback = null ) { if ( $ callback === null || ! $ callback instanceof \ Closure ) { throw new InvalidParamException ( "Invalid param: `callback`." ) ; } if ( $ appId !== Yii :: $ app -> id && isset ( Yii :: $ app -> params [ static :: $ remoteAppConfigs ] ) ) { if ( ! isset ( Yii :: $ app -> params [ static :: $ remoteAppConfigs ] [ $ appId ] ) ) { throw new InvalidParamException ( "Invalid param: `appId`." ) ; } if ( ! is_array ( Yii :: $ app -> params [ static :: $ remoteAppConfigs ] [ $ appId ] ) ) { throw new InvalidConfigException ( "Invalid config: Yii::$app->params[" . static :: $ remoteAppConfigs . "][$appId]." ) ; } if ( isset ( Yii :: $ app -> params [ static :: $ remoteAppConfigs ] [ $ appId ] [ 'class' ] ) ) { $ appClass = Yii :: $ app -> params [ static :: $ remoteAppConfigs ] [ $ appId ] [ 'class' ] ; unset ( Yii :: $ app -> params [ static :: $ remoteAppConfigs ] [ $ appId ] [ 'class' ] ) ; } else { $ appClass = get_called_class ( ) ; } // Save the original app to a temp app. $ yiiApp = Yii :: $ app ; ///[1.0.1 (fix:bug:i18n is invalid after Application::remoteAppCall('app-frontend'))] $ yiiAliases = Yii :: $ aliases ; // Create empty config array. $ config = [ ] ; // Assemble configuration for the current app. foreach ( Yii :: $ app -> params [ static :: $ remoteAppConfigs ] [ $ appId ] as $ configPath ) { // Merge every new configuration with the old config array. $ config = ArrayHelper :: merge ( $ config , require ( Yii :: getAlias ( $ configPath ) ) ) ; } // Call filter config callback function if ( $ filterConfigCallback !== null || $ filterConfigCallback instanceof \ Closure ) { $ config = call_user_func ( $ filterConfigCallback , $ config ) ; } // Create a new app using the config array. $ app = new $ appClass ( $ config ) ; ///[v0.12.1 (UGD# replace component/application into yongtiger/appliaction)] // Call callback function by using the new app call_user_func ( $ callback , $ app ) ; // Dump the new app unset ( $ app ) ; // Switch back to the original app. Yii :: $ app = $ yiiApp ; ///[1.0.1 (fix:bug:i18n is invalid after Application::remoteAppCall('app-frontend'))] Yii :: $ aliases = $ yiiAliases ; // Dump the temp app unset ( $ yiiApp , $ yiiAliases ) ; ///[1.0.1 (fix:bug:i18n is invalid after Application::remoteAppCall('app-frontend'))] } else { call_user_func ( $ callback , Yii :: $ app ) ; } }
Call callback function with a remote application.

@param string $appId
@param Closure $callback
@throws InvalidParamException|InvalidConfigException
Call callback function with a remote application .