*/ class Compile extends Command { /** * The signature of the command. * * @var string */ protected $signature = 'stack:compile {in_file} {out_file} {--format=Yaml}'; /** * The description of the command. * * @var string */ protected $description = 'Read an input file, process, output result to a file'; /** * Execute the console command. * * @return void */ public function handle() { $engine = new \App\Engine\Engine(); $serializer = $this->getSerializer(); $unserializer = $this->getUnserializer(); $engine->setSerializer($serializer)->setUnserializer($unserializer)->setCompiler(new \App\Engine\Cfnpp()); $output = $engine->process($this->argument('in_file'), new \App\Engine\CfnppOptions()); file_put_contents($this->argument('out_file'), $output); } /** * Retrieve a serializer instance based on the format specified in the command options. * * @return \App\Serialize\ISerialize */ protected function getSerializer(): \App\Serialize\ISerialize { $format = $this->option('format'); $class = '\\App\\Serialize\\'.$format; if (!class_exists($class)) { throw new \Exception('Unknown formatter: '.$format); } return new $class(); } /** * Retrieve a unserializer instance based on the format specified in the command options. * * @return \App\Serialize\IUnserialize */ protected function getUnserializer(): \App\Serialize\IUnserialize { $format = $this->option('format'); $class = '\\App\\Serialize\\'.$format; if (!class_exists($class)) { throw new \Exception('Unknown formatter: '.$format); } return new $class(); } }