Skip to content

Commit

Permalink
Move configuration to PHP
Browse files Browse the repository at this point in the history
  • Loading branch information
franmomu committed Sep 1, 2020
1 parent b65b5c6 commit ea9d3a3
Show file tree
Hide file tree
Showing 31 changed files with 1,042 additions and 493 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"symfony/asset": "^4.4",
"symfony/config": "^4.4",
"symfony/console": "^4.4",
"symfony/dependency-injection": "^4.4.3",
"symfony/dependency-injection": "^4.4.8",
"symfony/doctrine-bridge": "^4.4",
"symfony/event-dispatcher": "^4.4",
"symfony/event-dispatcher-contracts": "^1.1 || ^2.0",
Expand Down
34 changes: 17 additions & 17 deletions src/DependencyInjection/SonataAdminExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,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\DependencyInjection\Reference;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType as SymfonyChoiceType;
use Symfony\Component\Form\Extension\Core\Type\DateTimeType as SymfonyDateTimeType;
Expand Down Expand Up @@ -59,24 +59,24 @@ public function load(array $configs, ContainerBuilder $container)
]);
}

$loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
$loader->load('actions.xml');
$loader->load('block.xml');
$loader->load('commands.xml');
$loader->load('core.xml');
$loader->load('event_listener.xml');
$loader->load('form_types.xml');
$loader->load('menu.xml');
$loader->load('route.xml');
$loader->load('twig.xml');
$loader->load('validator.xml');
$loader = new PhpFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
$loader->load('actions.php');
$loader->load('block.php');
$loader->load('commands.php');
$loader->load('core.php');
$loader->load('event_listener.php');
$loader->load('form_types.php');
$loader->load('menu.php');
$loader->load('route.php');
$loader->load('twig.php');
$loader->load('validator.php');

if (isset($bundles['MakerBundle'])) {
$loader->load('makers.xml');
$loader->load('makers.php');
}

if (isset($bundles['SonataExporterBundle'])) {
$loader->load('exporter.xml');
$loader->load('exporter.php');
}

$configuration = $this->getConfiguration($configs, $container);
Expand Down Expand Up @@ -157,7 +157,7 @@ public function load(array $configs, ContainerBuilder $container)
$container->setParameter('sonata.admin.configuration.security.admin_permissions', $config['security']['admin_permissions']);
$container->setParameter('sonata.admin.configuration.security.object_permissions', $config['security']['object_permissions']);

$loader->load('security.xml');
$loader->load('security.php');

$container->setParameter('sonata.admin.extension.map', $config['extensions']);

