This repository has been archived by the owner on Sep 30, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 138
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
36 changed files
with
910 additions
and
59 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
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,105 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Sonata Connector project. | ||
* | ||
* (c) Sylvain Rascar <sylvain.rascar@fullsix.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Sonata\CoreBundle\Command; | ||
|
||
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand; | ||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Input\InputOption; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
use Symfony\Component\HttpKernel\Kernel; | ||
|
||
class SonataListFormMappingCommand extends ContainerAwareCommand | ||
{ | ||
/** | ||
* @var array | ||
*/ | ||
protected $metadata; | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected function configure() | ||
{ | ||
$this | ||
->setName('sonata:core:form-mapping') | ||
->addOption('format', 'f', InputOption::VALUE_REQUIRED, 'Output the mapping into a dedicated format (available: yaml, php)', 'yaml') | ||
->setDescription( | ||
'Get information on the current form mapping' | ||
); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function isEnabled() | ||
{ | ||
return Kernel::MAJOR_VERSION !== 3; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected function execute(InputInterface $input, OutputInterface $output) | ||
{ | ||
$output->writeln('Getting form types:'); | ||
foreach ($this->getContainer()->getParameter('sonata.core.form.types') as $id) { | ||
try { | ||
$instance = $this->getContainer()->get($id); | ||
|
||
if ($input->getOption('format') == 'yaml') { | ||
$output->writeln(sprintf(' %s: %s', $instance->getName(), get_class($instance))); | ||
} else { | ||
$output->writeln(sprintf(" '%s' => '%s',", $instance->getName(), get_class($instance))); | ||
} | ||
} catch (\Exception $e) { | ||
$output->writeln(sprintf('<error>Unable load service: %s</error>', $id)); | ||
} | ||
} | ||
|
||
$output->writeln("\n\n\nGetting form type extensions:"); | ||
$types = array(); | ||
foreach ($this->getContainer()->getParameter('sonata.core.form.type_extensions') as $id) { | ||
try { | ||
$instance = $this->getContainer()->get($id); | ||
if (!isset($types[$instance->getExtendedType()])) { | ||
$types[$instance->getExtendedType()] = array(); | ||
} | ||
|
||
$types[$instance->getExtendedType()][] = $id; | ||
} catch (\Exception $e) { | ||
$output->writeln(sprintf('<error>Unable load service: %s</error>', $id)); | ||
} | ||
} | ||
|
||
foreach ($types as $type => $classes) { | ||
if ($input->getOption('format') == 'yaml') { | ||
$output->writeln(sprintf(' %s: ', $type)); | ||
} else { | ||
$output->writeln(sprintf(" '%s' => array( ", $type)); | ||
} | ||
|
||
foreach ($classes as $class) { | ||
if ($input->getOption('format') == 'yaml') { | ||
$output->writeln(sprintf(' - %s', $class)); | ||
} else { | ||
$output->writeln(sprintf(" '%s',", $class)); | ||
} | ||
} | ||
|
||
if ($input->getOption('format') == 'php') { | ||
$output->writeln(' ), '); | ||
} | ||
} | ||
|
||
return 0; | ||
} | ||
} |
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,55 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Sonata package. | ||
* | ||
* (c) Thomas Rabaix <thomas.rabaix@sonata-project.org> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Sonata\CoreBundle\DependencyInjection\Compiler; | ||
|
||
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; | ||
use Symfony\Component\DependencyInjection\ContainerBuilder; | ||
|
||
class FormFactoryCompilerPass implements CompilerPassInterface | ||
{ | ||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function process(ContainerBuilder $container) | ||
{ | ||
$typeIdx = array(); | ||
foreach ($container->findTaggedServiceIds('form.type') as $id => $tags) { | ||
$typeIdx[] = $id; | ||
} | ||
|
||
$typeExtensionIdx = array(); | ||
foreach ($container->findTaggedServiceIds('form.type_extension') as $id => $tag) { | ||
$typeExtensionIdx[] = $id; | ||
} | ||
|
||
$container->setParameter('sonata.core.form.types', $typeIdx); | ||
$container->setParameter('sonata.core.form.type_extensions', $typeExtensionIdx); | ||
|
||
// nothing to do | ||
if (!$container->hasDefinition('sonata.core.form.extension.dependency')) { | ||
return; | ||
} | ||
|
||
// get factories | ||
$original = $container->getDefinition('form.extension'); | ||
|
||
$factory = $container->getDefinition('sonata.core.form.extension.dependency'); | ||
$factory->replaceArgument(1, $original->getArgument(1)); | ||
$factory->replaceArgument(2, $original->getArgument(2)); | ||
$factory->replaceArgument(3, $original->getArgument(3)); | ||
|
||
$container->removeDefinition('form.extension'); | ||
$container->removeDefinition('sonata.core.form.extension.dependency'); | ||
|
||
$container->setDefinition('form.extension', $factory); | ||
} | ||
} |
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
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
Oops, something went wrong.