Skip to content

Commit

Permalink
added a command to generate predefined hydrators
Browse files Browse the repository at this point in the history
  • Loading branch information
remi-san committed May 24, 2016
1 parent 7229df4 commit b9747e9
Showing 1 changed file with 63 additions and 0 deletions.
63 changes: 63 additions & 0 deletions src/Console/PredefinedHydratorGenerationCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<?php

namespace RemiSan\Serializer\Console;

use RemiSan\Serializer\Hydrator\HydratorFactory;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

/**
* @codeCoverageIgnore
*/
class PredefinedHydratorGenerationCommand extends Command
{
/**
* @var HydratorFactory
*/
private $hydratorFactory;

/**
* @var string[]
*/
private $classes;

/**
* Constructor
*
* @param HydratorFactory $hydratorFactory
* @param string[] $classes
* @param string $name
*/
public function __construct(HydratorFactory $hydratorFactory, array $classes, $name = null)
{
$this->hydratorFactory = $hydratorFactory;
$this->classes = $classes;

parent::__construct($name);
}

/**
* Configures the command
*/
protected function configure()
{
$this->setDescription('Generates hydrators cache files');
}

/**
* Code executed when command invoked
*
* @param InputInterface $input
* @param OutputInterface $output
* @return void
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
foreach ($this->classes as $className) {
$output->write('Generating "<info>' . $className . '</info>" ');
$this->hydratorFactory->getHydratorClassName($className);
$output->writeLn('<comment>Done</comment>');
}
}
}

0 comments on commit b9747e9

Please sign in to comment.