Package app info for export.

@param $app

@return bool
@throws \DreamFactory\Core\Exceptions\InternalServerErrorException
354430
private function packageAppDescription($app)
    {
        $record = [
            'name'                    => $app->name,
            'description'             => $app->description,
            'is_active'               => $app->is_active,
            'type'                    => $app->type,
            'path'                    => $app->path,
            'url'                     => $app->url,
            'requires_fullscreen'     => $app->requires_fullscreen,
            'allow_fullscreen_toggle' => $app->allow_fullscreen_toggle,
            'toggle_location'         => $app->toggle_location
        ];

        if (!$this->zip->addFromString('description.json', json_encode($record, JSON_UNESCAPED_SLASHES))) {
            throw new InternalServerErrorException("Can not include description in package file.");
        }

        return true;
    }
1156093
public static boolean isInstalledOnSDCard(Application app) {
        try {
            String packageName = app.getPackageName();
            PackageInfo info = app.getPackageManager().getPackageInfo(packageName, 0);
            String dir = info.applicationInfo.sourceDir;

            for (String path : INTERNAL_PATH) {
                if (path.equals(dir.substring(0, path.length())))
                    return false;
            }
        } catch (PackageManager.NameNotFoundException exp) {
            throw new IllegalArgumentException(exp);
        }
        return true;
    }
95421
protected function checkRbacModuleInstalled(Application $app)
    {
        if ($app instanceof WebApplication) {
            return $app->hasModule('rbac') && $app->getModule('rbac') instanceof RbacWebModule;
        } else {
            return $app->hasModule('rbac') && $app->getModule('rbac') instanceof RbacConsoleModule;
        }
    }
210028
public function bootstrap(Application $app)
    {
        if ($app->configurationIsCached()) {
            return;
        }

        $this->checkForSpecificEnvironmentFile($app);

        try {
            $this->createDotenv($app)->safeLoad();
        } catch (InvalidFileException $e) {
            $this->writeErrorAndDie($e);
        }
    }
893247
public static function repository(?string $app = null): Repository
    {
        self::initialize();
        if ($app === null) {
            $app = '*';
        }

        // Autoload default "config" in project root.
        if ($app === '*' && !isset(self::$repositories[$app])) {
            $path = Path::root('config');
            if (!is_dir($path)) {
                throw new ConfigException('Path ' . $path . ' does not exist.');
            }
            self::$repositories[$app] = new Repository($path);
        }

        if (!isset(self::$repositories[$app])) {
            throw new ConfigException('Application ' . $app . ' not registered.');
        }
        return self::$repositories[$app];
    }
729738
final public static function setApplication(Application $app)
    {
        if (null === self::$_app) {
            self::$_app = $app;
        } else {
            throw new Exception('application 只能被实例化一次', 100500101);
        }
    }
891885
private function checkFrameworkSupport($package)
	{
		$extra = $package->getExtra();

		if (!isset($extra[self::NAME])) {
			return FALSE;
		}

		if (!isset($extra[self::NAME][$this->framework])) {
			return FALSE;
		}

		return $this->enabled;
	}
49789
public static function exists($package)
	{
		if (array_key_exists($package, static::$packages))
		{
			return static::$packages[$package];
		}
		else
		{
			$paths = \Config::get('package_paths', array());
			empty($paths) and $paths = array(PKGPATH);

			foreach ($paths as $path)
			{
				if (is_dir($path.$package))
				{
					return $path.$package.DS;
				}
			}
		}

		return false;
	}
651054
public function getApplication()
    {
        if (!$this->app) {
            $this->app = $this->getPackage()->app ?: $this->container->get('application');
        }

        return $this->app;
    }
371392
final protected function resolveApplicationAliases($app): array
    {
        $aliases = new Collection($this->getApplicationAliases($app));
        $overrides = $this->overrideApplicationAliases($app);

        if (! empty($overrides)) {
            $aliases->transform(function ($alias, $name) use ($overrides) {
                return $overrides[$name] ?? $alias;
            });
        }

        return $aliases->merge($this->getPackageAliases($app))->all();
    }
