src/DI/ConsoleExtension.php
public function beforeCompile(): void
	{
		$builder = $this->getContainerBuilder();
		$config = $this->validateConfig($this->defaults);

		// Skip if isn't CLI
		if ($this->cliMode !== true) return;

		$application = $builder->getDefinition($this->prefix('application'));

		// Setup URL for CLI
		if ($builder->hasDefinition('http.request') && $config['url'] !== null) {
			$builder->getDefinition('http.request')
				->setFactory(Request::class, [new Statement(UrlScript::class, [$config['url']])]);
		}

		// Register all commands (if they are not lazy-loaded)
		// otherwise build a command map for command loader
		$commands = $builder->findByType(Command::class);

		if ($config['lazy'] === false) {
			// Iterate over all commands and add to console
			foreach ($commands as $serviceName => $service) {
				$application->addSetup('add', [$service]);
			}
		} else {
			$commandMap = [];

			// Iterate over all commands and build commandMap
			foreach ($commands as $serviceName => $service) {
				$tags = $service->getTags();
				$entry = ['name' => null, 'alias' => null];

				if (isset($tags[self::COMMAND_TAG])) {
					// Parse tag's name attribute
					if (is_string($tags[self::COMMAND_TAG])) {
						$entry['name'] = $tags[self::COMMAND_TAG];
					} elseif (is_array($tags[self::COMMAND_TAG])) {
						$entry['name'] = Arrays::get($tags[self::COMMAND_TAG], 'name', null);
					}
				} else {
					// Parse it from static property
					$entry['name'] = call_user_func([$service->getEntity(), 'getDefaultName']);
				}

				// Validate command name
				if (!isset($entry['name'])) {
					throw new ServiceCreationException(
						sprintf(
							'Command "%s" missing tag "%s[name]" or variable "$defaultName".',
							$service->getEntity(),
							self::COMMAND_TAG
						)
					);
				}

				// Append service to command map
				$commandMap[$entry['name']] = $serviceName;
			}

			$builder->getDefinition($this->prefix('commandLoader'))
				->getFactory()->arguments = ['@container', $commandMap];
		}
	}
public function beforeCompile(): void
	{
		$builder = $this->getContainerBuilder();
		$config = $this->validateConfig($this->defaults);

		// Skip if isn't CLI
		if ($this->cliMode !== true) return;

		$application = $builder->getDefinition($this->prefix('application'));

		// Setup URL for CLI
		if ($builder->hasDefinition('http.request') && $config['url'] !== null) {
			$builder->getDefinition('http.request')
				->setFactory(Request::class, [new Statement(UrlScript::class, [$config['url']])]);
		}

		// Register all commands (if they are not lazy-loaded)
		// otherwise build a command map for command loader
		$commands = $builder->findByType(Command::class);

		if ($config['lazy'] === false) {
			// Iterate over all commands and add to console
			foreach ($commands as $serviceName => $service) {
				$application->addSetup('add', [$service]);
			}
		} else {
			$commandMap = [];

			// Iterate over all commands and build commandMap
			foreach ($commands as $serviceName => $service) {
				$tags = $service->getTags();
				$entry = ['name' => null, 'alias' => null];

				if (isset($tags[self::COMMAND_TAG])) {
					// Parse tag's name attribute
					if (is_string($tags[self::COMMAND_TAG])) {
						$entry['name'] = $tags[self::COMMAND_TAG];
					} elseif (is_array($tags[self::COMMAND_TAG])) {
						$entry['name'] = Arrays::get($tags[self::COMMAND_TAG], 'name', null);
					}
				} else {
					// Parse it from static property
					$entry['name'] = call_user_func([$service->getEntity(), 'getDefaultName']);
				}

				// Validate command name
				if (!isset($entry['name'])) {
					throw new ServiceCreationException(
						sprintf(
							'Command "%s" missing tag "%s[name]" or variable "$defaultName".',
							$service->getEntity(),
							self::COMMAND_TAG
						)
					);
				}

				// Append service to command map
				$commandMap[$entry['name']] = $serviceName;
			}

			$builder->getDefinition($this->prefix('commandLoader'))
				->getFactory()->arguments = ['@container', $commandMap];
		}
	}
Decorate services