Created
April 30, 2012 09:35
-
-
Save roderik/2556858 to your computer and use it in GitHub Desktop.
BillSplitCommand v2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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