Skip to content

Commit

Permalink
Merge pull request #21 from Setono/compat-layer
Browse files Browse the repository at this point in the history
Add compatibility layer with setono/client-bundle
  • Loading branch information
loevgaard authored Apr 9, 2024
2 parents cbd6d06 + 7b0fc9c commit e36eb98
Show file tree
Hide file tree
Showing 16 changed files with 152 additions and 102 deletions.
32 changes: 13 additions & 19 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ jobs:
strategy:
matrix:
php-version:
- "7.4"
- "8.1"

dependencies:
- "highest"

steps:
- name: "Checkout"
uses: "actions/checkout@v3"
uses: "actions/checkout@v4"

- name: "Setup PHP, with composer and extensions"
uses: "shivammathur/setup-php@v2"
Expand All @@ -32,7 +32,7 @@ jobs:
coverage: "none"

- name: "Install composer dependencies"
uses: "ramsey/composer-install@v2"
uses: "ramsey/composer-install@v3"
with:
dependency-versions: "${{ matrix.dependencies }}"

Expand All @@ -53,8 +53,6 @@ jobs:
strategy:
matrix:
php-version:
- "7.4"
- "8.0"
- "8.1"
- "8.2"

Expand All @@ -63,7 +61,7 @@ jobs:

steps:
- name: "Checkout"
uses: "actions/checkout@v3"
uses: "actions/checkout@v4"

- name: "Setup PHP, with composer and extensions"
uses: "shivammathur/setup-php@v2"
Expand All @@ -74,7 +72,7 @@ jobs:
tools: "composer-require-checker, composer-unused"

- name: "Install composer dependencies"
uses: "ramsey/composer-install@v2"
uses: "ramsey/composer-install@v3"
with:
dependency-versions: "${{ matrix.dependencies }}"

Expand All @@ -92,8 +90,6 @@ jobs:
strategy:
matrix:
php-version:
- "7.4"
- "8.0"
- "8.1"
- "8.2"

Expand All @@ -102,7 +98,7 @@ jobs:

steps:
- name: "Checkout"
uses: "actions/checkout@v3"
uses: "actions/checkout@v4"

- name: "Setup PHP, with composer and extensions"
uses: "shivammathur/setup-php@v2"
Expand All @@ -112,7 +108,7 @@ jobs:
coverage: "none"

- name: "Install composer dependencies"
uses: "ramsey/composer-install@v2"
uses: "ramsey/composer-install@v3"
with:
dependency-versions: "${{ matrix.dependencies }}"

Expand All @@ -127,8 +123,6 @@ jobs:
strategy:
matrix:
php-version:
- "7.4"
- "8.0"
- "8.1"
- "8.2"

Expand All @@ -137,7 +131,7 @@ jobs:

steps:
- name: "Checkout"
uses: "actions/checkout@v3"
uses: "actions/checkout@v4"

- name: "Setup PHP, with composer and extensions"
uses: "shivammathur/setup-php@v2"
Expand All @@ -147,7 +141,7 @@ jobs:
coverage: "none"

- name: "Install composer dependencies"
uses: "ramsey/composer-install@v2"
uses: "ramsey/composer-install@v3"
with:
dependency-versions: "${{ matrix.dependencies }}"

Expand All @@ -169,7 +163,7 @@ jobs:

steps:
- name: "Checkout"
uses: "actions/checkout@v3"
uses: "actions/checkout@v4"

- name: "Setup PHP, with composer and extensions"
uses: "shivammathur/setup-php@v2"
Expand All @@ -182,7 +176,7 @@ jobs:
run: "echo \"::add-matcher::${{ runner.tool_cache }}/phpunit.json\""

- name: "Install composer dependencies"
uses: "ramsey/composer-install@v2"
uses: "ramsey/composer-install@v3"
with:
dependency-versions: "${{ matrix.dependencies }}"

Expand All @@ -209,7 +203,7 @@ jobs:

steps:
- name: "Checkout"
uses: "actions/checkout@v3"
uses: "actions/checkout@v4"

- name: "Setup PHP, with composer and extensions"
uses: "shivammathur/setup-php@v2"
Expand All @@ -219,7 +213,7 @@ jobs:
php-version: "${{ matrix.php-version }}"