604758
public function all($app = NULL) : Bool
    {
        if( ! is_string($app) )
        {
            if( $app === NULL )
            {
                $MLFiles = Filesystem::getFiles($this->appdir, 'ml');
            }
            elseif( is_array($app) )
            {
                $MLFiles = $app;
            }
            else
            {
                return false;
            }

            $allMLFiles = [];

            if( ! empty($MLFiles) ) foreach( $MLFiles as $file )
            {
                $removeExtension = str_replace($this->extension, '', $file);
                $this->all($removeExtension);
            }

            return true;
        }
        else
        {
            $createFile = $this->_langFile($app);
      
            if( is_file($createFile) )
            {
                return unlink($createFile);
            }

            return false;
        }
    }
1221808
public function getClosure($app)
    {    
        // Confirm the matched property is a key in the routes array
        if (!isset($this->routes[$this->matched]))
            return false;
        
        $callback = $this->routes[$this->matched];
        
        // Is the callback a string? If so, it should be the name of a resource 
        // class, which will be used to build the logic inside a closure.
        if (is_string($callback)) {
            $className = 'Resources\\' . $callback;
            if (class_exists($className)) {
                // Success, so lets build a closure for executing the 
                // requested resource's output
                $callback = function() use ($app, $className, $callback) {
                    // Does this resource have a IoC alias registered?
                    if (!$resource = $app->get($callback))
                        $resource = new $className(
                            $app->get('request'), 
                            $app->get('response')
                        );
                    
                    $resource->output();
                };

            } else {
                // Oops, bad class name given to the router
                return false;
            }
        }
        
        // $callback should now be a closure - either because that's what the 
        // router was given originally, or because one was built from the 
        // string it was given.
        if (is_callable($callback)) {
            return $callback;
        } else {
            // The callback wasn't callable (that's not good).
            return false;
        }
    }
1160563
public function exportAppAsPackage($includeFiles = true, $includeData = false)
    {
        /** @type App $app */
        $app = App::find($this->exportAppId);

        if (empty($app)) {
            throw new NotFoundException('App not found in database with app id - ' . $this->exportAppId);
        }

        $appName = $app->name;

        try {
            $this->initExportZipFile($appName);
            $this->packageAppDescription($app);
            $this->packageServices();
            $this->packageSchemas();

            if ($includeData) {
                $this->packageData();
            }

            if ($app->type === AppTypes::STORAGE_SERVICE && $includeFiles) {
                $this->packageAppFiles($app);
            }

            $this->zip->close();
            FileUtilities::sendFile($this->zipFilePath, true);

            return null;
        } catch (\Exception $e) {
            //Do necessary things here.

            throw $e;
        }
    }
