Configure console

@param mixed $app
@return void
496808
public static function console($app)
  {
    if (Filesystem::isDirectory(Self::$dir . DIRECTORY_SEPARATOR . 'Commands')) {
      $app->craftsman->load(Self::$dir . DIRECTORY_SEPARATOR . 'Commands');
    }
  }
200833
protected function resolveApplicationConfiguration($app)
    {
        $app->make('Illuminate\Foundation\Bootstrap\LoadConfiguration')->bootstrap($app);

        \tap($this->getApplicationTimezone($app), function ($timezone) {
            ! \is_null($timezone) && \date_default_timezone_set($timezone);
        });

        $app['config']['app.aliases'] = $this->resolveApplicationAliases($app);
        $app['config']['app.providers'] = $this->resolveApplicationProviders($app);
    }
1136969
public function bootstrap(Application $app)
    {
        $this->app = $app;

        $this->app->setBasePath($this->basePath);

        $this->app->instance('path', $this->getPath());

        foreach ([ 'config', 'database', 'lang', 'public', 'storage' ] as $path) {
            $this->app->instance('path.' . $path, $this->getPath($path));
        }
    }
802221
public function register(Application $app)
    {
        /** @var Translator $translator  */
        $translator = $app['translator'];
        $translator->addTranslationFolder(__DIR__ . DIRECTORY_SEPARATOR . 'Messages');

        /** @var ApplicationConfiguration $config */
        $config = $app['config'];

        $partialsCollection = new PartialsCollection($app['markdown']);
        $app['partials'] = $partialsCollection;

        /** @var Partial[] $partials */
        $partials = $config->getPartials();
        if ($partials) {
            foreach ($partials as $partial) {
                if (! $partial->getName()) {
                    throw new Exception\MissingNameForPartialException('The name of the partial to load is missing');
                }

                $content = '';
                if ($partial->getContent()) {
                    $content = $partial->getContent();
                } elseif ($partial->getLink()) {
                    if (! is_readable($partial->getLink())) {
                        $app['monolog']->error(
                            sprintf($translator->translate('PPCPP:EXC-NOPARTIAL'), $partial->getLink())
                        );
                        continue;
                    }

                    $content = file_get_contents($partial->getLink());
                }
                $partialsCollection->set($partial->getName(), $content);
            }
        }
    }
1303205
public function boot(Application $app)
    {
        $app->on(KernelEvents::EXCEPTION, function (GetResponseForExceptionEvent $event) {
            $e = $event->getException();
            if ($e instanceof MethodNotAllowedHttpException && $e->getHeaders()["Allow"] === "OPTIONS") {
                $event->setException(new NotFoundHttpException("No route found for \"{$event->getRequest()->getMethod()} {$event->getRequest()->getPathInfo()}\""));
            }
        });
    }
226382
public function applicationConsole()
    {
        $this->setIsCli(true);
        $config = $this->getConfigArray();
        $config['defaultRoute'] = 'help';
        if (isset($config['components'])) {
            if (isset($config['components']['composition'])) {
                unset($config['components']['composition']);
            }
        }
        
        $this->includeYii();

        $baseUrl = null;
        if (isset($config['consoleBaseUrl'])) {
            $baseUrl = $config['consoleBaseUrl'];
        } elseif (isset($config['consoleHostInfo'])) {
            $baseUrl = '/';
        }
        
        $mergedConfig = ArrayHelper::merge($config, [
            'bootstrap' => ['luya\console\Bootstrap'],
            'components' => [
                'urlManager' => [
                    'class' => 'yii\web\UrlManager',
                    'enablePrettyUrl' => true,
                    'showScriptName' => false,
                    'baseUrl' => $baseUrl,
                    'hostInfo' => isset($config['consoleHostInfo']) ? $config['consoleHostInfo'] : null,
                ],
            ],
        ]);
        $this->app = new ConsoleApplication($mergedConfig);
        if (!$this->mockOnly) {
            exit($this->app->run());
        }
    }
1017627
public function bootstrap($app)
    {
        if ($app instanceof Application) {
            if (is_callable($this->languages)) {
                $this->languages = call_user_func($this->languages);
            }
            if (!is_array($this->languages)) {
                throw new InvalidConfigException(
                    'The "languages" property must be an array or callable function that returns an array'
                );
            }

            if (!is_bool($this->appendSetLanguageHandler)) {
            	throw new InvalidConfigException(
            		'The "appendSetLanguageHandler" property must be a boolean'
	            );
            }
            foreach ($this->handlers as &$handler) {
                if (is_object($handler) === false) {
                    $handler = Yii::createObject($handler);
                }
                if (!$handler instanceof AbstractHandler) {
                    throw new InvalidConfigException(sprintf(
                        'The handler must be an instance of "%s"',
                        AbstractHandler::className()
                    ));
                }
            }
            $app->on($app::EVENT_BEFORE_ACTION, [$this, 'setLanguage'], $app, $this->appendSetLanguageHandler);
        }
    }
95834
public function bootstrap(Application $app)
    {
        $this->app = $app;

        error_reporting(-1);

        set_error_handler([$this, 'handleError']);

        set_exception_handler([$this, 'handleException']);

        register_shutdown_function([$this, 'handleShutdown']);

        if (! $app->environment('testing')) {
            ini_set('display_errors', 'Off');
        }
    }
800917
protected function configure()
	{
		// the short description shown while running "php bin/console list"
		if( $this->docs->getIs("description") )
		{
			$this->setDescription($this->docs["description"]);
		}

		// the full command description shown when running the command with
		// the "--help" option
		if( $this->docs->getIs("help") )
		{
			$this->setHelp($this->docs["help"]);
		}
	}
