Skip to content

Instantly share code, notes, and snippets.

@roderik
Created April 30, 2012 09:35
Show Gist options
  • Save roderik/2556858 to your computer and use it in GitHub Desktop.
Save roderik/2556858 to your computer and use it in GitHub Desktop.
BillSplitCommand v2
<?php
namespace Kunstmaan\Hosting\BillSplitBundle\Command;
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
use SplFileObject;
use SplFileInfo;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Yaml\Parser;
class BillSplitCommand extends ContainerAwareCommand
{
protected function configure()
{
$this
->setName('bill:split')
->setDescription('Split the bill')
->addArgument('billpath', InputArgument::REQUIRED, 'The path to the bill yml file');
}
protected function execute(InputInterface $input, OutputInterface $output)
{
$bill = $this->parseBill($input->getArgument('billpath'), $output);
}
/**
* Parses the YAML file containing the bill content into an array.
*
* @param string $billpath
* @param OutputInterface $output
* @return array a multidimensional array with the bill.yml content
*/
private function parseBill($billpath, OutputInterface $output)
{
$output->writeln(" - Locating and parsing the Bill input file: " . $billpath);
$content = file_get_contents($billpath);
$yaml = new Parser();
return $yaml->parse($content);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment