Skip to content

Instantly share code, notes, and snippets.

@mattattui
Created April 17, 2013 23:08
Show Gist options
  • Save mattattui/5408519 to your computer and use it in GitHub Desktop.
Save mattattui/5408519 to your computer and use it in GitHub Desktop.
<?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