public function run() { $parser = new CommandParser($this->request, $this->response, $this->container['grid'], $this->container['personalInventory']); $response = $parser->parseCommand(); echo str_replace(PHP_EOL, '<br />', $response->output()); $this->state->save($this->container); }
} switch ($matches[1]) { case 'toggle': $command = LightSwitchCommand::COMMAND_TOGGLE; break; case 'turn on': $command = LightSwitchCommand::COMMAND_ON; break; case 'turn off': default: $command = LightSwitchCommand::COMMAND_OFF; } return new LightSwitchCommand(Coordinate::fromString($matches[2]), Coordinate::fromString($matches[3]), $command); } } $parser = new CommandParser(); $lightGrid = new LightGrid(new OnOffLightStrategy()); foreach (file('6.txt') as $instruction) { echo 'excecuting ' . $instruction . PHP_EOL; $lightGrid->toggleLights($parser->parseCommand($instruction)); } echo 'Part 1 answer: ' . $lightGrid->getNumLights(true); $lightGrid = new LightGrid(new BrightnessLightStrategy()); foreach (file('6.txt') as $instruction) { echo 'excecuting ' . $instruction . PHP_EOL; $lightGrid->toggleLights($parser->parseCommand($instruction)); } $totalBrightness = 0; foreach ($lightGrid->getLights() as $x => $arr) { foreach ($arr as $y => $brightness) { $totalBrightness += $brightness;
public static function run($string, $args = array()) { $command = CommandParser::getCommandObject($string); return $command->run($args); }
public function testNotGate() { $expected = ['type' => 'NOT', 'assignee' => 'h', 'wires' => ['x']]; $cmdParser = new CommandParser('NOT x -> h'); $this->assertEquals($expected, $cmdParser->getCommand(), 'NOT gate command not parsed correctly'); }
/** * Configure the console command using a fluent definition. * * @return void */ protected function configureUsingFluentDefinition() { list($name, $arguments, $options) = \CommandParser::parse($this->signature); parent::__construct($name); foreach ($arguments as $argument) { $this->getDefinition()->addArgument($argument); } foreach ($options as $option) { $this->getDefinition()->addOption($option); } }