<commit_before><?php
namespace Etg24\EventSourcing\Command\Controller\Aspect;

use Etg24\EventSourcing\Command as Domain;
use Etg24\EventSourcing\Command\Controller\DomainCommand;
use Etg24\EventSourcing\Command\Controller\DomainModelCommandController;
use TYPO3\Flow\Annotations as Flow;
use TYPO3\Flow\Aop\JoinPointInterface;
use TYPO3\Flow\Cli as Cli;
use TYPO3\Flow\Reflection\ObjectAccess;
use TYPO3\Flow\Reflection\ReflectionService;

/**
 * @Flow\Scope("singleton")
 * @Flow\Aspect
 */
class RegisteringDomainCommandsAspect {

	/**
	 * @var ReflectionService
	 * @Flow\Inject
	 */
	protected $reflectionService;

	/**
	 * @param JoinPointInterface $joinPoint
	 * @return mixed Result of the target method
	 * @Flow\Around("class(TYPO3\Flow\Cli\CommandManager) && method(.*->getAvailableCommands()) && setting(Etg24.EventSourcing.Command.Controller.enabled)")
	 */
	public function registerDomainModelCommands(JoinPointInterface $joinPoint) {
		$proxy = $joinPoint->getProxy();

		$currentCommands = ObjectAccess::getProperty($proxy, 'availableCommands', TRUE);

		// commands have been initialized
		if ($currentCommands !== NULL) {
			return $joinPoint->getAdviceChain()->proceed($joinPoint);
		}

		$commands = $joinPoint->getAdviceChain()->proceed($joinPoint);
		$domainCommands = $this->getDomainCommands();
		$allCommands = array_merge($commands, $domainCommands);

		ObjectAccess::setProperty($proxy, 'availableCommands', $allCommands, TRUE);
		return $allCommands;
	}

	/**
	 * @return Cli\Command[]
	 */
	protected function getDomainCommands() {
		$cliCommands = [];
		$domainCommandClassNames = $this->reflectionService->getAllImplementationClassNamesForInterface(Domain\CommandInterface::class);

		foreach ($domainCommandClassNames as $domainCommandClassName) {
			$cliCommands[] = $this->buildDomainCommand($domainCommandClassName);
		}

		return $cliCommands;
	}

	/**
	 * @param string $commandClassName
	 * @return Cli\Command
	 */
	protected function buildDomainCommand($commandClassName) {
		return new DomainCommand(
			DomainModelCommandController::class,
			$commandClassName
		);
	}

}<commit_msg>[BUGFIX] Domain commands cannot be executed in runlevel Runtime<commit_after><?php
namespace Etg24\EventSourcing\Command\Controller\Aspect;

use Etg24\EventSourcing\Command as Domain;
use Etg24\EventSourcing\Command\Controller\DomainCommand;
use Etg24\EventSourcing\Command\Controller\DomainModelCommandController;
use TYPO3\Flow\Annotations as Flow;
use TYPO3\Flow\Aop\JoinPointInterface;
use TYPO3\Flow\Cli as Cli;
use TYPO3\Flow\Reflection\ObjectAccess;
use TYPO3\Flow\Reflection\ReflectionService;

/**
 * @Flow\Scope("singleton")
 * @Flow\Aspect
 */
class RegisteringDomainCommandsAspect {

	/**
	 * @var ReflectionService
	 * @Flow\Inject
	 */
	protected $reflectionService;

	/**
	 * @param JoinPointInterface $joinPoint
	 * @return mixed Result of the target method
	 * @Flow\Around("class(TYPO3\Flow\Cli\CommandManager) && method(.*->getAvailableCommands()) && setting(Etg24.EventSourcing.Command.Controller.enabled)")
	 */
	public function registerDomainModelCommands(JoinPointInterface $joinPoint) {
		$proxy = $joinPoint->getProxy();

		$currentCommands = ObjectAccess::getProperty($proxy, 'availableCommands', TRUE);

		// commands have been initialized
		if ($currentCommands !== NULL) {
			return $joinPoint->getAdviceChain()->proceed($joinPoint);
		}

		$commands = $joinPoint->getAdviceChain()->proceed($joinPoint);
		$domainCommands = $this->getDomainCommands();
		$allCommands = array_merge($commands, $domainCommands);

		ObjectAccess::setProperty($proxy, 'availableCommands', $allCommands, TRUE);
		return $allCommands;
	}

	/**
	 * @return Cli\Command[]
	 */
	protected function getDomainCommands() {
		$cliCommands = [];
		$domainCommandClassNames = $this->reflectionService->getAllImplementationClassNamesForInterface(Domain\CommandInterface::class);

		foreach ($domainCommandClassNames as $domainCommandClassName) {
			$cliCommands[] = $this->buildDomainCommand($domainCommandClassName);
		}

		return $cliCommands;
	}

	/**
	 * @param string $commandClassName
	 * @return Cli\Command
	 */
	protected function buildDomainCommand($commandClassName) {
		return new DomainCommand(
			DomainModelCommandController::class,
			$commandClassName
		);
	}

	/**
	 * @param JoinPointInterface $joinPoint
	 * @return mixed Result of the target method
	 * @Flow\Around("class(TYPO3\Flow\Cli\Command) && method(.*->__construct())")
	 */
	public function replaceCommandWithDomainCommand(JoinPointInterface $joinPoint) {
		try {
			return $joinPoint->getAdviceChain()->proceed($joinPoint);
		} catch (\InvalidArgumentException $e) {
			$controllerClassName = $joinPoint->getMethodArgument('controllerClassName');
			$controllerCommandName = $joinPoint->getMethodArgument('controllerCommandName');

			return new DomainCommand($controllerClassName, $controllerCommandName);
		}
	}

}
{'fraction_non_alphanumeric': 0.12810085400569338, 'fraction_numerical': 0.0067100447336315575, 'mean_word_length': 5.784827586206896, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 28, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4158498', 'n_tokens_mistral': 1546, 'n_tokens_neox': 1432, 'n_words': 255}