Skip to content

Commit

Permalink
sf5 compatibility
Browse files Browse the repository at this point in the history
feat: drop support for php < 7.2, add support for symfony 6, drop support for symfony < 4.4, bump dependencies, fix restrict public services in phpunit, add php 8.0, 8.1, 8.2 to the travis ci tests
php ^8.0, sf5 & sf6, fix replaced IvoryJsonBuilder, Fixed removed XML support
fix services and config tree

strict dependencies for sf5
  • Loading branch information
Chris8934 authored and Samuel Breu committed Feb 19, 2024
1 parent 450abf7 commit 5277256
Show file tree
Hide file tree
Showing 43 changed files with 210 additions and 357 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@
# PHPUnit
/build
/phpunit.xml
/.phpunit.result.cache
4 changes: 3 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ dist: xenial

php:
- '7.4'
# - '8.0'
- '8.0'
- '8.1'
- '8.2'

branches:
only:
Expand Down
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ order to set up the project.

When you're on the new branch with the dependencies, code as much as you want and when the fix is ready, don't commit
it immediately. Before, you will need to add tests and update the doc. For the tests, everything is tested with
[PHPUnit](http://phpunit.de/) and the doc is in the markdown format under the `Resources/doc` directory.
[PHPUnit](https://phpunit.de/) and the doc is in the markdown format under the `Resources/doc` directory.

Then, when you have fixed the bug, tested it and documented it, you can commit and push it with the following commands:

Expand Down
2 changes: 1 addition & 1 deletion DependencyInjection/Compiler/CleanTemplatingPass.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class CleanTemplatingPass implements CompilerPassInterface
/**
* {@inheritdoc}
*/
public function process(ContainerBuilder $container)
public function process(ContainerBuilder $container): void
{
if (!$container->hasDefinition('templating.engine.php')) {
$container->removeDefinition('ivory.google_map.templating.api');
Expand Down
12 changes: 7 additions & 5 deletions DependencyInjection/Compiler/PublicForTestsCompilerPass.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,20 @@

class PublicForTestsCompilerPass implements CompilerPassInterface
{
public function process(ContainerBuilder $container)
public function process(ContainerBuilder $container): void
{
if (!$this->isPHPUnit()) {
return;
}

foreach ($container->getDefinitions() as $definition) {
$definition->setPublic(true);
}

foreach ($container->getAliases() as $definition) {
$definition->setPublic(true);
if(str_contains($definition->getClass(), 'Ivory\GoogleMapBundle') ||
str_contains($definition->getClass(), 'Ivory\GoogleMap') ||
str_contains($definition->getClass(), 'Ivory\Serializer'))
{
$definition->setPublic(true);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class RegisterControlRendererPass implements CompilerPassInterface
/**
* {@inheritdoc}
*/
public function process(ContainerBuilder $container)
public function process(ContainerBuilder $container): void
{
$controlManagerRenderer = $container->getDefinition('ivory.google_map.helper.renderer.control.manager');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class RegisterExtendableRendererPass implements CompilerPassInterface
/**
* {@inheritdoc}
*/
public function process(ContainerBuilder $container)
public function process(ContainerBuilder $container): void
{
$tag = 'ivory.google_map.helper.renderer.extendable';
$extendableRenderer = $container->getDefinition('ivory.google_map.helper.renderer.overlay.extendable');
Expand Down
2 changes: 1 addition & 1 deletion DependencyInjection/Compiler/RegisterFormResourcePass.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class RegisterFormResourcePass implements CompilerPassInterface
/**
* {@inheritdoc}
*/
public function process(ContainerBuilder $container)
public function process(ContainerBuilder $container): void
{
if ($container->hasParameter($parameter = 'templating.helper.form.resources')) {
$container->setParameter(
Expand Down
17 changes: 1 addition & 16 deletions DependencyInjection/Compiler/RegisterHelperListenerPass.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,8 @@

namespace Ivory\GoogleMapBundle\DependencyInjection\Compiler;

use Symfony\Component\DependencyInjection\Argument\ServiceClosureArgument;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Reference;
use Symfony\Component\EventDispatcher\ContainerAwareEventDispatcher;
use Symfony\Component\EventDispatcher\DependencyInjection\RegisterListenersPass;

/**
Expand All @@ -38,9 +35,6 @@ class RegisterHelperListenerPass implements CompilerPassInterface
*/
private $passes = [];

/**
* {@inheritdoc}
*/
public function __construct()
{
foreach (self::$helpers as $helper) {
Expand All @@ -55,17 +49,8 @@ public function __construct()
/**
* {@inheritdoc}
*/
public function process(ContainerBuilder $container)
public function process(ContainerBuilder $container): void
{
if (!class_exists(ServiceClosureArgument::class)) {
foreach (self::$helpers as $helper) {
$container
->getDefinition('ivory.google_map.helper.'.$helper.'.event_dispatcher')
->setClass(ContainerAwareEventDispatcher::class)
->addArgument(new Reference('service_container'));
}
}

foreach ($this->passes as $pass) {
$pass->process($container);
}
Expand Down
32 changes: 5 additions & 27 deletions DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class Configuration implements ConfigurationInterface
/**
* {@inheritdoc}
*/
public function getConfigTreeBuilder()
public function getConfigTreeBuilder(): TreeBuilder
{
$treeBuilder = $this->createTreeBuilder('ivory_google_map');
$children = $treeBuilder->getRootNode()
Expand All @@ -51,10 +51,7 @@ public function getConfigTreeBuilder()
return $treeBuilder;
}

/**
* @return ArrayNodeDefinition
*/
private function createMapNode()
private function createMapNode(): ArrayNodeDefinition
{
return $this->createNode('map')
->addDefaultsIfNotSet()
Expand All @@ -78,13 +75,7 @@ private function createStaticMapNode()
->end();
}

/**
* @param string $service
* @param bool $http
*
* @return ArrayNodeDefinition
*/
private function createServiceNode($service, $http)
private function createServiceNode(string $service, bool $http): ArrayNodeDefinition
{
$node = $this->createNode($service);
$children = $node
Expand Down Expand Up @@ -116,12 +107,7 @@ private function createServiceNode($service, $http)
return $node;
}

/**
* @param bool $service
*
* @return ArrayNodeDefinition
*/
private function createBusinessAccountNode($service)
private function createBusinessAccountNode(bool $service): ArrayNodeDefinition
{
$node = $this->createNode('business_account');
$clientIdNode = $node->children()
Expand All @@ -142,22 +128,14 @@ private function createBusinessAccountNode($service)
}

/**
* @param string $name
* @param string $type
*
* @return ArrayNodeDefinition|NodeDefinition
*/
private function createNode(string $name = null, string $type = 'array')
{
return $this->createTreeBuilder($name, $type)->getRootNode();
}

/**
* @param string $name
* @param string $type
* @return TreeBuilder
*/
private function createTreeBuilder(string $name = null, string $type = 'array')
private function createTreeBuilder(string $name = null, string $type = 'array'): TreeBuilder
{
return new TreeBuilder($name, $type);
}
Expand Down
74 changes: 29 additions & 45 deletions DependencyInjection/IvoryGoogleMapExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ class IvoryGoogleMapExtension extends ConfigurableExtension
/**
* {@inheritdoc}
*/
protected function loadInternal(array $config, ContainerBuilder $container)
protected function loadInternal(array $mergedConfig, ContainerBuilder $container): void
{
$loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
$loader = new XmlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config'));

$resources = [
'form',
Expand All @@ -45,18 +45,18 @@ protected function loadInternal(array $config, ContainerBuilder $container)
];

foreach ($resources as $resource) {
$loader->load($resource.'.xml');
$loader->load($resource . '.xml');
}

$this->loadMapConfig($config['map'], $container);
$this->loadStaticMapConfig($config['static_map'], $container);
$this->loadServicesConfig($config, $container, $loader);
$this->loadMapConfig($mergedConfig['map'], $container);
$this->loadStaticMapConfig($mergedConfig['static_map'], $container);
$this->loadServicesConfig($mergedConfig, $container, $loader);
}

/**
* @param mixed[] $config
*/
private function loadMapConfig(array $config, ContainerBuilder $container)
private function loadMapConfig(array $config, ContainerBuilder $container): void
{
$container
->getDefinition('ivory.google_map.helper.renderer.loader')
Expand All @@ -78,7 +78,7 @@ private function loadMapConfig(array $config, ContainerBuilder $container)
/**
* @param mixed[] $config
*/
private function loadStaticMapConfig(array $config, ContainerBuilder $container)
private function loadStaticMapConfig(array $config, ContainerBuilder $container): void
{
if (isset($config['api_key'])) {
$container
Expand All @@ -100,67 +100,51 @@ private function loadStaticMapConfig(array $config, ContainerBuilder $container)
/**
* @param mixed[] $config
*/
private function loadServicesConfig(array $config, ContainerBuilder $container, LoaderInterface $loader)
private function loadServicesConfig(array $config, ContainerBuilder $container, LoaderInterface $loader): void
{
$services = [
'direction' => true,
'distance_matrix' => true,
'elevation' => true,
'geocoder' => true,
'direction' => true,
'distance_matrix' => true,
'elevation' => true,
'geocoder' => true,
'place_autocomplete' => true,
'place_detail' => true,
'place_photo' => false,
'place_search' => true,
'time_zone' => true,
'place_detail' => true,
'place_photo' => false,
'place_search' => true,
'time_zone' => true,
];

$serializerLoaded = false;
$loadSerializer = function() use ($container, $loader) {
$loader->load('service/serializer.xml');

if ($container->hasParameter('kernel.project_dir')) {
$container
->getDefinition('ivory.google_map.serializer.loader')
->replaceArgument(0, '%kernel.project_dir%/vendor/ivory/google-map/src/Service/Serializer');
}
};

foreach ($services as $service => $http) {
if (!isset($config[$service])) {
continue;
}

if ($http && !$serializerLoaded) {
$loadSerializer();
$serializerLoaded = true;
}

$this->loadServiceConfig($service, $config[$service], $container, $loader, $http);
}
}

/**
* @param string $service
* @param string $service
* @param mixed[] $config
* @param bool $http
* @param bool $http
*
* @throws Exception
*/
private function loadServiceConfig(
string $service,
array $config,
string $service,
array $config,
ContainerBuilder $container,
LoaderInterface $loader,
$http = true
) {
$loader->load('service/'.$service.'.xml');
$definition = $container->getDefinition($serviceName = 'ivory.google_map.'.$service);
LoaderInterface $loader,
$http = true
): void
{
$loader->load('service/' . $service . '.xml');
$definition = $container->getDefinition($serviceName = 'ivory.google_map.' . $service);

if ($http) {
$definition
->addArgument(new Reference($config['client']))
->addArgument(new Reference($config['message_factory']))
->addArgument(new Reference('ivory.serializer'));
->addArgument(new Reference($config['message_factory']));
}

if ($http && isset($config['format'])) {
Expand All @@ -175,7 +159,7 @@ private function loadServiceConfig(
$businessAccountConfig = $config['business_account'];

$container->setDefinition(
$businessAccountName = $serviceName.'.business_account',
$businessAccountName = $serviceName . '.business_account',
new Definition(BusinessAccount::class, [
$businessAccountConfig['client_id'],
$businessAccountConfig['secret'],
Expand Down
15 changes: 6 additions & 9 deletions Form/Type/PlaceAutocompleteType.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class PlaceAutocompleteType extends AbstractType
/**
* {@inheritdoc}
*/
public function buildForm(FormBuilderInterface $builder, array $options)
public function buildForm(FormBuilderInterface $builder, array $options): void
{
$autocomplete = new Autocomplete();

Expand Down Expand Up @@ -63,7 +63,7 @@ public function buildForm(FormBuilderInterface $builder, array $options)
/**
* {@inheritdoc}
*/
public function finishView(FormView $view, FormInterface $form, array $options)
public function finishView(FormView $view, FormInterface $form, array $options): void
{
$autocomplete = $form->getConfig()->getAttribute('autocomplete');
$autocomplete->setInputId($view->vars['id']);
Expand All @@ -77,7 +77,7 @@ public function finishView(FormView $view, FormInterface $form, array $options)
/**
* {@inheritdoc}
*/
public function configureOptions(OptionsResolver $resolver)
public function configureOptions(OptionsResolver $resolver): void
{
$resolver
->setDefaults([
Expand Down Expand Up @@ -107,23 +107,20 @@ public function configureOptions(OptionsResolver $resolver)
/**
* {@inheritdoc}
*/
public function getParent()
public function getParent(): string
{
return method_exists(AbstractType::class, 'getBlockPrefix') ? TextType::class : 'text';
}

/**
* {@inheritdoc}
*/
public function getBlockPrefix()
public function getBlockPrefix(): string
{
return 'place_autocomplete';
}

/**
* {@inheritdoc}
*/
public function getName()
public function getName(): string
{
return $this->getBlockPrefix();
}
Expand Down
Loading

0 comments on commit 5277256

Please sign in to comment.