Expand Down Expand Up @@ -272,10 +272,10 @@ private function replacePropertyAccessor(ContainerBuilder $container): void
/**
* NEXT_MAJOR: remove this method.
*/
private function configureTwigTextExtension(ContainerBuilder $container, XmlFileLoader $loader, array $config): void
private function configureTwigTextExtension(ContainerBuilder $container, PhpFileLoader $loader, array $config): void
{
$container->setParameter('sonata.admin.configuration.legacy_twig_text_extension', $config['options']['legacy_twig_text_extension']);
$loader->load('twig_string.xml');
$loader->load('twig_string.php');

if (false !== $config['options']['legacy_twig_text_extension']) {
$container
Expand Down
2 changes: 1 addition & 1 deletion src/Export/Exporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,6 @@ public function __construct()
} else {
class_alias(
BaseExporter::class,
__NAMESPACE__.'\Exporter'
'Sonata\AdminBundle\Export\Exporter'
);
}
86 changes: 86 additions & 0 deletions src/Resources/config/actions.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
<?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\AdminBundle\Action\AppendFormFieldElementAction;
use Sonata\AdminBundle\Action\DashboardAction;
use Sonata\AdminBundle\Action\GetShortObjectDescriptionAction;
use Sonata\AdminBundle\Action\RetrieveAutocompleteItemsAction;
use Sonata\AdminBundle\Action\RetrieveFormFieldElementAction;
use Sonata\AdminBundle\Action\SearchAction;
use Sonata\AdminBundle\Action\SetObjectFieldValueAction;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
use Symfony\Component\DependencyInjection\Loader\Configurator\ReferenceConfigurator;

return static function (ContainerConfigurator $containerConfigurator): void {
// Use "service" and "param" functions for creating references to services and parameters
// when dropping support for Symfony 4.4
$containerConfigurator->services()

->set(DashboardAction::class, DashboardAction::class)
->public()
->args([
'%sonata.admin.configuration.dashboard_blocks%',
new ReferenceConfigurator('sonata.admin.breadcrumbs_builder'),
new ReferenceConfigurator('sonata.admin.global_template_registry'),
new ReferenceConfigurator('sonata.admin.pool'),
new ReferenceConfigurator('twig'),
])

->set(SearchAction::class, SearchAction::class)
->public()
->args([
new ReferenceConfigurator('sonata.admin.pool'),
new ReferenceConfigurator('sonata.admin.search.handler'),
new ReferenceConfigurator('sonata.admin.global_template_registry'),
new ReferenceConfigurator('sonata.admin.breadcrumbs_builder'),
new ReferenceConfigurator('twig'),
])

->set('sonata.admin.action.append_form_field_element', AppendFormFieldElementAction::class)
->public()
->args([
new ReferenceConfigurator('twig'),
new ReferenceConfigurator('sonata.admin.pool'),
new ReferenceConfigurator('sonata.admin.helper'),
])

->set('sonata.admin.action.retrieve_form_field_element', RetrieveFormFieldElementAction::class)
->public()
->args([
new ReferenceConfigurator('twig'),
new ReferenceConfigurator('sonata.admin.pool'),
new ReferenceConfigurator('sonata.admin.helper'),
])

->set('sonata.admin.action.get_short_object_description', GetShortObjectDescriptionAction::class)
->public()
->args([
new ReferenceConfigurator('twig'),
new ReferenceConfigurator('sonata.admin.pool'),
])

->set('sonata.admin.action.set_object_field_value', SetObjectFieldValueAction::class)
->public()
->args([
new ReferenceConfigurator('twig'),
new ReferenceConfigurator('sonata.admin.pool'),
new ReferenceConfigurator('validator'),
])

->set('sonata.admin.action.retrieve_autocomplete_items', RetrieveAutocompleteItemsAction::class)
->public()
->args([
new ReferenceConfigurator('sonata.admin.pool'),
])
;
};
42 changes: 0 additions & 42 deletions src/Resources/config/actions.xml

This file was deleted.

51 changes: 51 additions & 0 deletions src/Resources/config/block.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?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\AdminBundle\Block\AdminListBlockService;
use Sonata\AdminBundle\Block\AdminSearchBlockService;
use Sonata\AdminBundle\Block\AdminStatsBlockService;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
use Symfony\Component\DependencyInjection\Loader\Configurator\ReferenceConfigurator;

return static function (ContainerConfigurator $containerConfigurator): void {
// Use "service" and "param" functions for creating references to services and parameters
// when dropping support for Symfony 4.4
$containerConfigurator->services()

->set('sonata.admin.block.admin_list', AdminListBlockService::class)
->public()
->tag('sonata.block')
->args([
new ReferenceConfigurator('twig'),
new ReferenceConfigurator('sonata.admin.pool'),
new ReferenceConfigurator('sonata.admin.global_template_registry'),
])

->set('sonata.admin.block.search_result', AdminSearchBlockService::class)
->public()
->tag('sonata.block')
->args([
new ReferenceConfigurator('twig'),
new ReferenceConfigurator('sonata.admin.pool'),
new ReferenceConfigurator('sonata.admin.search.handler'),
])

->set('sonata.admin.block.stats', AdminStatsBlockService::class)
->public()
->tag('sonata.block')
->args([
new ReferenceConfigurator('twig'),
new ReferenceConfigurator('sonata.admin.pool'),
])
;
};
22 changes: 0 additions & 22 deletions src/Resources/config/block.xml

This file was deleted.

71 changes: 71 additions & 0 deletions src/Resources/config/commands.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<?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\AdminBundle\Command\CreateClassCacheCommand;
use Sonata\AdminBundle\Command\ExplainAdminCommand;
use Sonata\AdminBundle\Command\GenerateObjectAclCommand;
use Sonata\AdminBundle\Command\ListAdminCommand;
use Sonata\AdminBundle\Command\SetupAclCommand;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
use Symfony\Component\DependencyInjection\Loader\Configurator\ReferenceConfigurator;

return static function (ContainerConfigurator $containerConfigurator): void {
// Use "service" and "param" functions for creating references to services and parameters
// when dropping support for Symfony 4.4
$containerConfigurator->services()

// NEXT_MAJOR: Remove this service.
->set(CreateClassCacheCommand::class, CreateClassCacheCommand::class)
->public()
->tag('console.command', [
'command' => 'cache:create-cache-class',
])
->deprecate('The "%service_id%" service is deprecated since version sonata-project/admin-bundle 3.39.0 and will be removed in 4.0.')
->args([
'%kernel.cache_dir%',
'%kernel.debug%',
])

->set(ExplainAdminCommand::class, ExplainAdminCommand::class)
->public()
->tag('console.command')
->args([
new ReferenceConfigurator('sonata.admin.pool'),
new ReferenceConfigurator('validator'),
])

->set(GenerateObjectAclCommand::class, GenerateObjectAclCommand::class)
->public()
->tag('console.command')
->args([
new ReferenceConfigurator('sonata.admin.pool'),
[],
(new ReferenceConfigurator('doctrine'))->nullOnInvalid(),
])

->set(ListAdminCommand::class, ListAdminCommand::class)
->public()
->tag('console.command')
->args([
new ReferenceConfigurator('sonata.admin.pool'),
])

->set(SetupAclCommand::class, SetupAclCommand::class)
->public()
->tag('console.command')
->args([
new ReferenceConfigurator('sonata.admin.pool'),
new ReferenceConfigurator('sonata.admin.manipulator.acl.admin'),
])
;
};
31 changes: 0 additions & 31 deletions src/Resources/config/commands.xml

This file was deleted.

Loading

0 comments on commit ea9d3a3

Please sign in to comment.