270496
public function bootstrap($app)
    {

        Event::on(ProductController::className(),
            ProductController::EVENT_AFTER_CREATE_PRODUCT, [$this, 'invalidateCache']);
        Event::on(ProductController::className(),
            ProductController::EVENT_AFTER_EDIT_PRODUCT, [$this, 'invalidateCache']);
        Event::on(ProductController::className(),
            ProductController::EVENT_AFTER_DELETE_PRODUCT, [$this, 'invalidateCache']);

        Event::on(CategoryController::className(),
            CategoryController::EVENT_AFTER_CREATE_CATEGORY, [$this, 'invalidateCache']);
        Event::on(CategoryController::className(),
            CategoryController::EVENT_AFTER_EDIT_CATEGORY, [$this, 'invalidateCache']);
        Event::on(CategoryController::className(),
            CategoryController::EVENT_AFTER_DELETE_CATEGORY, [$this, 'invalidateCache']);

        Event::on(Category::className(),
            Category::EVENT_AFTER_DELETE, [$this, 'invalidateCache']);
        Event::on(Category::className(),
            Category::EVENT_AFTER_INSERT, [$this, 'invalidateCache']);
        Event::on(Category::className(),
            Category::EVENT_AFTER_UPDATE, [$this, 'invalidateCache']);

        Event::on(Product::className(),
            Product::EVENT_AFTER_DELETE, [$this, 'invalidateCache']);
        Event::on(Product::className(),
            Product::EVENT_AFTER_INSERT, [$this, 'invalidateCache']);
        Event::on(Product::className(),
            Product::EVENT_AFTER_UPDATE, [$this, 'invalidateCache']);

        Event::on(Vendor::className(),
            Vendor::EVENT_AFTER_DELETE, [$this, 'invalidateCache']);
        Event::on(Vendor::className(),
            Vendor::EVENT_AFTER_INSERT, [$this, 'invalidateCache']);
        Event::on(Vendor::className(),
            Vendor::EVENT_AFTER_UPDATE, [$this, 'invalidateCache']);

        Event::on(Vendor::className(),
            Vendor::EVENT_AFTER_DELETE, [$this, 'invalidateCache']);
        Event::on(Vendor::className(),
            Vendor::EVENT_AFTER_INSERT, [$this, 'invalidateCache']);
        Event::on(Vendor::className(),
            Vendor::EVENT_AFTER_UPDATE, [$this, 'invalidateCache']);

        Event::on(ProductAvailability::className(),
            ProductAvailability::EVENT_AFTER_DELETE, [$this, 'invalidateCache']);
        Event::on(ProductAvailability::className(),
            ProductAvailability::EVENT_AFTER_INSERT, [$this, 'invalidateCache']);
        Event::on(ProductAvailability::className(),
            ProductAvailability::EVENT_AFTER_UPDATE, [$this, 'invalidateCache']);

        Event::on(ShopAttribute::className(),
            ShopAttribute::EVENT_AFTER_DELETE, [$this, 'invalidateCache']);
        Event::on(ShopAttribute::className(),
            ShopAttribute::EVENT_AFTER_INSERT, [$this, 'invalidateCache']);
        Event::on(ShopAttribute::className(),
            ShopAttribute::EVENT_AFTER_UPDATE, [$this, 'invalidateCache']);

        Event::on(ShopAttributeValue::className(),
            ShopAttributeValue::EVENT_AFTER_DELETE, [$this, 'invalidateCache']);
        Event::on(ShopAttributeValue::className(),
            ShopAttributeValue::EVENT_AFTER_INSERT, [$this, 'invalidateCache']);
        Event::on(ShopAttributeValue::className(),
            ShopAttributeValue::EVENT_AFTER_UPDATE, [$this, 'invalidateCache']);

        Event::on(ProductCountry::className(),
            ProductCountry::EVENT_BEFORE_DELETE, [$this, 'invalidateCache']);
        Event::on(ProductCountry::className(),
            ProductCountry::EVENT_BEFORE_INSERT, [$this, 'invalidateCache']);
        Event::on(ProductCountry::className(),
            ProductCountry::EVENT_BEFORE_UPDATE, [$this, 'invalidateCache']);

        Event::on(FavoriteProduct::className(),
            FavoriteProduct::EVENT_AFTER_DELETE, [$this, 'invalidateCache']);
        Event::on(FavoriteProduct::className(),
            FavoriteProduct::EVENT_AFTER_INSERT, [$this, 'invalidateCache']);
        Event::on(FavoriteProduct::className(),
            FavoriteProduct::EVENT_AFTER_UPDATE, [$this, 'invalidateCache']);

        Event::on(CartComponent::className(),
            CartComponent::EVENT_AFTER_CLEAR, [$this, 'invalidateCache']);
        Event::on(CartComponent::className(),
            CartComponent::EVENT_AFTER_ADD_PRODUCT, [$this, 'invalidateCache']);
        Event::on(CartComponent::className(),
            CartComponent::EVENT_AFTER_REMOVE_PRODUCT, [$this, 'invalidateCache']);
        Event::on(CartComponent::className(),
            CartComponent::EVENT_BEFORE_GET_ORDER, [$this, 'invalidateCache']);
        Event::on(CartComponent::className(),
            CartComponent::EVENT_BEFORE_GET_ORDER_FROM_DB, [$this, 'invalidateCache']);

    }
534515
public function getDefaultOption(string $app)
    {
        if($this->option($app)) {
            return $this->option($app);
        }

        if(!isset($this->defaultsOptions[$app])) {
            throw new \Exception('Option '.$app.' is not configured');
        }

        return $this->defaultsOptions[$app];
    }
98186
private function initExportZipFile($appName)
    {
        $zip = new \ZipArchive();
        $tmpDir = rtrim(sys_get_temp_dir(), DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR;
        $zipFileName = $tmpDir . $appName . '.' . static::FILE_EXTENSION;
        $this->zip = $zip;
        $this->zipFilePath = $zipFileName;

        if (true !== $this->zip->open($zipFileName, \ZipArchive::CREATE)) {
            throw new InternalServerErrorException('Can not create package file for this application.');
        }

        return true;
    }
1317946
private function initializeConfig(Application $app)
    {
        $config_provider = $app->make('Concrete\Core\Config\ConfigServiceProvider');
        $config_provider->register();

        /*
         * @var \Concrete\Core\Config\Repository\Repository
         */
        $config = $app->make('config');

        return $config;
    }