Created
April 17, 2013 23:08
-
-
Save mattattui/5408519 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 Acme\DemoBundle\Command; | |
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand; | |
use Symfony\Component\Console\Input\InputArgument; | |
use Symfony\Component\Console\Input\InputInterface; | |
use Symfony\Component\Console\Input\InputOption; | |
use Symfony\Component\Console\Output\OutputInterface; | |
class ImportCSVCommand extends ContainerAwareCommand | |
{ | |
protected function configure() | |
{ | |
$this | |
->setName('demo:load-fixtures') | |
->setDescription('Import CSV into database') | |
->addArgument( | |
'filename', | |
InputArgument::OPTIONAL, | |
'What file do you want to import?', | |
__DIR__.'/../../../app/Resources/fixtures.csv' | |
) | |
; | |
} | |
protected function execute(InputInterface $input, OutputInterface $output) | |
{ | |
$filename = $input->getArgument('filename'); | |
$output->writeln(sprintf('<info>Parsing %s</info>',$filename)); | |
if (!is_file($filename)) { | |
$output->writeln('<error>No such file!</error>'); | |
return; | |
} | |
$loader = $this->container->get('fixture_loader'); | |
$loader->load($filename); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment