Instantly share code, notes, and snippets.

Embed
What would you like to do?
<?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