Commit 19c959da authored by jaapjansma's avatar jaapjansma
Browse files

Compatibility fix for Symfony 2.8, 3.4 and 4.0

parent d70c518c
Version 1.25 (not yet released)
============
* Compatibility fix for Symfony 2.8, 3.4 and 4.0
Version 1.24
============
......
<?php
/**
* Copyright (C) 2021 Jaap Jansma (jaap.jansma@civicoop.org)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
namespace Civi\FormProcessor\Symfony\Component\DependencyInjection;
use Symfony\Component\DependencyInjection\Definition;
class DefinitionAdapter extends Definition {
/**
* Returns a definition class.
* We have to set is private to false on the definition class
* with newer versions of civicrm (especially with civicrm and drupal 9)
* with older versions of civicrm the setPrivate method is not available so we cannot set it.
*
* @param null $class
* @param array $arguments
* @return \Symfony\Component\DependencyInjection\Definition
*/
public static function createDefinitionClass($class = null, array $arguments = array()) {
$definition = new Definition($class, $arguments);
$definition->setPublic(true);
if (method_exists(Definition::class, 'setPrivate')) {
$definition->setPrivate(FALSE);
}
return $definition;
}
}
......@@ -4,7 +4,7 @@ require_once 'form_processor.civix.php';
use CRM_FormProcessor_ExtensionUtil as E;
use \Symfony\Component\DependencyInjection\ContainerBuilder;
use \Symfony\Component\DependencyInjection\Definition;
use \Civi\FormProcessor\Symfony\Component\DependencyInjection\DefinitionAdapter;
/**
* Implements hook_civicrm_container()
......@@ -13,21 +13,17 @@ use \Symfony\Component\DependencyInjection\Definition;
*/
function form_processor_civicrm_container(ContainerBuilder $container) {
// Register the TypeFactory
$typeFactoryDefinition = new Definition('Civi\FormProcessor\Type\Factory');
$typeFactoryDefinition->setPrivate(FALSE);
$typeFactoryDefinition = DefinitionAdapter::createDefinitionClass('Civi\FormProcessor\Type\Factory');
$container->setDefinition('form_processor_type_factory', $typeFactoryDefinition);
// Register the OutputHandlerFactory
$outputHandlerDefinition = new Definition('Civi\FormProcessor\OutputHandler\Factory');
$outputHandlerDefinition->setPrivate(FALSE);
$outputHandlerDefinition = DefinitionAdapter::createDefinitionClass('Civi\FormProcessor\OutputHandler\Factory');
$container->setDefinition('form_processor_output_handler_factory', $outputHandlerDefinition);
// Register the DelayedAction Factoory
$delayedActionFactoryDefinition = new Definition('Civi\FormProcessor\OutputHandler\Factory');
$delayedActionFactoryDefinition->setPrivate(FALSE);
$delayedActionFactoryDefinition = DefinitionAdapter::createDefinitionClass('Civi\FormProcessor\OutputHandler\Factory');
$container->setDefinition('form_processor_delayed_action_factory', $delayedActionFactoryDefinition);
// Register the validationFactory
$validationFactoryDefinition = new Definition('Civi\FormProcessor\Validation\Factory');
$validationFactoryDefinition = DefinitionAdapter::createDefinitionClass('Civi\FormProcessor\Validation\Factory');
$validationFactoryDefinition->setFactory(['Civi\FormProcessor\Validation\Factory', 'singleton']);
$validationFactoryDefinition->setPrivate(FALSE);
$container->setDefinition('form_processor_validation_factory', $validationFactoryDefinition);
......@@ -35,9 +31,9 @@ function form_processor_civicrm_container(ContainerBuilder $container) {
// The API provider is used to process incoming api calls and process them
// with the form processor logic.
$apiKernelDefinition = $container->getDefinition('civi_api_kernel');
$apiProviderDefinition = new Definition('Civi\FormProcessor\API\FormProcessor');
$apiProviderDefinition = DefinitionAdapter::createDefinitionClass('Civi\FormProcessor\API\FormProcessor');
$apiKernelDefinition->addMethodCall('registerApiProvider', array($apiProviderDefinition));
$apiProviderDefaultsDefinition = new Definition('Civi\FormProcessor\API\FormProcessorDefaults');
$apiProviderDefaultsDefinition = DefinitionAdapter::createDefinitionClass('Civi\FormProcessor\API\FormProcessorDefaults');
$apiKernelDefinition->addMethodCall('registerApiProvider', array($apiProviderDefaultsDefinition));
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment