src/Ace/Commands/Make/MakeCommandCommand.php
/**
	 * Works some unbelievably nasty "magic" to add the command to the console.php configuration file, and sort the
	 * commands in that file alphabetically...
	 *
	 * @param string $commandName
	 * @param string $className
	 * @param OutputInterface $out
	 * @return void
	 */
Works some unbelievably nasty "magic" to add the command to the console.php configuration file, and sort the
commands in that file alphabetically

@param string $commandName
@param string $className
@param OutputInterface $out
@return void
Works some unbelievably nasty " magic " to add the command to the console . php configuration file and sort the commands in that file alphabetically @param string $commandName @param string $className @param OutputInterface $out @return void
private function addCommandToConfig($commandName, $className, OutputInterface $out) {
		$configPath = Application::paths()->config('console.php');
		$content = file_get_contents($configPath);
		$expression = "/^([\t ]*)(['\"])commands(?:['\"]) => (?:array\(|\[) *([^\]\)]*)[\]\)](,?)/ms";
		if (!preg_match_all($expression, $content, $matches)) {
			return $out->writeln(
				'<fg=red>[×]</> couldn\'t add command to ' . Application::paths()->getRelative($configPath)
			);
		}
		$indentation = $matches[1][0];
		$quoteCharacter = $matches[2][0];
		$commandLinesRaw = trim($matches[3][0]);
		$trailingComma = $matches[4][0];
		$newLines = [];
		preg_match_all(
			"/^(?:[\t ]*)['\"]([^'\"]+)['\"][\t ]*=>[\t ]*['\"]([^\t ]*)['\"],?/m",
			$commandLinesRaw,
			$commandLines,
			PREG_SET_ORDER
		);
		foreach ($commandLines as $line) {
			$lineName = $line[1];
			$lineClassName = $line[2];
			$newLines[$lineName] = implode('', [
				str_repeat($indentation, 2), $quoteCharacter, $lineName, $quoteCharacter, ' => ',
				$quoteCharacter, $lineClassName, $quoteCharacter, ','
			]);
		}
		$newLines[$commandName] = implode('', [
			str_repeat($indentation, 2), $quoteCharacter, $commandName, $quoteCharacter, ' => ',
			$quoteCharacter, $className, $quoteCharacter, ','
		]);
		ksort($newLines);
		$newArray = implode('', [
			$indentation, $quoteCharacter, 'commands', $quoteCharacter, " => [\n",
			rtrim(implode("\n", $newLines), ','),
			"\n", $indentation, ']', $trailingComma
		]);
		$content = preg_replace($expression, $newArray, $content);
		file_put_contents($configPath, $content);
		$out->writeln("<fg=green>[✓]</> append " . Application::paths()->getRelative($configPath));
	}
private function addCommandToConfig ( $ commandName , $ className , OutputInterface $ out ) { $ configPath = Application :: paths ( ) -> config ( 'console.php' ) ; $ content = file_get_contents ( $ configPath ) ; $ expression = " /^([ \t  ]*)([' \" ])commands(?:[' \" ]) => (?:array\(|\[) *([^\]\)]*)[\]\)](,?)/ms " ; if ( ! preg_match_all ( $ expression , $ content , $ matches ) ) { return $ out -> writeln ( '<fg=red>[×]</> couldn\'t add command to '  pplication: :p aths( ) - >g etRelative( $ c onfigPath) ) ; } $ indentation = $ matches [ 1 ] [ 0 ] ; $ quoteCharacter = $ matches [ 2 ] [ 0 ] ; $ commandLinesRaw = trim ( $ matches [ 3 ] [ 0 ] ) ; $ trailingComma = $ matches [ 4 ] [ 0 ] ; $ newLines = [ ] ; preg_match_all ( " /^(?:[ \t  ]*)[' \" ]([^' \" ]+)[' \" ][ \t  ]*=>[ \t  ]*[' \" ]([^ \t  ]*)[' \" ],?/m " , $ commandLinesRaw , $ commandLines , PREG_SET_ORDER ) ; foreach ( $ commandLines as $ line ) { $ lineName = $ line [ 1 ] ; $ lineClassName = $ line [ 2 ] ; $ newLines [ $ lineName ] = implode ( '' , [ str_repeat ( $ indentation , 2 ) , $ quoteCharacter , $ lineName , $ quoteCharacter , ' => ' , $ quoteCharacter , $ lineClassName , $ quoteCharacter , ',' ] ) ; } $ newLines [ $ commandName ] = implode ( '' , [ str_repeat ( $ indentation , 2 ) , $ quoteCharacter , $ commandName , $ quoteCharacter , ' => ' , $ quoteCharacter , $ className , $ quoteCharacter , ',' ] ) ; ksort ( $ newLines ) ; $ newArray = implode ( '' , [ $ indentation , $ quoteCharacter , 'commands' , $ quoteCharacter , "  => [ \n " , rtrim ( implode ( " \n " , $ newLines ) , ',' ) , " \n " , $ indentation , ']' , $ trailingComma ] ) ; $ content = preg_replace ( $ expression , $ newArray , $ content ) ; file_put_contents ( $ configPath , $ content ) ; $ out -> writeln ( " <fg=green>[✓]</> append "  . A plication:: pa ths() - > ge tRelative($ c o nfigPath)) ; }
Works some unbelievably nasty "magic" to add the command to the console.php configuration file, and sort the
 commands in that file alphabetically...
Works some unbelievably nasty " magic " to add the command to the console . php configuration file and sort the commands in that file alphabetically ...