Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix deprecations and support sf7 #15

Merged
merged 3 commits into from
Mar 21, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -18,7 +18,7 @@ jobs:
matrix:
php-version:
- "8.0"
- "8.1"
- "8.2"
dependencies:
- "highest"
stability:
@@ -31,7 +31,7 @@ jobs:
# Tests the highest set of dependencies
- dependencies: "highest"
stability: "dev"
php-version: "8.1"
php-version: "8.2"

steps:
- name: "Checkout"
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
/composer.lock
/vendor/
/.idea
/.devenv
.phpunit.cache
.php-cs-fixer.cache
.phpunit.result.cache
coverage.xml
coverage.xml
.result
flake.lock
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -67,7 +67,7 @@ class PostController
### Validations
- Response header
```
Content-Type: application/problem+json; charset=utf-8
Content-Type: application/json; charset=utf-8
```
- Response body
```json
19 changes: 9 additions & 10 deletions composer.json
Original file line number Diff line number Diff line change
@@ -19,18 +19,17 @@
"license": "MIT",
"require": {
"php": "^8.0",
"symfony/http-kernel": "^5.4 || ^6.0",
"symfony/http-foundation": "^5.4 || ^6.0",
"symfony/serializer": "^5.4 || ^6.0",
"symfony/validator": "^5.4 || ^6.0",
"symfony/dependency-injection": "^5.4 || ^6.0",
"symfony/property-access": "^5.4 || ^6.0"
"symfony/http-kernel": "^6.2|^7.0",
"symfony/http-foundation": "^6.2|^7.0",
"symfony/serializer": "^6.2|^7.0",
"symfony/validator": "^6.2|^7.0",
"symfony/dependency-injection": "^6.2|^7.0",
"symfony/property-access": "^6.2|^7.0"
},
"require-dev": {
"phpunit/phpunit": "^9.5",
"symfony/framework-bundle": "^5.4 || ^6.0",
"phpspec/prophecy-phpunit": "^2.0",
"friendsofphp/php-cs-fixer": "^3.13",
"phpunit/phpunit": "^10.0",
"symfony/framework-bundle": "^6.2|^7.0",
"friendsofphp/php-cs-fixer": "^3.5",
"phpstan/phpstan": "^1.9"
},
"autoload": {
34 changes: 34 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
phps.url = "github:fossar/nix-phps";
devenv.url = "github:cachix/devenv";
systems.url = "github:nix-systems/default";
};

outputs = inputs @ { self, flake-parts, ... }: flake-parts.lib.mkFlake { inherit inputs; } {
systems = import inputs.systems;

imports = [
inputs.devenv.flakeModule
];

perSystem = { config, self', inputs', pkgs, system, lib, ... }: {
_module.args.pkgs = import self.inputs.nixpkgs {
inherit system;
overlays = [
inputs.phps.overlays.default
];
};

devenv.shells.default = {
name = "php-dev-env";

packages = [
pkgs.php82
pkgs.php82.packages.composer
];
};
};
};
}
16 changes: 8 additions & 8 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit colors="true" bootstrap="vendor/autoload.php">
<coverage>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" colors="true" bootstrap="vendor/autoload.php" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd">
<testsuites>
<testsuite name="RequestInputBundle for the Symfony Framework">
<directory>./tests</directory>
</testsuite>
</testsuites>
<source>
<include>
<directory>.</directory>
</include>
<exclude>
<directory>./tests</directory>
<directory>./vendor</directory>
</exclude>
</coverage>
<testsuites>
<testsuite name="RequestInputBundle for the Symfony Framework">
<directory>./tests</directory>
</testsuite>
</testsuites>
</source>
</phpunit>
28 changes: 0 additions & 28 deletions src/ArgumentResolver/InputArgumentResolver.php

This file was deleted.

4 changes: 2 additions & 2 deletions src/DependencyInjection/RequestInputExtension.php
Original file line number Diff line number Diff line change
@@ -4,13 +4,13 @@

namespace Sfmok\RequestInput\DependencyInjection;

use Sfmok\RequestInput\ArgumentResolver\InputArgumentResolver;
use Sfmok\RequestInput\Factory\InputFactory;
use Sfmok\RequestInput\Factory\InputFactoryInterface;
use Sfmok\RequestInput\Metadata\InputMetadataFactory;
use Sfmok\RequestInput\Metadata\InputMetadataFactoryInterface;
use Sfmok\RequestInput\EventListener\ReadInputListener;
use Sfmok\RequestInput\EventListener\ExceptionListener;
use Sfmok\RequestInput\ValueResolver\InputValueResolver;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Reference;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
@@ -46,7 +46,7 @@ public function load(array $configs, ContainerBuilder $container): void
$container->setAlias(InputFactoryInterface::class, InputFactory::class)->setPublic(false);
$container->setAlias(InputMetadataFactoryInterface::class, InputMetadataFactory::class)->setPublic(false);

$container->register(InputArgumentResolver::class)
$container->register(InputValueResolver::class)
->setArguments([
'$inputFactory' => new Reference(InputFactoryInterface::class),
])
2 changes: 1 addition & 1 deletion src/EventListener/ExceptionListener.php
Original file line number Diff line number Diff line change
@@ -25,7 +25,7 @@ public function onKernelException(ExceptionEvent $event): void
return;
}

$headers = ['Content-Type' => 'application/problem+json; charset=utf-8'];
$headers = ['Content-Type' => 'application/json; charset=utf-8'];

if ($exception instanceof ValidationException) {
$event->setResponse(new Response(
14 changes: 6 additions & 8 deletions src/Factory/InputFactory.php
Original file line number Diff line number Diff line change
@@ -27,13 +27,11 @@ public function __construct(
) {
}

public function createFromRequest(Request $request, string $type): InputInterface
public function createFromRequest(Request $request, string $type): iterable
{
// @codeCoverageIgnoreStart
if (\func_num_args() > 2) {
@trigger_error("Third argument of 'InputFactory::createFromRequest' is not in use and is removed, however the argument in the callers code can be removed without side-effects.", \E_USER_DEPRECATED);
if (!is_subclass_of($type, InputInterface::class)) {
return [];
}
// @codeCoverageIgnoreEnd

$contentType = $request->headers->get('CONTENT_TYPE');
if (null === $contentType || '' === $contentType) {
@@ -49,7 +47,7 @@ public function createFromRequest(Request $request, string $type): InputInterfac
}

$data = $request->getContent();
$format = $request->getContentType();
$format = $request->getContentTypeFormat();
if (Input::INPUT_FORM_FORMAT === $format) {
$data = json_encode($request->request->all());
$format = Input::INPUT_JSON_FORMAT;
@@ -70,14 +68,14 @@ public function createFromRequest(Request $request, string $type): InputInterfac
}
}

return $input;
return [$input];
}

private function getSupportedMimeTypes(Request $request, array $formats): array
{
$mimeTypes = [];
foreach ($formats as $format) {
$mimeTypes = [...$mimeTypes, ...$request->getMimeTypes($format)];
$mimeTypes = array_merge($mimeTypes, $request->getMimeTypes($format));
}

return $mimeTypes;
2 changes: 1 addition & 1 deletion src/Factory/InputFactoryInterface.php
Original file line number Diff line number Diff line change
@@ -9,5 +9,5 @@

interface InputFactoryInterface
{
public function createFromRequest(Request $request, string $type): InputInterface;
public function createFromRequest(Request $request, string $type): iterable;
}
22 changes: 22 additions & 0 deletions src/ValueResolver/InputValueResolver.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

declare(strict_types=1);

namespace Sfmok\RequestInput\ValueResolver;

use Symfony\Component\HttpFoundation\Request;
use Sfmok\RequestInput\Factory\InputFactoryInterface;
use Symfony\Component\HttpKernel\Controller\ValueResolverInterface;
use Symfony\Component\HttpKernel\ControllerMetadata\ArgumentMetadata;

class InputValueResolver implements ValueResolverInterface
{
public function __construct(private InputFactoryInterface $inputFactory)
{
}

public function resolve(Request $request, ArgumentMetadata $argument): iterable
{
return $this->inputFactory->createFromRequest($request, $argument->getType());
}
}
64 changes: 0 additions & 64 deletions tests/ArgumentResolver/InputArgumentResolverTest.php

This file was deleted.

Loading