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 Aug 13, 2020
1 parent 3fa3f49 commit 1dfdf3b
Show file tree
Hide file tree
Showing 16 changed files with 843 additions and 18 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,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
70 changes: 70 additions & 0 deletions src/Resources/config/actions.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
<?php

declare(strict_types=1);

/*
* This file is part of the Sonata Project 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.
*/

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 function Symfony\Component\DependencyInjection\Loader\Configurator\ref;

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

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

$services->set(SearchAction::class, SearchAction::class)
->public()
->args([
ref('sonata.admin.pool'),
ref('sonata.admin.search.handler'),
ref('sonata.admin.global_template_registry'),
ref('sonata.admin.breadcrumbs_builder'),
ref('twig'),
]);

$services->set('sonata.admin.action.append_form_field_element', AppendFormFieldElementAction::class)
->public()
->args([
ref('twig'),
ref('sonata.admin.pool'),
ref('sonata.admin.helper'),
]);

$services->set('sonata.admin.action.retrieve_form_field_element', RetrieveFormFieldElementAction::class)
->public()
->args([ref('twig'), ref('sonata.admin.pool'), ref('sonata.admin.helper')]);

$services->set('sonata.admin.action.get_short_object_description', GetShortObjectDescriptionAction::class)
->public()
->args([ref('twig'), ref('sonata.admin.pool')]);

$services->set('sonata.admin.action.set_object_field_value', SetObjectFieldValueAction::class)
->public()
->args([ref('twig'), ref('sonata.admin.pool'), ref('validator')]);

$services->set('sonata.admin.action.retrieve_autocomplete_items', RetrieveAutocompleteItemsAction::class)
->public()
->args([ref('sonata.admin.pool')]);
};
48 changes: 48 additions & 0 deletions src/Resources/config/block.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php

declare(strict_types=1);

/*
* This file is part of the Sonata Project 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.
*/

use Sonata\AdminBundle\Block\AdminListBlockService;
use Sonata\AdminBundle\Block\AdminSearchBlockService;
use Sonata\AdminBundle\Block\AdminStatsBlockService;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
use function Symfony\Component\DependencyInjection\Loader\Configurator\ref;

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

$services->set('sonata.admin.block.admin_list', AdminListBlockService::class)
->public()
->tag('sonata.block', [])
->args([
ref('twig'),
ref('sonata.admin.pool'),
ref('sonata.admin.global_template_registry'),
]);

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

$services->set('sonata.admin.block.stats', AdminStatsBlockService::class)
->public()
->tag('sonata.block', [])
->args([
ref('twig'),
ref('sonata.admin.pool'),
]);
};
50 changes: 50 additions & 0 deletions src/Resources/config/commands.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php

declare(strict_types=1);

/*
* This file is part of the Sonata Project 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.
*/

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 function Symfony\Component\DependencyInjection\Loader\Configurator\ref;

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

$services->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%']);

$services->set(ExplainAdminCommand::class, ExplainAdminCommand::class)
->public()
->tag('console.command')
->args([ref('sonata.admin.pool'), ref('validator')]);

$services->set(GenerateObjectAclCommand::class, GenerateObjectAclCommand::class)
->public()
->tag('console.command')
->args([ref('sonata.admin.pool'), [], ref('doctrine')->nullOnInvalid()]);

$services->set(ListAdminCommand::class, ListAdminCommand::class)
->public()
->tag('console.command')
->args([ref('sonata.admin.pool')]);

$services->set(SetupAclCommand::class, SetupAclCommand::class)
->public()
->tag('console.command')
->args([ref('sonata.admin.pool'), ref('sonata.admin.manipulator.acl.admin')]);
};
Loading

0 comments on commit 1dfdf3b

Please sign in to comment.