677157
public function register(Container $app)
    {
        $app['console.name'] = 'Silex console';
        $app['console.version'] = 'UNKNOWN';
        // Assume we are in vendor/knplabs/console-service-provider/Knp/Provider
        $app['console.project_directory'] = __DIR__.'/../../../../..';
        $app['console.class'] = ConsoleApplication::class;
        // List of command service ids indexed by command name (i.e: array('my:command' => 'my.command.service.id'))
        $app['console.command.ids'] = [];

        // Maintain BC with projects that depend on the old behavior (application gets booted from console constructor)
        $app['console.boot_in_constructor'] = false;

        $app['console'] = function () use ($app) {
            /** @var ConsoleApplication $console */
            $console = new $app['console.class'](
                $app,
                $app['console.project_directory'],
                $app['console.name'],
                $app['console.version']
            );
            $console->setDispatcher($app['dispatcher']);

            foreach ($app['console.command.ids'] as $id) {
                $console->add($app[$id]);
            }

            if ($app['dispatcher']->hasListeners(ConsoleEvents::INIT)) {
                @trigger_error('Listening to the Knp\Console\ConsoleEvents::INIT event is deprecated and will be removed in v3 of the service provider. You should extend the console service instead.', E_USER_DEPRECATED);

                $app['dispatcher']->dispatch(ConsoleEvents::INIT, new ConsoleEvent($console));
            }

            return $console;
        };

        $commands = [];

        if (isset($app['twig']) && class_exists(TwigBridgeDebugCommand::class)) {
            $app['console.command.twig.debug'] = function (Container $container) {
                return new DebugCommand($container);
            };

            $app['console.command.twig.lint'] = function (Container $container) {
                return new LintCommand($container);
            };

            $commands['debug:twig'] = 'console.command.twig.debug';
            $commands['lint:twig'] = 'console.command.twig.lint';
        }

        if (class_exists(LintYamlCommand::class)) {
            $app['console.command.yaml.lint'] = function () {
                return new LintYamlCommand();
            };
            $commands['lint:yaml'] = 'console.command.yaml.lint';
        }

        $app['console.command.ids'] = $commands;
    }
233554
private function addDefaultArgumentsAndOptions(Application $app) {
    $app->getDefinition()
      ->addOption(
        new InputOption('--define', '-D', InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY, 'Define a configuration item value.', [])
      );
    $app->getDefinition()
      ->addOption(
        new InputOption('--environment', NULL, InputOption::VALUE_REQUIRED, 'Set the environment to load config from blt/[env].yml file.', [])
      );
    $app->getDefinition()
      ->addOption(
        new InputOption('--site', NULL, InputOption::VALUE_REQUIRED, 'The multisite to execute this command against.', [])
      );
  }
815219
protected function _configure() {

			// Create my settings object
			$this->config = new Core\Configuration();
			
			// Define some paths
			define("CHICKENWIRE_PATH", dirname(__FILE__));
			define("APP_PATH", APP_ROOT . "/Application");
			define("CONFIG_PATH", APP_PATH . "/Config");
			define("CONTROLLER_PATH", APP_PATH . "/Controllers");
			define("LAYOUT_PATH", APP_PATH . "/Layouts");
			define("MODEL_PATH", APP_PATH . "/Models");
			define("VIEW_PATH", APP_PATH . "/Views");
			define("PUBLIC_PATH", APP_PATH . "/Public");
			define("MODULE_PATH", APP_ROOT . "/Modules");

			define("MODEL_NS", $this->config->applicationNamespace . "\\Models");

			// Include all php files in the config directory
			$dh = opendir(CONFIG_PATH);
			$configFiles = scandir(CONFIG_PATH, SCANDIR_SORT_ASCENDING);
			foreach ($configFiles as $file) {

				// PHP?
				if (preg_match("/\.php$/", $file)) {

					// Load it
					$this->config->load(CONFIG_PATH . '/' . $file);
					
				}

			}

			// Initalize database configuration
			$dbConnections = $this->config->allFor("database");
			$environment = $this->config->environment;
			\ActiveRecord\Config::initialize(function($config) use ($dbConnections, $environment) {

				// Set model path
				$config->setModelDirectory(MODEL_PATH);

				// Apply connections
				$config->setConnections($dbConnections);

				// Set default to my environment
				$config->setDefaultConnection($environment);

			});

			// Set the timezone
			if ($this->config->timezone == '') {
				throw new \Exception("You need to specify the timezone in the Application configuration.", 1);				
			}
			date_default_timezone_set($this->config->timezone);

			// Set self closing slash
			\HtmlObject\Traits\Tag::$useSelfClosingSlash = $this->config->htmlSelfClosingSlash;

			// Set the webPath
			$this->config->webPath = rtrim($this->config->webPath, ' /');

		}
1178479
public function bootstrap(Application $app)
	{
		Facade::clearResolvedInstances();

		Facade::setFacadeApplication($app);

		AliasLoader::getInstance($app['config']['app.aliases'])->register();
	}
985823
public static function unregisterApp(?string $app = null): void
    {
        self::initialize();
        if ($app === null) {
            $app = '*';
        }
        if (self::isAppRegistered($app)) {
            unset(self::$repositories[$app]);
        }
    }
1294580
public function register(Application $app)
    {
        $this->loadConfigurations($app);
        $this->registerServices($app);
        $this->registerEventListener($app);
    }
771677
public function bootstrap($app)
    {
        if ($app instanceof \yii\console\Application) {
            if (!isset($app->controllerMap['schedule'])) {
                $app->controllerMap['schedule'] = 'omnilight\scheduling\ScheduleController';
            }
        }
    }
977115
public function onConstruct($app)
    {
        //if not null
        if (!is_null($app)) {
            $key = $this->settingsKey;
            $this->$key = $app;
        }
    }