Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move internal configuration to PHP #132

Merged
merged 1 commit into from
Sep 4, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/Bridge/Symfony/DependencyInjection/SonataFormExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface;
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
use Symfony\Component\DependencyInjection\Loader\PhpFileLoader;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;

/**
Expand Down Expand Up @@ -47,10 +47,10 @@ public function load(array $configs, ContainerBuilder $container): void
$configuration = new Configuration();
$config = $processor->processConfiguration($configuration, $configs);

$loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
$loader->load('date.xml');
$loader->load('form_types.xml');
$loader->load('validator.xml');
$loader = new PhpFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
$loader->load('date.php');
$loader->load('form_types.php');
$loader->load('validator.php');

$container->setParameter('sonata.form.form_type', $config['form_type']);

Expand Down
21 changes: 21 additions & 0 deletions src/Bridge/Symfony/Resources/config/date.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

declare(strict_types=1);

/*
* This file is part of the Sonata Project package.
*
* (c) Thomas Rabaix <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

use Sonata\Form\Date\MomentFormatConverter;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;

return static function (ContainerConfigurator $containerConfigurator): void {
$containerConfigurator->services()

->set('sonata.form.date.moment_format_converter', MomentFormatConverter::class);
};
6 changes: 0 additions & 6 deletions src/Bridge/Symfony/Resources/config/date.xml

This file was deleted.

106 changes: 106 additions & 0 deletions src/Bridge/Symfony/Resources/config/form_types.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
<?php

declare(strict_types=1);

/*
* This file is part of the Sonata Project package.
*
* (c) Thomas Rabaix <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

use Sonata\Form\Type\BooleanType;
use Sonata\Form\Type\CollectionType;
use Sonata\Form\Type\DatePickerType;
use Sonata\Form\Type\DateRangePickerType;
use Sonata\Form\Type\DateRangeType;
use Sonata\Form\Type\DateTimePickerType;
use Sonata\Form\Type\DateTimeRangePickerType;
use Sonata\Form\Type\DateTimeRangeType;
use Sonata\Form\Type\EqualType;
use Sonata\Form\Type\ImmutableArrayType;
use Symfony\Component\Config\Definition\BaseNode;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
use Symfony\Component\DependencyInjection\Loader\Configurator\ReferenceConfigurator;

return static function (ContainerConfigurator $containerConfigurator): void {
// BC layer for deprecation messages for symfony/config < 5.1
$getDeprecationParameters = static function (string $message, string $version): array {
if (method_exists(BaseNode::class, 'getDeprecation')) {
return [
'sonata-project/form-extensions',
$version,
$message,
];
}

return [$message];
};

// Use "service" function for creating references to services when dropping support for Symfony 4.4
// Use "param" function for creating references to parameters when dropping support for Symfony 5.1
$containerConfigurator->services()

->set('sonata.form.type.array', ImmutableArrayType::class)
->tag('form.type', ['alias' => 'sonata_type_immutable_array'])

->set('sonata.form.type.boolean', BooleanType::class)
->tag('form.type', ['alias' => 'sonata_type_boolean'])

->set('sonata.form.type.collection', CollectionType::class)
->tag('form.type', ['alias' => 'sonata_type_collection'])

->set('sonata.form.type.date_range', DateRangeType::class)
->tag('form.type', ['alias' => 'sonata_type_date_range'])
->args([
new ReferenceConfigurator('translator'),
])

->set('sonata.form.type.datetime_range', DateTimeRangeType::class)
->tag('form.type', ['alias' => 'sonata_type_datetime_range'])
->args([
new ReferenceConfigurator('translator'),
])

->set('sonata.form.type.date_picker', DatePickerType::class)
->tag('kernel.locale_aware')
->tag('form.type', ['alias' => 'sonata_type_date_picker'])
->args([
new ReferenceConfigurator('sonata.form.date.moment_format_converter'),
new ReferenceConfigurator('translator'),
'%kernel.default_locale%',
])

->set('sonata.form.type.datetime_picker', DateTimePickerType::class)
->tag('kernel.locale_aware')
->tag('form.type', ['alias' => 'sonata_type_datetime_picker'])
->args([
new ReferenceConfigurator('sonata.form.date.moment_format_converter'),
new ReferenceConfigurator('translator'),
'%kernel.default_locale%',
])

->set('sonata.form.type.date_range_picker', DateRangePickerType::class)
->tag('form.type', ['alias' => 'sonata_type_date_range_picker'])
->args([
new ReferenceConfigurator('translator'),
])

->set('sonata.form.type.datetime_range_picker', DateTimeRangePickerType::class)
->tag('form.type', ['alias' => 'sonata_type_datetime_range_picker'])
->args([
new ReferenceConfigurator('translator'),
])

->set('sonata.form.type.equal', EqualType::class)
->tag('form.type', ['alias' => 'sonata_type_equal'])
->deprecate(...$getDeprecationParameters(
'The "%service_id%" service is deprecated since sonata-project/form-extensions 1.2 and will be removed in 2.0. Use Sonata\AdminBundle\Form\Type\Operator\EqualOperatorType instead',
'1.2'
))
->args([
new ReferenceConfigurator('translator'),
]);
};
49 changes: 0 additions & 49 deletions src/Bridge/Symfony/Resources/config/form_types.xml

This file was deleted.

29 changes: 29 additions & 0 deletions src/Bridge/Symfony/Resources/config/validator.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

declare(strict_types=1);

/*
* This file is part of the Sonata Project package.
*
* (c) Thomas Rabaix <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

use Sonata\Form\Validator\InlineValidator;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
use Symfony\Component\DependencyInjection\Loader\Configurator\ReferenceConfigurator;

return static function (ContainerConfigurator $containerConfigurator): void {
$containerConfigurator->services()
// Use "service" function for creating references to services when dropping support for Symfony 4.4
->set('sonata.form.validator.inline', InlineValidator::class)
->tag('validator.constraint_validator', [
'alias' => 'sonata.form.validator.inline',
])
->args([
new ReferenceConfigurator('service_container'),
new ReferenceConfigurator('validator.validator_factory'),
]);
};
10 changes: 0 additions & 10 deletions src/Bridge/Symfony/Resources/config/validator.xml

This file was deleted.