Skip to content
This repository has been archived by the owner on Sep 30, 2021. It is now read-only.

Commit

Permalink
fix deprecated notices
Browse files Browse the repository at this point in the history
  • Loading branch information
rande committed Nov 23, 2015
1 parent abc144d commit 0bd414f
Show file tree
Hide file tree
Showing 36 changed files with 910 additions and 59 deletions.
7 changes: 4 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,20 @@ matrix:
- php: 5.6
env: SYMFONY_VERSION=2.8.*@dev
- php: 5.6
env: SYMFONY_VERSION="3.0.x-dev as 2.8"
env: SYMFONY_VERSION="3.0.x-dev" DEPENDENCIES="dev" COMPOSER_FLAGS="--prefer-stable"
allow_failures:
- php: 7.0
- php: hhvm
- env: SYMFONY_VERSION=2.8.*@dev
- env: SYMFONY_VERSION="3.0.x-dev as 2.8"
- env: SYMFONY_VERSION="3.0.x-dev"

before_script:
- mkdir -p ~/.phpenv/versions/$(phpenv version-name)/etc/conf.d && echo "memory_limit=-1" >> ~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/travis.ini
- composer selfupdate
- composer config -q github-oauth.github.com $GITHUB_OAUTH_TOKEN
- if [ "$SYMFONY_VERSION" = "2.8.*@dev" ] || [ "$SYMFONY_VERSION" = "3.0.x-dev as 2.8" ]; then SYMFONY_DEPRECATIONS_HELPER=strict; fi;
- if [ "$SYMFONY_VERSION" = "2.8.*@dev" ] || [ "$SYMFONY_VERSION" = "3.0.x-dev" ]; then SYMFONY_DEPRECATIONS_HELPER=strict; fi;
- if [ "$SYMFONY_VERSION" != "" ]; then composer require "symfony/symfony:${SYMFONY_VERSION}" --no-update; fi;
- if [ "$DEPENDENCIES" = "dev" ]; then perl -pi -e 's/^}$/,"minimum-stability":"dev"}/' composer.json; fi;
- travis_wait composer update --prefer-dist --no-interaction $COMPOSER_FLAGS
- export PATH=$HOME/.local/bin:$PATH
- pip install -r Resources/doc/requirements.txt --user `whoami`
Expand Down
105 changes: 105 additions & 0 deletions Command/SonataListFormMappingCommand.php
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;
}
}
55 changes: 55 additions & 0 deletions DependencyInjection/Compiler/FormFactoryCompilerPass.php
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);
}
}
37 changes: 37 additions & 0 deletions DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

namespace Sonata\CoreBundle\DependencyInjection;

use Sonata\CoreBundle\Form\FormHelper;
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
use Symfony\Component\Config\Definition\ConfigurationInterface;
Expand All @@ -35,6 +36,42 @@ public function getConfigTreeBuilder()

$this->addFlashMessageSection($rootNode);

$rootNode
->children()
->arrayNode('form')
->addDefaultsIfNotSet()
->children()
->booleanNode('force_mapping')
->defaultValue(true)
->end()
->arrayNode('type_mapping')
->useAttributeAsKey('id')
->defaultValue(FormHelper::getFormTypeMapping())
->beforeNormalization()
->always()
->then(function ($mapping) {
return array_merge(FormHelper::getFormTypeMapping(), $mapping);
})
->end()
->prototype('scalar')->end()
->end()

->arrayNode('extension_mapping')
->useAttributeAsKey('id')
->defaultValue(FormHelper::getFormExtensionMapping())
->beforeNormalization()
->always()
->then(function ($mapping) {
return array_merge(FormHelper::getFormExtensionMapping(), $mapping);
})
->end()
->prototype('scalar')->end()
->end()
->end()
->end()
->end()
;

return $treeBuilder;
}

Expand Down
21 changes: 21 additions & 0 deletions DependencyInjection/SonataCoreExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface;
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
use Symfony\Component\HttpKernel\Kernel;

/**
* SonataCoreExtension.
Expand Down Expand Up @@ -61,6 +62,7 @@ public function load(array $configs, ContainerBuilder $container)
$this->registerFlashTypes($container, $config);
$container->setParameter('sonata.core.form_type', $config['form_type']);

$this->configureFormFactory($container, $config);
$this->configureClassesToCompile();
}

Expand All @@ -77,6 +79,25 @@ public function configureClassesToCompile()
));
}

/**
* @param ContainerBuilder $container
* @param array $config
*/
public function configureFormFactory(ContainerBuilder $container, array $config)
{
if (!$config['form']['force_mapping'] || version_compare(Kernel::VERSION, '2.8', '<')) {
$container->removeDefinition('sonata.core.form.extension.dependency');

return;
}

$definition = $container->getDefinition('sonata.core.form.extension.dependency');
$definition->replaceArgument(4, $config['form']['type_mapping']);

$definition = $container->getDefinition('sonata.core.form.extension.dependency');
$definition->replaceArgument(5, $config['form']['extension_mapping']);
}

/**
* Registers flash message types defined in configuration to flash manager.
*
Expand Down
Loading

0 comments on commit 0bd414f

Please sign in to comment.