Detect the default app
@param array $apps App list
@return array The default app
@deprecated  Will remove next major release
@throws \Exception When does not have a default app
430900
public static function detectDefaultApp(array $apps):array
    {
        foreach ($apps as $oneapp => $val) {
            if ($val['isdefault'] == "yes") {
                return (array("name" => $oneapp, "value" => $val));
            }
        }

        throw new Server500(new \ArrayObject(array("explain" => "No Default app is detected", "solution" =>
            "Please edit apps.json to set a default app")));
    }
636935
protected function onlyExpectsJobs($jobs)
    {
        $jobs = is_array($jobs) ? $jobs : func_get_args();

        $this->withoutJobs();

        $this->beforeApplicationDestroyed(function () use ($jobs) {
            $dispatched = $this->getDispatchedJobs($jobs);

            if ($jobsNotDispatched = array_diff($jobs, $dispatched)) {
                throw new Exception(
                    'These expected jobs were not dispatched: ['.implode(', ', $jobsNotDispatched).']'
                );
            }

            if ($jobsDispatched = array_diff(array_map('get_class', $this->dispatchedJobs), $dispatched)) {
                throw new Exception(
                    'These unexpected jobs were dispatched: ['.implode(', ', $jobsDispatched).']'
                );
            }
        });

        return $this;
    }
1192550
public function addDefaults(array $defaults)
    {
        foreach ($defaults as $name => $default) {
            $this->defaults[$name] = $default;
        }
        $this->compiled = null;

        return $this;
    }
1332716
public function findDefaults(array &$settings)
    {
        if (!isset($settings['allow_multiple_selection'])) {
            $settings['allow_multiple_selection'] = 'no';
        }

        if (!isset($settings['show_association'])) {
            $settings['show_association'] = 'no';
        }

        if (!isset($settings['sort_options'])) {
            $settings['sort_options'] = 'no';
        }
    }
1008636
final protected function showEnabledAppsRegister():int
    {
        $this->params['applist'] = array();
        $file = json_decode(file_get_contents(FEnvFcm::get("framework.config.core.apps.file")));
        $i = 1;
        if ((is_string($file) && strlen($file) < 3) || (count((array) $file) == 0)) {
            Output::outputAsError("Ops! You do not have an enabled application.");
            return (false);
        }
        $str = "";
        foreach ($file as $val) {
            if ($val->enabled == "yes") {
                $str .= $i . ") " . $val->name . " : Enabled"  . "\n";
                array_push($this->params['applist'], $val->name);
                $i++;
            }
        }

        if (count($this->params['applist']) == 0) {
            Output::displayAsRed("Ops! You do not have an enabled app.");
            return (false);
        } else {
            Output::displayAsGreen("Your apps \n------------\n".$str, "none", false);
        }
        return (true);
    }
64367
public function doUpdate( App $app ) {
		$update = function () use ( $app ) {
			if ( ! $app->remove_actions ) {
				return FALSE;
			}
			foreach ( $app->remove_actions as $args ) {
				if ( ! is_array( $args ) ) {
					throw new ConfigException(
					    __("All elements of 'remove_actions' property in '*.config.json' must be arrays too.", 'wpf') );
				}
				remove_action( ...$args );
			}
		};
		add_action('after_setup_theme', $update );
	}
901976
protected function startBindingsPlugin($app)
    {
        /* @var \Illuminate\Foundation\Application $app */
        $this->requiresPlugins(Commands::class, Events::class);

        $this->onRegister('bindings', function (Application $app) {

            // Container bindings and aliases
            $legacy = ! class_exists('Illuminate\Foundation\Application') || version_compare(\Illuminate\Foundation\Application::VERSION, '5.7.0', '<');
            if ($legacy) {
                foreach ($this->bindings as $binding => $class) {
                    $this->app->bind($binding, $class);
                }
            }

            foreach ($this->weaklings as $binding => $class) {
                $this->bindIf($binding, $class);
            }

            foreach ([ 'share' => $this->share, 'shared' => $this->shared ] as $type => $bindings) {
                foreach ($bindings as $binding => $class) {
                    $this->share($binding, $class, [], $type === 'shared');
                }
            }

            if ($legacy) {
                foreach ($this->singletons as $binding => $class) {
                    if ($this->strict && ! class_exists($class) && ! interface_exists($class)) {
                        throw new \Exception(get_called_class() . ": Could not find alias class [{$class}]. This exception is only thrown when \$strict checking is enabled");
                    }
                    $this->app->singleton($binding, $class);
                }
            }

            foreach ($this->aliases as $alias => $full) {
                if ($this->strict && ! class_exists($full) && ! interface_exists($full)) {
                    throw new \Exception(get_called_class() . ": Could not find alias class [{$full}]. This exception is only thrown when \$strict checking is enabled");
                }
                $this->app->alias($alias, $full);
            }
        });
    }
174231
public function dueEvents(Application $app)
    {
        return array_filter($this->events, function ($event) use ($app)
        {
            return $event->isDue($app);
        });
    }
