[Command] Added a new command named: propel:form:generate

Allows to quickly create Form Type stubs
Added a PropelGeneratorAwareCommand class (abstract) to write more code generation based commands
Added few tests, fixed some tests as well
This commit is contained in:
William DURAND 2012-04-11 11:54:25 +02:00
commit 0b85aba836
11 changed files with 325 additions and 54 deletions

View file

@ -235,15 +235,25 @@ abstract class AbstractPropelCommand extends ContainerAwareCommand
{
$finalSchemas = array();
foreach ($kernel->getBundles() as $bundle) {
if (is_dir($dir = $bundle->getPath().'/Resources/config')) {
$finder = new Finder();
$schemas = $finder->files()->name('*schema.xml')->followLinks()->in($dir);
$finalSchemas = array_merge($finalSchemas, $this->getSchemasFromBundle($bundle));
}
if (!iterator_count($schemas)) {
continue;
}
return $finalSchemas;
}
/**
* @param \Symfony\Component\HttpKernel\Bundle\BundleInterface
*/
protected function getSchemasFromBundle(BundleInterface $bundle)
{
$finalSchemas = array();
if (is_dir($dir = $bundle->getPath().'/Resources/config')) {
$finder = new Finder();
$schemas = $finder->files()->name('*schema.xml')->followLinks()->in($dir);
if (iterator_count($schemas)) {
foreach ($schemas as $schema) {
$logicalName = $this->transformToLogicalName($schema, $bundle);
$finalSchema = new \SplFileInfo($this->getFileLocator()->locate($logicalName));
@ -255,6 +265,11 @@ abstract class AbstractPropelCommand extends ContainerAwareCommand
return $finalSchemas;
}
protected function getRelativeFileName(\SplFileInfo $file)
{
return substr(str_replace(realpath($this->getContainer()->getParameter('kernel.root_dir') . '/../'), '', $file), 1);
}
/**
* Create a 'build.properties' file.
*
@ -424,7 +439,7 @@ EOT;
* Write Propel output as summary based on a Regexp.
*
* @param OutputInterface $output The output object.
* @param string $taskname A task name
* @param string $taskname A task name
*/
protected function writeSummary(OutputInterface $output, $taskname)
{
@ -447,8 +462,8 @@ EOT;
* @see https://github.com/sensio/SensioGeneratorBundle/blob/master/Command/Helper/DialogHelper.php#L52
*
* @param OutputInterface $output The output.
* @param string $text A text message.
* @param string $style A style to apply on the section.
* @param string $text A text message.
* @param string $style A style to apply on the section.
*/
protected function writeSection(OutputInterface $output, $text, $style = 'bg=blue;fg=white')
{
@ -463,8 +478,8 @@ EOT;
* Renders an error message if a task has failed.
*
* @param OutputInterface $output The output.
* @param string $taskName A task name.
* @param Boolean $more Whether to add a 'more details' message or not.
* @param string $taskName A task name.
* @param Boolean $more Whether to add a 'more details' message or not.
*/
protected function writeTaskError($output, $taskName, $more = true)
{
@ -479,25 +494,42 @@ EOT;
/**
* @param OutputInterface $output The output.
* @param string $filename The filename.
* @param string $filename The filename.
*/
protected function writeNewFile($output, $filename)
{
return $output->writeln('>> <info>File+</info> ' . $filename);
}
/**
* @param OutputInterface $output The output.
* @param string $directory The directory.
*/
protected function writeNewDirectory($output, $directory)
{
return $output->writeln('>> <info>Dir+</info> ' . $directory);
}
/**
* Ask confirmation from the user.
*
* @param OutputInterface $output The output.
* @param string $question A given question.
* @param string $default A default response.
* @param string $question A given question.
* @param string $default A default response.
*/
protected function askConfirmation(OutputInterface $output, $question, $default = null)
{
return $this->getHelperSet()->get('dialog')->askConfirmation($output, $question, $default);
}
/**
* @return \Symfony\Component\Config\FileLocatorInterface
*/
protected function getFileLocator()
{
return $this->getContainer()->get('file_locator');
}
private function transformToLogicalName(\SplFileInfo $schema, BundleInterface $bundle)
{
$schemaPath = str_replace($bundle->getPath(). DIRECTORY_SEPARATOR . 'Resources' . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR, '', $schema->getRealPath());
@ -505,11 +537,6 @@ EOT;
return sprintf('@%s/Resources/config/%s', $bundle->getName(), $schemaPath);
}
protected function getFileLocator()
{
return $this->getContainer()->get('file_locator');
}
/**
* Compiles arguments/properties for the Phing process.
* @return array