-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added a command to generate predefined hydrators
- Loading branch information
Showing
1 changed file
with
63 additions
and
0 deletions.
There are no files selected for viewing
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
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>'); | ||
} | ||
} | ||
} |