151707
public function extractModules($app)
    {
        if ($this->_modules === null) {
            foreach ($app->getModules() as $id => $obj) {
                // create module object
                $moduleObject = Yii::$app->getModule($id);
                // see if the module is a luya base module, otherwise ignore
                if ($moduleObject instanceof \luya\base\Module) {
                    $this->_modules[$id] = $moduleObject;
                }
            }
            // when no luya modules are registered an empty array will be returned.
            if ($this->_modules === null) {
                $this->_modules = [];
            }
        }
    }
829431
public function removeApplications(Application ...$applications)
    {
        foreach ($applications as $application) {
            $this->getApplications()->removeElement($application);
        }

        return $this;
    }
158946
public function defaultIndexAction(Application $app, Request $request)
    {
        return $this->renderIndex($app, array(
            'entities' => $app->getRepository($this->getModelName())->findAll(),
        ));
    }
396593
protected function getLoggerIfEnabled($app)
    {
        /** @var ApplicationInterface $app */

        if ($this->logger === false) {
            $settings       = $this->getSettings();
            $loggingEnabled =
                array_key_exists(Settings::KEY_LOGS_ENABLED, $settings) === true &&
                $settings[Settings::KEY_LOGS_ENABLED] === true;

            $this->logger = $loggingEnabled === true ? $app[LoggerInterface::class] : null;
        }

        return $this->logger;
    }
784505
public function all($app = NULL) : Array
    {
        if( ! is_string($app) )
        {
            if( $app === NULL )
            {
                $MLFiles = $this->getMLFiles();
            }
            elseif( is_array($app) )
            {
                $MLFiles = $app;
            }
            else
            {
                return false;
            }

            $allMLFiles = [];

            if( ! empty($MLFiles) ) foreach( $MLFiles as $file )
            {
                $removeExtension = $this->removeExtension($file);
                $allMLFiles[$removeExtension] = $this->all($removeExtension);
            }

            return $allMLFiles;
        }
        else
        {
            if( is_file($createFile = $this->_langFile($app)) )
            {
                $read = file_get_contents($createFile);

                return json_decode($read, true);
            }   

            return [];
        }
    }
1247932
protected function setEnvironment(Application $app)
    {
        // Define acceptable environments
        $environments = array(
            'production',
            'staging',
            'qa',
            'testing',
            'development',
            'beta',
        );

        if (! isset($_SERVER['APP_ENV'])) {
            throw new \Exception('Missing \'APP_ENV\' environment variable');
        }

        if (! in_array($_SERVER['APP_ENV'], $environments)) {
            throw new \Exception('Invalid \'APP_ENV\' environment variable: \'' + $_SERVER['APP_ENV'] +'\'');
        }

        $app['environment'] = $_SERVER['APP_ENV'];
    }
517491
public function load(Application $app, array $providers)
    {
        $manifest = $this->loadManifest();

        // First we will load the service manifest, which contains information on all
        // service providers registered with the application and which services it
        // provides. This is used to know which services are "deferred" loaders.
        if ($this->shouldRecompile($manifest, $providers)) {
            $manifest = $this->compileManifest($app, $providers);
        }

        // If the application is running in the console, we will not lazy load any of
        // the service providers. This is mainly because it's not as necessary for
        // performance and also so any provided Artisan commands get registered.
        if ($app->runningInConsole()) {
            $manifest['eager'] = $manifest['providers'];
        }

        // Next, we will register events to load the providers for each of the events
        // that it has requested. This allows the service provider to defer itself
        // while still getting automatically loaded when a certain event occurs.
        foreach ($manifest['when'] as $provider => $events) {
            $this->registerLoadEvents($app, $provider, $events);
        }

        // We will go ahead and register all of the eagerly loaded providers with the
        // application so their services can be registered with the application as
        // a provided service. Then we will set the deferred service list on it.
        foreach ($manifest['eager'] as $provider) {
            $app->register($this->createProvider($app, $provider));
        }

        $app->setDeferredServices($manifest['deferred']);
    }
413369
protected function getHandlers(Application $app)
    {
        $handlers = [];

        // File Handler
        $file = Arr::path($this->config, 'file.path');

        if ($file) {
            $handlers[] = $this->getFileHandler($file);
            $handlers[] = $this->getFileExceptionHandler($file);
        }

        // Loggly Handler
        $enableLoggly = Arr::path($this->config, 'loggly.enable');

        if ($enableLoggly) {
            $handlers[] = $this->getLogglyHandler();
        }

        // Rollbar Handler
        $enableRollbar = Arr::path($this->config, 'rollbar.enable');

        if ($enableRollbar) {
            $handlers[] = $this->getRollbarHandler($app['environment']);
        }

        // Syslog Handler
        $syslogIdent = Arr::path($this->config, 'syslog.ident');

        if ($syslogIdent) {
            $handlers[] = $this->getSyslogHandler($syslogIdent);
        }

        return $handlers;
    }
1111088
public function sessionHasErrors($app)
    {
        $config = $app['config']['session'];

        if (isset($app['session.store']) && ! is_null($config['driver']))
        {
            return $app['session.store']->has('errors');
        }
    }