diff --git a/DataSource/Extension/Symfony/Form/Field/FormFieldExtension.php b/DataSource/Extension/Symfony/Form/Field/FormFieldExtension.php index 712e14e..6d014dc 100644 --- a/DataSource/Extension/Symfony/Form/Field/FormFieldExtension.php +++ b/DataSource/Extension/Symfony/Form/Field/FormFieldExtension.php @@ -28,7 +28,6 @@ use Symfony\Component\Form\FormFactory; use Symfony\Component\Form\FormFactoryInterface; use Symfony\Component\Form\FormInterface; -use Symfony\Component\Form\FormTypeInterface; use Symfony\Component\Translation\TranslatorInterface; class FormFieldExtension extends FieldAbstractExtension @@ -173,18 +172,20 @@ protected function getForm(FieldTypeInterface $field, bool $force = false): ?For return $this->forms[$fieldOid]; } - $options = $field->getOption('form_options'); - $options = array_merge($options, ['required' => false, 'auto_initialize' => false]); + $options = array_merge( + $field->getOption('form_options'), + ['required' => false, 'auto_initialize' => false] + ); $form = $this->formFactory->createNamed( $datasource->getName(), - $this->isFqcnFormTypePossible() ? CollectionType::class : 'collection', + CollectionType::class, null, ['csrf_protection' => false] ); $fieldsForm = $this->formFactory->createNamed( DataSourceInterface::PARAMETER_FIELDS, - $this->isFqcnFormTypePossible() ? FormType::class : 'form', + FormType::class, null, ['auto_initialize' => false] ); @@ -193,18 +194,14 @@ protected function getForm(FieldTypeInterface $field, bool $force = false): ?For case 'between': $this->buildBetweenComparisonForm($fieldsForm, $field, $options); break; - case 'isNull': $this->buildIsNullComparisonForm($fieldsForm, $field, $options); break; - default: - switch ($field->getType()) { case 'boolean': $this->buildBooleanForm($fieldsForm, $field, $options); break; - default: $fieldsForm->add($field->getName(), $this->getFieldFormType($field), $options); } @@ -223,7 +220,7 @@ protected function buildBetweenComparisonForm( ): void { $betweenBuilder = $this->getFormFactory()->createNamedBuilder( $field->getName(), - $this->isFqcnFormTypePossible() ? BetweenType::class : 'datasource_between', + BetweenType::class, null, $options ); @@ -252,30 +249,17 @@ protected function buildIsNullComparisonForm(FormInterface $form, FieldTypeInter } $defaultOptions = [ + 'placeholder' => '', 'choices' => [ - $this->translator->trans('datasource.form.choices.is_null', [], 'DataSourceBundle') => 'null', - $this->translator->trans('datasource.form.choices.is_not_null', [], 'DataSourceBundle') => 'no_null' + $this->translator->trans('datasource.form.choices.is_null', [], 'DataSourceBundle') => 'null', + $this->translator->trans('datasource.form.choices.is_not_null', [], 'DataSourceBundle') => 'no_null' ], ]; - if ($this->isSymfonyForm27()) { - $defaultOptions['placeholder'] = ''; - } else { - $defaultOptions['empty_value'] = ''; - $defaultOptions['choices'] = array_flip($defaultOptions['choices']); - if (isset($options['choices'])) { - $options['choices'] = array_merge( - $defaultOptions['choices'], - array_intersect_key($options['choices'], $defaultOptions['choices']) - ); - } - } - - $options = array_merge($defaultOptions, $options); $form->add( $field->getName(), - $this->isFqcnFormTypePossible() ? ChoiceType::class : 'choice', - $options + ChoiceType::class, + array_merge($defaultOptions, $options) ); } @@ -291,27 +275,17 @@ protected function buildBooleanForm(FormInterface $form, FieldTypeInterface $fie } $defaultOptions = [ + 'placeholder' => '', 'choices' => [ $this->translator->trans('datasource.form.choices.yes', [], 'DataSourceBundle') => '1', - $this->translator->trans('datasource.form.choices.no', [], 'DataSourceBundle') => '0', + $this->translator->trans('datasource.form.choices.no', [], 'DataSourceBundle') => '0' ], ]; - if ($this->isSymfonyForm27()) { - $defaultOptions['placeholder'] = ''; - } else { - $defaultOptions['empty_value'] = ''; - $defaultOptions['choices'] = array_flip($defaultOptions['choices']); - if (isset($options['choices'])) { - $options['choices'] = array_intersect_key($options['choices'], $defaultOptions['choices']); - } - } - - $options = array_merge($defaultOptions, $options); $form->add( $field->getName(), - $this->isFqcnFormTypePossible() ? ChoiceType::class : 'choice', - $options + ChoiceType::class, + array_merge($defaultOptions, $options) ); } @@ -327,11 +301,6 @@ private function getFieldFormType(FieldTypeInterface $field): string } $declaredType = $field->getType(); - - if (!$this->isFqcnFormTypePossible()) { - return $declaredType; - } - switch ($declaredType) { case 'text': return TextType::class; @@ -372,7 +341,7 @@ private function getParameterValue(array $array, FieldTypeInterface $field) * @param FieldTypeInterface $field * @param mixed $value */ - private function setParameterValue(array &$array, FieldTypeInterface $field, $value) + private function setParameterValue(array &$array, FieldTypeInterface $field, $value): void { $array[$field->getDataSource()->getName()][DataSourceInterface::PARAMETER_FIELDS][$field->getName()] = $value; } @@ -381,14 +350,4 @@ private function clearParameterValue(array &$array, FieldTypeInterface $field): { unset($array[$field->getDataSource()->getName()][DataSourceInterface::PARAMETER_FIELDS][$field->getName()]); } - - private function isFqcnFormTypePossible(): bool - { - return class_exists('Symfony\Component\Form\Extension\Core\Type\RangeType'); - } - - private function isSymfonyForm27(): bool - { - return method_exists(FormTypeInterface::class, 'configureOptions'); - } } diff --git a/DataSource/Extension/Symfony/Form/Type/BetweenType.php b/DataSource/Extension/Symfony/Form/Type/BetweenType.php index d9bfd13..ba01fc6 100644 --- a/DataSource/Extension/Symfony/Form/Type/BetweenType.php +++ b/DataSource/Extension/Symfony/Form/Type/BetweenType.php @@ -11,39 +11,14 @@ use Symfony\Component\Form\AbstractType; use Symfony\Component\OptionsResolver\OptionsResolver; -use Symfony\Component\OptionsResolver\OptionsResolverInterface; class BetweenType extends AbstractType { - /** - * {@inheritdoc} - */ - public function setDefaultOptions(OptionsResolverInterface $resolver) - { - $resolver->setDefaults(['label' => false]); - } - - /** - * {@inheritdoc} - */ public function configureOptions(OptionsResolver $resolver) { $resolver->setDefaults(['label' => false]); } - /** - * Returns the name of this type. - * - * @return string The name of this type - */ - public function getName() - { - return 'datasource_between'; - } - - /** - * @return string - */ public function getBlockPrefix() { return 'datasource_between'; diff --git a/DependencyInjection/Compiler/TemplatePathPass.php b/DependencyInjection/Compiler/TemplatePathPass.php index c15dd40..6afd069 100644 --- a/DependencyInjection/Compiler/TemplatePathPass.php +++ b/DependencyInjection/Compiler/TemplatePathPass.php @@ -9,28 +9,24 @@ namespace FSi\Bundle\DataSourceBundle\DependencyInjection\Compiler; -use Symfony\Component\DependencyInjection\ContainerBuilder; +use FSi\Bundle\DataSourceBundle\DataSourceBundle; +use ReflectionClass; use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; +use Symfony\Component\DependencyInjection\ContainerBuilder; class TemplatePathPass implements CompilerPassInterface { public function process(ContainerBuilder $container) { - $loaderDefinition = null; - - if ($container->hasDefinition('twig.loader.filesystem')) { - $loaderDefinition = $container->getDefinition('twig.loader.filesystem'); - } elseif ($container->hasDefinition('twig.loader')) { - // Symfony 2.0 and 2.1 were not using an alias for the filesystem loader - $loaderDefinition = $container->getDefinition('twig.loader'); - } - + $loaderDefinition = $container->getDefinition('twig.loader.filesystem'); if (null === $loaderDefinition) { return; } - $refl = new \ReflectionClass('FSi\Bundle\DataSourceBundle\DataSourceBundle'); - $path = dirname($refl->getFileName()).'/Resources/views'; - $loaderDefinition->addMethodCall('addPath', [$path]); + $reflection = new ReflectionClass(DataSourceBundle::class); + $loaderDefinition->addMethodCall( + 'addPath', + [dirname($reflection->getFileName()).'/Resources/views'] + ); } } diff --git a/DependencyInjection/FSIDataSourceExtension.php b/DependencyInjection/FSIDataSourceExtension.php index 477fe38..205e55f 100644 --- a/DependencyInjection/FSIDataSourceExtension.php +++ b/DependencyInjection/FSIDataSourceExtension.php @@ -9,6 +9,15 @@ namespace FSi\Bundle\DataSourceBundle\DependencyInjection; +use FSi\Bundle\DataSourceBundle\DataSource\Extension\Symfony\DependencyInjection\Driver\Collection\EventSubscriberInterface; +use FSi\Bundle\DataSourceBundle\DataSource\Extension\Symfony\DependencyInjection\Driver\Collection\FieldEventSubscriberInterface; +use FSi\Bundle\DataSourceBundle\DataSource\Extension\Symfony\DependencyInjection\Driver\Doctrine\DBAL\EventSubscriberInterface; +use FSi\Bundle\DataSourceBundle\DataSource\Extension\Symfony\DependencyInjection\Driver\Doctrine\ORM; +use FSi\Component\DataSource\Driver\Collection\CollectionAbstractField; +use FSi\Component\DataSource\Driver\Doctrine\DBAL\DBALAbstractField; +use FSi\Component\DataSource\Driver\Doctrine\ORM\DoctrineAbstractField; +use FSi\Component\DataSource\Driver\DriverExtensionInterface; +use FSi\Component\DataSource\Driver\DriverFactoryInterface; use Symfony\Component\Config\FileLocator; use Symfony\Component\Config\Loader\LoaderInterface; use Symfony\Component\DependencyInjection\ContainerBuilder; @@ -48,53 +57,38 @@ public function load(array $configs, ContainerBuilder $container) private function registerDrivers(LoaderInterface $loader): void { $loader->load('driver/collection.xml'); - /* doctrine driver is loaded for compatibility with fsi/datasource 1.x only */ - if (class_exists('FSi\Component\DataSource\Driver\Doctrine\DoctrineDriver')) { - $loader->load('driver/doctrine.xml'); - } - if (class_exists('FSi\Component\DataSource\Driver\Doctrine\ORM\DoctrineDriver')) { - $loader->load('driver/doctrine-orm.xml'); - } - if (class_exists('FSi\Component\DataSource\Driver\Doctrine\DBAL\DBALDriver')) { - $loader->load('driver/doctrine-dbal.xml'); - } + $loader->load('driver/doctrine-orm.xml'); + $loader->load('driver/doctrine-dbal.xml'); } private function registerForAutoconfiguration(ContainerBuilder $container): void { - $container->registerForAutoconfiguration('FSi\Component\DataSource\Driver\DriverFactoryInterface') - ->addTag('datasource.driver.factory'); - $container->registerForAutoconfiguration('FSi\Component\DataSource\Driver\DriverExtensionInterface') - ->addTag('datasource.driver.extension'); - $container->registerForAutoconfiguration('FSi\Component\DataSource\Driver\Collection\CollectionAbstractField') - ->addTag('datasource.driver.collection.field'); - $container->registerForAutoconfiguration('FSi\Bundle\DataSourceBundle\DataSource\Extension\Symfony\DependencyInjection\Driver\Collection\FieldEventSubscriberInterface') - ->addTag('datasource.driver.collection.field.subscriber'); - $container->registerForAutoconfiguration('FSi\Bundle\DataSourceBundle\DataSource\Extension\Symfony\DependencyInjection\Driver\Collection\EventSubscriberInterface') - ->addTag('datasource.driver.collection.subscriber'); - if (class_exists('FSi\Component\DataSource\Driver\Doctrine\DoctrineDriver')) { - $container->registerForAutoconfiguration('FSi\Component\DataSource\Driver\Doctrine\DoctrineAbstractField') - ->addTag('datasource.driver.doctrine.field'); - $container->registerForAutoconfiguration('FSi\Bundle\DataSourceBundle\DataSource\Extension\Symfony\DependencyInjection\Driver\Doctrine\FieldEventSubscriberInterface') - ->addTag('datasource.driver.doctrine.field.subscriber'); - $container->registerForAutoconfiguration('FSi\Bundle\DataSourceBundle\DataSource\Extension\Symfony\DependencyInjection\Driver\Doctrine\EventSubscriberInterface') - ->addTag('datasource.driver.doctrine.subscriber'); - } - if (class_exists('FSi\Component\DataSource\Driver\Doctrine\ORM\DoctrineDriver')) { - $container->registerForAutoconfiguration('FSi\Component\DataSource\Driver\Doctrine\ORM\DoctrineAbstractField') - ->addTag('datasource.driver.doctrine-orm.field'); - $container->registerForAutoconfiguration('FSi\Bundle\DataSourceBundle\DataSource\Extension\Symfony\DependencyInjection\Driver\Doctrine\ORM\FieldEventSubscriberInterface') - ->addTag('datasource.driver.doctrine-orm.field.subscriber'); - $container->registerForAutoconfiguration('FSi\Bundle\DataSourceBundle\DataSource\Extension\Symfony\DependencyInjection\Driver\Doctrine\ORM\EventSubscriberInterface') - ->addTag('datasource.driver.doctrine-orm.subscriber'); - } - if (class_exists('FSi\Component\DataSource\Driver\Doctrine\DBAL\DBALDriver')) { - $container->registerForAutoconfiguration('FSi\Component\DataSource\Driver\Doctrine\DBAL\DBALAbstractField') - ->addTag('datasource.driver.doctrine-dbal.field'); - $container->registerForAutoconfiguration('FSi\Bundle\DataSourceBundle\DataSource\Extension\Symfony\DependencyInjection\Driver\Doctrine\DBAL\FieldEventSubscriberInterface') - ->addTag('datasource.driver.doctrine-dbal.field.subscriber'); - $container->registerForAutoconfiguration('FSi\Bundle\DataSourceBundle\DataSource\Extension\Symfony\DependencyInjection\Driver\Doctrine\DBAL\EventSubscriberInterface') - ->addTag('datasource.driver.doctrine-dbal.subscriber'); - } + $container->registerForAutoconfiguration(DriverFactoryInterface::class)->addTag('datasource.driver.factory'); + $container->registerForAutoconfiguration(DriverExtensionInterface::class)->addTag('datasource.driver.extension'); + $container->registerForAutoconfiguration(CollectionAbstractField::class)->addTag('datasource.driver.collection.field'); + $container->registerForAutoconfiguration(FieldEventSubscriberInterface::class) + ->addTag('datasource.driver.collection.field.subscriber') + ; + $container->registerForAutoconfiguration(EventSubscriberInterface::class) + ->addTag('datasource.driver.collection.subscriber') + ; + $container->registerForAutoconfiguration(DoctrineAbstractField::class) + ->addTag('datasource.driver.doctrine-orm.field') + ; + $container->registerForAutoconfiguration(ORM\FieldEventSubscriberInterface::class) + ->addTag('datasource.driver.doctrine-orm.field.subscriber') + ; + $container->registerForAutoconfiguration(ORM\EventSubscriberInterface::class) + ->addTag('datasource.driver.doctrine-orm.subscriber') + ; + $container->registerForAutoconfiguration(DBALAbstractField::class) + ->addTag('datasource.driver.doctrine-dbal.field') + ; + $container->registerForAutoconfiguration(DBAL\FieldEventSubscriberInterface::class) + ->addTag('datasource.driver.doctrine-dbal.field.subscriber') + ; + $container->registerForAutoconfiguration(DBAL\EventSubscriberInterface::class) + ->addTag('datasource.driver.doctrine-dbal.subscriber') + ; } } diff --git a/Resources/views/datasource.html.twig b/Resources/views/datasource.html.twig index bcde60f..ff1882f 100644 --- a/Resources/views/datasource.html.twig +++ b/Resources/views/datasource.html.twig @@ -1,13 +1,13 @@ {% block datasource_filter %} -{% filter spaceless %} +{% apply spaceless %} {% for field in datasource.fields %} {{ datasource_field_widget(field, vars) }} {% endfor %} -{% endfilter %} +{% endapply %} {% endblock %} {% block datasource_field %} -{% filter spaceless %} +{% apply spaceless %} {% if field.hasAttribute('form') is not empty %}
{% for child in field.getAttribute('form').children %} @@ -19,11 +19,11 @@ {% endfor %}
{% endif %} -{% endfilter %} +{% endapply %} {% endblock %} {% block datasource_sort %} -{% filter spaceless %} +{% apply spaceless %} {% if (field.getAttribute('sorted_ascending')) %} {{ ascending|raw }} {% else %} @@ -34,11 +34,11 @@ {% else %} {{ descending|raw }} {% endif %} -{% endfilter %} +{% endapply %} {% endblock %} {% block datasource_pagination %} -{% filter spaceless %} +{% apply spaceless %} -{% endfilter %} +{% endapply %} {% endblock %} {% block datasource_max_results_widget %} diff --git a/Tests/DataSource/Extension/Configuration/EventSubscriber/ConfigurationBuilderTest.php b/Tests/DataSource/Extension/Configuration/EventSubscriber/ConfigurationBuilderTest.php index ec88922..869febc 100644 --- a/Tests/DataSource/Extension/Configuration/EventSubscriber/ConfigurationBuilderTest.php +++ b/Tests/DataSource/Extension/Configuration/EventSubscriber/ConfigurationBuilderTest.php @@ -177,15 +177,10 @@ public function testExceptionThrownWhenMainConfigPathIsNotADirectory() protected function setUp() { $kernelMockBuilder = $this->getMockBuilder(Kernel::class)->setConstructorArgs(['dev', true]); - if (version_compare(Kernel::VERSION, '2.7.0', '<')) { - $kernelMockBuilder->setMethods( - ['registerContainerConfiguration', 'registerBundles', 'getBundles', 'getContainer', 'init'] - ); - } else { - $kernelMockBuilder->setMethods( - ['registerContainerConfiguration', 'registerBundles', 'getBundles', 'getContainer'] - ); - } + $kernelMockBuilder->setMethods( + ['registerContainerConfiguration', 'registerBundles', 'getBundles', 'getContainer'] + ); + $this->kernel = $kernelMockBuilder->getMock(); $this->subscriber = new ConfigurationBuilder($this->kernel); } diff --git a/Tests/Extension/Symfony/FormExtensionEntityTest.php b/Tests/Extension/Symfony/FormExtensionEntityTest.php index d9161bb..eddfb0c 100644 --- a/Tests/Extension/Symfony/FormExtensionEntityTest.php +++ b/Tests/Extension/Symfony/FormExtensionEntityTest.php @@ -24,12 +24,10 @@ use Symfony\Bridge\Doctrine\Form\DoctrineOrmExtension; use Symfony\Component\Form\Extension\Core\CoreExtension; use Symfony\Component\Form\Extension\Csrf\CsrfExtension; -use Symfony\Component\Form\Extension\Csrf\CsrfProvider\DefaultCsrfProvider; use Symfony\Component\Form\FormFactory; use Symfony\Component\Form\FormFactoryInterface; use Symfony\Component\Form\FormRegistry; use Symfony\Component\Form\ResolvedFormTypeFactory; -use Symfony\Component\HttpKernel\Kernel; use Symfony\Component\Security\Csrf\CsrfTokenManager; use Symfony\Component\Translation\TranslatorInterface; @@ -96,17 +94,11 @@ public function testEntityField() private function getFormFactory(): FormFactoryInterface { - if (version_compare(Kernel::VERSION, '3.0.0', '>=')) { - $tokenManager = new CsrfTokenManager(); - } else { - $tokenManager = new DefaultCsrfProvider('tests'); - } - $typeFactory = new ResolvedFormTypeFactory(); $registry = new FormRegistry( [ new CoreExtension(), - new CsrfExtension($tokenManager), + new CsrfExtension(new CsrfTokenManager()), new DoctrineOrmExtension(new TestManagerRegistry($this->getEntityManager())), ], $typeFactory diff --git a/Tests/Extension/Symfony/FormExtensionTest.php b/Tests/Extension/Symfony/FormExtensionTest.php index 5601d2c..6ce104c 100644 --- a/Tests/Extension/Symfony/FormExtensionTest.php +++ b/Tests/Extension/Symfony/FormExtensionTest.php @@ -9,7 +9,7 @@ namespace FSi\Bundle\DataSourceBundle\Tests\Extension\Symfony; -use DateTime; +use DateTimeImmutable; use FSi\Bundle\DataSourceBundle\DataSource\Extension\Symfony\Form\Driver\DriverExtension; use FSi\Bundle\DataSourceBundle\DataSource\Extension\Symfony\Form\EventSubscriber\Events; use FSi\Bundle\DataSourceBundle\DataSource\Extension\Symfony\Form\Extension\DatasourceExtension; @@ -32,9 +32,7 @@ use RuntimeException; use Symfony\Component\Form; use Symfony\Component\Form\Extension\Core\Type\HiddenType; -use Symfony\Component\Form\Extension\Csrf\CsrfProvider\DefaultCsrfProvider; use Symfony\Component\Form\FormFactoryInterface; -use Symfony\Component\Form\FormTypeInterface; use Symfony\Component\Form\FormView; use Symfony\Component\Security\Csrf\CsrfTokenManager; use Symfony\Component\Translation\TranslatorInterface; @@ -237,7 +235,7 @@ public function testFields(string $type) $parameters2 = [ 'datasource' => [ DataSourceInterface::PARAMETER_FIELDS => [ - 'name' => new DateTime('2012-12-12 12:12:00') + 'name' => new DateTimeImmutable('2012-12-12 12:12:00') ] ] ]; @@ -252,7 +250,7 @@ public function testFields(string $type) $parameters2 = [ 'datasource' => [ DataSourceInterface::PARAMETER_FIELDS => [ - 'name' => new DateTime(date('Y-m-d', 0).' 12:12:00') + 'name' => new DateTimeImmutable(date('Y-m-d', 0).' 12:12:00') ] ] ]; @@ -264,7 +262,7 @@ public function testFields(string $type) ] ] ]; - $parameters2 = ['datasource' => [DataSourceInterface::PARAMETER_FIELDS => ['name' => new DateTime('2012-12-12')]]]; + $parameters2 = ['datasource' => [DataSourceInterface::PARAMETER_FIELDS => ['name' => new DateTimeImmutable('2012-12-12')]]]; } elseif ($type === 'number') { $parameters = ['datasource' => [DataSourceInterface::PARAMETER_FIELDS => ['name' => 123]]]; $parameters2 = $parameters; @@ -385,11 +383,7 @@ public function testBuildBooleanFormWhenOptionsProvided() case 'form_filter': return true; case 'form_options': - return [ - 'choices' => $this->isSymfonyForm27() - ? ['tak' => '1', 'nie' => '0'] - : ['1' => 'tak', '0' => 'nie'] - ]; + return ['choices' => ['tak' => '1', 'nie' => '0']]; } })); @@ -470,7 +464,7 @@ public function testCreateDataSourceFieldWithCustomFormType(string $dataSourceFi $options = [ 'form_filter' => true, 'form_options' => [], - 'form_type' => $this->isSymfonyForm27() ? HiddenType::class : 'hidden' + 'form_type' => HiddenType::class ]; $field->expects($this->atLeastOnce()) @@ -521,17 +515,11 @@ private function getFormFactory(): FormFactoryInterface $typeFactory = new Form\ResolvedFormTypeFactory(); $typeFactory->createResolvedType(new BetweenType(), []); - if ($this->isSymfonyForm27()) { - $tokenManager = new CsrfTokenManager(); - } else { - $tokenManager = new DefaultCsrfProvider('tests'); - } - $registry = new Form\FormRegistry( [ new TestForm\Extension\TestCore\TestCoreExtension(), new Form\Extension\Core\CoreExtension(), - new Form\Extension\Csrf\CsrfExtension($tokenManager), + new Form\Extension\Csrf\CsrfExtension(new CsrfTokenManager()), new DatasourceExtension() ], $typeFactory @@ -566,9 +554,4 @@ private function getTranslator(): MockObject return $translator; } - - private function isSymfonyForm27(): bool - { - return method_exists(FormTypeInterface::class, 'configureOptions'); - } } diff --git a/Tests/Fixtures/Form/Extension/TestCore/Type/FormType.php b/Tests/Fixtures/Form/Extension/TestCore/Type/FormType.php index 5580e4d..cf4798d 100644 --- a/Tests/Fixtures/Form/Extension/TestCore/Type/FormType.php +++ b/Tests/Fixtures/Form/Extension/TestCore/Type/FormType.php @@ -15,9 +15,6 @@ class FormType extends BaseFormType { - /** - * {@inheritdoc} - */ public function buildView(FormView $view, FormInterface $form, array $options) { parent::buildView($view, $form, $options); diff --git a/Tests/Twig/Extension/DataSourceExtensionTest.php b/Tests/Twig/Extension/DataSourceExtensionTest.php index 5ece979..86d16f8 100644 --- a/Tests/Twig/Extension/DataSourceExtensionTest.php +++ b/Tests/Twig/Extension/DataSourceExtensionTest.php @@ -16,11 +16,8 @@ use PHPUnit\Framework\TestCase; use Symfony\Bridge\Twig\Extension\FormExtension; use Symfony\Bridge\Twig\Extension\TranslationExtension; -use Symfony\Bridge\Twig\Form\TwigRenderer; -use Symfony\Bridge\Twig\Form\TwigRendererEngine; use Symfony\Bridge\Twig\Tests\Extension\Fixtures\StubTranslator; use Symfony\Component\DependencyInjection\ContainerInterface; -use Symfony\Component\HttpKernel\Kernel; use Symfony\Component\Routing\RouterInterface; use Twig\Environment; use Twig\Error\LoaderError; @@ -148,18 +145,17 @@ public function testDataSourceRenderBlockFromParent() protected function setUp() { - $subPath = version_compare(Kernel::VERSION, '2.7.0', '<') ? 'Symfony/Bridge/Twig/' : ''; $loader = new FilesystemLoader([ - __DIR__ . '/../../../vendor/symfony/twig-bridge/' . $subPath . 'Resources/views/Form', + __DIR__ . '/../../../vendor/symfony/twig-bridge/Resources/views/Form', __DIR__ . '/../../../Resources/views', // datasource base theme ]); $twig = new Environment($loader); $twig->addExtension(new TranslationExtension(new StubTranslator())); - $twig->addExtension($this->getFormExtension($subPath !== '')); + $twig->addExtension(new FormExtension()); $twig->addGlobal('global_var', 'global_value'); - $this->twig = $twig; + $this->twig = $twig; $this->extension = new DataSourceExtension($this->getContainer(), 'datasource.html.twig'); } @@ -191,17 +187,4 @@ private function getTemplateMock(): MockObject { return $this->createMock(Template::class); } - - private function getFormExtension(bool $legacy): FormExtension - { - if (true === $legacy) { - $rendererEngine = new TwigRendererEngine(['form_div_layout.html.twig',]); - $renderer = new TwigRenderer($rendererEngine); - $formExtension = new FormExtension($renderer); - } else { - $formExtension = new FormExtension(); - } - - return $formExtension; - } } diff --git a/Twig/Extension/DataSourceExtension.php b/Twig/Extension/DataSourceExtension.php index 727456f..33752d8 100644 --- a/Twig/Extension/DataSourceExtension.php +++ b/Twig/Extension/DataSourceExtension.php @@ -53,7 +53,7 @@ class DataSourceExtension extends AbstractExtension implements InitRuntimeInterf private $additionalParameters; /** - * @var \TemplateInterface + * @var Template */ private $baseTemplate; @@ -157,7 +157,7 @@ public function datasourceFilterCount(DataSourceViewInterface $view) { $fields = $view->getFields(); $count = 0; - /** @var $field \FSi\Component\DataSource\Field\FieldViewInterface */ + /** @var $field FieldViewInterface */ foreach ($fields as $field) { if ($field->hasAttribute('form')) { $count++; diff --git a/composer.json b/composer.json index 2ed3d9e..a61a03c 100644 --- a/composer.json +++ b/composer.json @@ -13,22 +13,22 @@ "require": { "doctrine/orm": "^2.3", "doctrine/collections": "^1.0", - "fsi/datasource": "^1.3|^2.0", + "fsi/datasource": "^2.0", "php": ">=7.1", - "symfony/framework-bundle" : "^2.2|^3.0|^4.0", - "symfony/options-resolver": "^2.6|^3.0|^4.0", - "symfony/dependency-injection" : "^2.2|^3.0|^4.0", - "symfony/doctrine-bridge": "^2.2|^3.0|^4.0", - "symfony/security-csrf": "^2.4|^3.0|^4.0", - "symfony/yaml": "^2.2|^3.0|^4.0", - "symfony/translation": "^2.2|^3.0|^4.0", - "twig/twig": "^1.42|^2.0" + "symfony/framework-bundle" : "^3.4|^4.0", + "symfony/options-resolver": "^3.4|^4.0", + "symfony/dependency-injection" : "^3.4|^4.0", + "symfony/doctrine-bridge": "^3.4|^4.0", + "symfony/security-csrf": "^3.4|^4.0", + "symfony/yaml": "^3.4|^4.0", + "symfony/translation": "^3.4|^4.0", + "twig/twig": "^2.11" }, "require-dev": { - "symfony/form" : "^2.2|^3.0|^4.0", + "symfony/form" : "^3.4|^4.0", "symfony/phpunit-bridge": "^4.0", - "symfony/twig-bridge" : "^2.2|^3.0|^4.0", - "phpunit/phpunit": "^7.1" + "symfony/twig-bridge" : "^3.4|^4.0", + "phpunit/phpunit": "^7.5" }, "autoload": { "psr-4": { "FSi\\Bundle\\DataSourceBundle\\": "" } @@ -41,7 +41,11 @@ }, "extra": { "branch-alias": { - "dev-master": "2.0-dev" + "dev-master": "2.1-dev", + "2.0": "2.0-dev", + "1.2": "1.2-dev", + "1.1": "1.1-dev", + "1.0": "1.0-dev" } } }