Skip to content
This repository was archived by the owner on Nov 2, 2020. It is now read-only.

Commit a3ee0da

Browse files
author
Mathieu Lechat
committed
Symfony 4 compatibility
1 parent 5325f9b commit a3ee0da

File tree

4 files changed

+50
-23
lines changed

4 files changed

+50
-23
lines changed

.travis.yml

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,36 @@
11
language: php
22

33
php:
4-
- 7
4+
- 5.4
5+
- 5.5
6+
- 5.6
7+
- 7.0
8+
- 7.1
9+
- 7.2
10+
- hhvm
511

612
env:
7-
- SYMFONY_VERSION=2.*
8-
- SYMFONY_VERSION=3.*
13+
- SYMFONY_VERSION=2.* PHPUNIT_VERSION=4.*
14+
- SYMFONY_VERSION=3.* PHPUNIT_VERSION=5.*
15+
16+
matrix:
17+
exclude:
18+
- php: 5.4
19+
env: SYMFONY_VERSION=3.* PHPUNIT_VERSION=5.*
20+
21+
- php: 5.5
22+
env: SYMFONY_VERSION=3.* PHPUNIT_VERSION=5.*
923

1024
cache:
1125
directories:
1226
- $HOME/.composer/cache
1327

1428
install:
15-
- composer require --dev --no-update symfony/framework-bundle:${SYMFONY_VERSION}
29+
- composer require --dev --no-update symfony/framework-bundle:${SYMFONY_VERSION} phpunit/phpunit:${PHPUNIT_VERSION}
1630
- composer install
1731

1832
script:
1933
- vendor/bin/php-cs-fixer fix --dry-run --diff
20-
- phpunit --coverage-text
34+
- vendor/bin/phpunit --coverage-text
2135

2236
sudo: false

DependencyInjection/SendinBlueApiExtension.php

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
use Symfony\Component\Config\FileLocator;
66
use Symfony\Component\DependencyInjection\ContainerBuilder;
77
use Symfony\Component\DependencyInjection\Definition;
8-
use Symfony\Component\DependencyInjection\DefinitionDecorator;
98
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
109
use Symfony\Component\DependencyInjection\Reference;
1110
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
@@ -43,8 +42,10 @@ public function load(array $config, ContainerBuilder $container)
4342
$config['default_client'] = reset($keys);
4443
}
4544

45+
$onlyClient = 1 === count($config['clients']);
46+
4647
foreach ($config['clients'] as $name => $client) {
47-
$this->loadClient($name, $config['default_client'] === $name, $client, $container);
48+
$this->loadClient($name, $config['default_client'] === $name, $onlyClient, $client, $container);
4849
}
4950
}
5051

@@ -83,22 +84,25 @@ public static function getEndpoints()
8384
/**
8485
* @param string $name
8586
* @param bool $default
87+
* @param bool $only
8688
* @param array $client
8789
* @param ContainerBuilder $container
8890
*/
89-
private function loadClient($name, $default, array $client, ContainerBuilder $container)
91+
private function loadClient($name, $default, $only, array $client, ContainerBuilder $container)
9092
{
93+
$definitionClassName = $this->getDefinitionClassname();
94+
9195
$configurationService = sprintf('sendinblue_api.%s_client.configuration', $name);
9296
$configuration = $container->setDefinition(
9397
$configurationService,
94-
new DefinitionDecorator('sendinblue_api.client.configuration')
98+
new $definitionClassName('sendinblue_api.client.configuration')
9599
);
96100

97101
$configuration->addMethodCall('setApiKey', ['api-key', $client['key']]);
98102

99103
$clientService = sprintf('sendinblue_api.%s_client', $name);
100104
$container
101-
->setDefinition($clientService, new DefinitionDecorator('sendinblue_api.client'))
105+
->setDefinition($clientService, new $definitionClassName('sendinblue_api.client'))
102106
->setArguments([new Reference($configurationService)])
103107
;
104108

@@ -111,11 +115,23 @@ private function loadClient($name, $default, array $client, ContainerBuilder $co
111115
));
112116

113117
if ($default) {
114-
$container->setAlias(
115-
sprintf('sendinblue_api.%s_endpoint', $endpoint),
116-
$endpointService
117-
);
118+
$container->setAlias(sprintf('sendinblue_api.%s_endpoint', $endpoint), $endpointService);
119+
}
120+
121+
if ($only) {
122+
$container->setAlias(self::$MAPPING[$endpoint], $endpointService);
118123
}
119124
}
120125
}
126+
127+
/**
128+
* @return string
129+
*/
130+
private function getDefinitionClassname()
131+
{
132+
return class_exists('Symfony\Component\DependencyInjection\ChildDefinition')
133+
? 'Symfony\Component\DependencyInjection\ChildDefinition'
134+
: 'Symfony\Component\DependencyInjection\DefinitionDecorator'
135+
;
136+
}
121137
}

composer.json

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,14 @@
1111
}
1212
],
1313
"require": {
14+
"php": ">=5.4",
1415
"sendinblue/api-v3-sdk": "^2",
15-
"symfony/config": "^2|^3",
16-
"symfony/dependency-injection": "^2|^3",
17-
"symfony/http-kernel": "^2|^3"
16+
"symfony/config": "^2|^3|^4",
17+
"symfony/dependency-injection": "^2|^3|^4",
18+
"symfony/http-kernel": "^2|^3|^4"
1819
},
1920
"require-dev": {
20-
"friendsofphp/php-cs-fixer": "^2",
21-
"phpunit/phpunit": "^6",
22-
"symfony/framework-bundle": "^2|^3"
21+
"friendsofphp/php-cs-fixer": "^2"
2322
},
2423
"autoload": {
2524
"psr-4": { "SendinBlue\\Bundle\\ApiBundle\\" : "" },

phpunit.xml.dist

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22

33
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4-
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/6.3/phpunit.xsd"
4+
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/4.8/phpunit.xsd"
55
backupGlobals="false"
66
colors="true"
77
bootstrap="Tests/bootstrap.php"
8-
failOnRisky="true"
9-
failOnWarning="true"
108
>
119
<testsuites>
1210
<testsuite name="SendinBlue ApiBundle Test Suite">

0 commit comments

Comments
 (0)