- name: "Install composer dependencies"
uses: "ramsey/composer-install@v2"
uses: "ramsey/composer-install@v3"
with:
dependency-versions: "${{ matrix.dependencies }}"

Expand Down
5 changes: 5 additions & 0 deletions composer-require-checker.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"symbol-whitelist": [
"Setono\\ClientBundle\\Context\\ClientContextInterface"
]
}
29 changes: 16 additions & 13 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,28 @@
}
],
"require": {
"php": ">=7.4",
"php": ">=8.1",
"composer/composer": "^2.0",
"doctrine/dbal": "^2.12 || ^3.0",
"setono/client-id": "^0.2",
"setono/client-id-contracts": "^0.2",
"symfony/config": "^5.4 || ^6.0",
"symfony/dependency-injection": "^5.4 || ^6.0",
"symfony/event-dispatcher": "^5.4 || ^6.0",
"symfony/http-foundation": "^5.4 || ^6.0",
"symfony/http-kernel": "^5.4 || ^6.0",
"symfony/config": "^5.4 || ^6.0 || ^7.0",
"symfony/dependency-injection": "^5.4 || ^6.0 || ^7.0",
"symfony/event-dispatcher": "^5.4 || ^6.0 || ^7.0",
"symfony/http-foundation": "^5.4 || ^6.0 || ^7.0",
"symfony/http-kernel": "^5.4 || ^6.0 || ^7.0",
"webmozart/assert": "^1.11"
},
"require-dev": {
"infection/infection": "^0.23.0",
"matthiasnoback/symfony-dependency-injection-test": "^4.2",
"nyholm/symfony-bundle-test": "^1.7",
"phpunit/phpunit": "^9.5",
"psalm/plugin-phpunit": "^0.16.0",
"psalm/plugin-symfony": "^2.1",
"setono/code-quality-pack": "^2.4"
"infection/infection": "^0.27.11",
"matthiasnoback/symfony-dependency-injection-test": "^4.3 || ^5.1",
"nyholm/symfony-bundle-test": "^3.0",
"phpspec/prophecy-phpunit": "^2.2",
"phpunit/phpunit": "^9.6",
"psalm/plugin-phpunit": "^0.19",
"psalm/plugin-symfony": "^5.1",
"setono/client-bundle": "dev-master",
"setono/code-quality-pack": "^2.7"
},
"prefer-stable": true,
"autoload": {
Expand Down
12 changes: 6 additions & 6 deletions ecs.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

declare(strict_types=1);

use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
use Symplify\EasyCodingStandard\ValueObject\Option;
use Symplify\EasyCodingStandard\Config\ECSConfig;

return static function (ContainerConfigurator $containerConfigurator): void {
$containerConfigurator->import('vendor/sylius-labs/coding-standard/ecs.php');
$containerConfigurator->parameters()->set(Option::PATHS, [
'src', 'tests'
return static function (ECSConfig $config): void {
$config->import('vendor/sylius-labs/coding-standard/ecs.php');
$config->paths([
'src',
'tests',
]);
};
8 changes: 4 additions & 4 deletions infection.json.dist
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
},
"logs": {
"text": "php://stderr",
"badge": {
"branch": "master"
"stryker": {
"badge": "master"
}
},
"minMsi": 100,
"minCoveredMsi": 100
"minMsi": 94.87,
"minCoveredMsi": 97.37
}
4 changes: 4 additions & 0 deletions psalm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="https://getpsalm.org/schema/config"
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
findUnusedPsalmSuppress="false"
findUnusedVariablesAndParams="false"
findUnusedCode="false"
findUnusedBaselineEntry="false"
errorLevel="1"
>
<projectFiles>
Expand Down
7 changes: 7 additions & 0 deletions src/DependencyInjection/SetonoClientIdExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Setono\ClientIdBundle\DependencyInjection;

use Composer\InstalledVersions;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Extension\Extension;
Expand All @@ -15,5 +16,11 @@ public function load(array $configs, ContainerBuilder $container): void
{
$loader = new XmlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config'));
$loader->load('services.xml');

if (InstalledVersions::isInstalled('setono/client-bundle', false)) {
$loader->load('services/conditional/provider.xml');
} else {
$loader->load('services/conditional/event_listener.xml');
}
}
}
2 changes: 1 addition & 1 deletion src/Doctrine/Type/ClientIdType.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
use Doctrine\DBAL\Types\Type;
use Setono\ClientId\ClientId;

// todo see this https://github.com/symfony/symfony/blob/5.x/src/Symfony/Bridge/Doctrine/Types/AbstractUidType.php as an example
final class ClientIdType extends Type
{
public const CLIENT_ID = 'client_id';
Expand All @@ -21,6 +20,7 @@ public function getName(): string

public function getSQLDeclaration(array $column, AbstractPlatform $platform): string
{
/** @psalm-suppress DeprecatedMethod */
return $platform->getVarcharTypeDeclarationSQL($column);
}

Expand Down
2 changes: 1 addition & 1 deletion src/EventListener/SaveClientIdSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public function save(ResponseEvent $event): void
$response->headers->setCookie(Cookie::create(
$this->cookieName,
$this->clientIdProvider->getClientId()->toString(),
new \DateTime('+360 days')
new \DateTime('+360 days'),
));
}
}
24 changes: 24 additions & 0 deletions src/Provider/CompatibilityProvider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

declare(strict_types=1);

namespace Setono\ClientIdBundle\Provider;

use Setono\ClientBundle\Context\ClientContextInterface;
use Setono\ClientId\ClientId;
use Setono\ClientId\Provider\ClientIdProviderInterface;

final class CompatibilityProvider implements ClientIdProviderInterface
{
private ClientContextInterface $clientContext;

public function __construct(ClientContextInterface $clientContext)
{
$this->clientContext = $clientContext;
}

public function getClientId(): ClientId
{
return new ClientId($this->clientContext->getClient()->id);
}
}
1 change: 0 additions & 1 deletion src/Resources/config/services.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
<imports>
<import resource="services/cookie.xml"/>
<import resource="services/event_listener.xml"/>
<import resource="services/generator.xml"/>
<import resource="services/provider.xml"/>
</imports>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<container xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://symfony.com/schema/dic/services"
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
<services>
<!-- This service is registered if the setono/client-bundle is NOT installed -->
<service id="setono_client_id.event_listener.save_client_id_subscriber"
class="Setono\ClientIdBundle\EventListener\SaveClientIdSubscriber">
<argument type="service" id="setono_client_id.provider.default_client_id"/>
Expand Down
13 changes: 13 additions & 0 deletions src/Resources/config/services/conditional/provider.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8" ?>

<container xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://symfony.com/schema/dic/services"
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
<services>
<!-- This service is registered if the setono/client-bundle is installed -->
<service id="setono_client_id.provider.compatibility"
class="Setono\ClientIdBundle\Provider\CompatibilityProvider"
decorates="setono_client_id.provider.generated_client_id" decoration-priority="32">
<argument type="service" id="setono_client.client_context.default"/>
</service>
</services>
</container>
4 changes: 2 additions & 2 deletions tests/Doctrine/Type/ClientIdTypeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public function it_converts_string_to_database_value(): void
public function it_throws_exception_when_trying_to_convert_unsupported_type_for_database_value(): void
{
$this->expectException(ConversionException::class);
$this->expectExceptionMessage("Could not convert PHP value of type 'stdClass' to type 'client_id'. Expected one of the following types: null, string, Setono\ClientId\ClientId");
$this->expectExceptionMessage('Could not convert PHP value of type stdClass to type client_id. Expected one of the following types: null, string, Setono\ClientId\ClientId');

$this->type->convertToDatabaseValue(new \stdClass(), $this->platform);
}
Expand Down Expand Up @@ -99,7 +99,7 @@ public function it_converts_string_to_php_value(): void
public function it_throws_exception_when_trying_to_convert_unsupported_type_for_php_value(): void
{
$this->expectException(ConversionException::class);
$this->expectExceptionMessage("Could not convert PHP value of type 'stdClass' to type 'client_id'. Expected one of the following types: null, string, Setono\ClientId\ClientId");
$this->expectExceptionMessage('Could not convert PHP value of type stdClass to type client_id. Expected one of the following types: null, string, Setono\ClientId\ClientId');

$this->type->convertToPHPValue(new \stdClass(), $this->platform);
}
Expand Down
Loading

0 comments on commit e36eb98

Please sign in to comment.