Skip to content
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion .github/workflows/continuous-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ jobs:
ci:
uses: ray-di/.github/.github/workflows/continuous-integration.yml@v1
with:
old_stable: '["7.3", "7.4", "8.0", "8.1", "8.2", "8.3"]'
old_stable: '["8.1", "8.2", "8.3"]'
current_stable: 8.4
23 changes: 23 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Changelog

All notable changes to this project will be documented in this file.

## [1.4.0] - 2026-01-29

### Added
- PHP 8 Attribute support for `UploadFiles`.
- Lazy Loading example in README.

### Changed
- Required PHP version increased to `^8.1`.
- `HttpRequestProvider` now implements `Ray\Di\ProviderInterface` directly.
- Updated `doctrine/coding-standard` to `^13.0`.

### Deprecated
- `Ray\HttpMessage\RequestProviderInterface` (Use `Ray\Di\ProviderInterface` instead).
- `Ray\HttpMessage\HttpRequestRayProvider` (Use `Ray\HttpMessage\HttpRequestProvider` instead).

### Removed
- Support for PHP 7.3, 7.4, and 8.0.
- Dependency on `doctrine/annotations` and `koriym/attributes`.
- Direct dependency on `ray/aop`.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) <2018-2021> <Akihito Koriyama>
Copyright (c) <2018-2026> <Akihito Koriyama>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
32 changes: 26 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,35 @@ use Ray\HttpMessage\Annotation\UploadFiles;

class Foo
{
/**
* @UploadFiles
*/
public function __construct(array $files)
{
public function __construct(
#[UploadFiles] array $files
) {
// retrieve file name
$file = $files['my-form']['details']['avatar'][0]
$file = $files['my-form']['details']['avatar'][0];
/* @var UploadedFileInterface $file */
$name = $file->getClientFilename(); // my-avatar3.png
}
}
````

### Lazy Loading

If you want to lazy load the `ServerRequest`, use `Ray\Di\Di\Set` attribute.

```php
use Ray\Di\Di\Set;
use Ray\Di\ProviderInterface;
use Psr\Http\Message\ServerRequestInterface;

class Foo
{
public function __construct(
#[Set(ServerRequestInterface::class)] private ProviderInterface $requestProvider
) {}

public function onGet()
{
$request = $this->requestProvider->get();
}
}
```
70 changes: 54 additions & 16 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,14 @@
}
],
"require": {
"php": "^7.3 || ^8.0",
"php": "^8.1",
"psr/http-message": "^1.0 || ^2.0",
"nyholm/psr7": "^1.0",
"nyholm/psr7-server": "^1.0",
"ray/di": "^2.11",
"ray/aop": "^2.10.3"
"ray/di": "^2.11"
},
"require-dev": {
"phpunit/phpunit": "^8.5.41 || ^9.5",
"phpunit/phpunit": "^9.5",
"bamarni/composer-bin-plugin": "^1.4"
},
"autoload": {
Expand All @@ -34,21 +33,60 @@
}
},
"scripts": {
"test": ["./vendor/bin/phpunit"],
"tests": ["@cs", "@test", "@sa"],
"coverage": ["php -dzend_extension=xdebug.so -dxdebug.mode=coverage ./vendor/bin/phpunit --coverage-text --coverage-html=build/coverage"],
"pcov": ["php -dextension=pcov.so -d pcov.enabled=1 ./vendor/bin/phpunit --coverage-text --coverage-html=build/coverage --coverage-clover=coverage.xml"],
"cs": ["phpcs --standard=./phpcs.xml src tests"],
"cs-fix": ["./vendor/bin/phpcbf src tests"],
"clean": ["./vendor/bin/phpstan clear-result-cache", "./vendor/bin/psalm --clear-cache", "rm -rf tests/tmp/*.php"],
"sa": ["./vendor/bin/phpstan analyse -c phpstan.neon", "psalm --show-info=true"],
"metrics": ["./vendor/bin/phpmetrics --report-html=build/metrics --exclude=Exception --junit=build/junit.xml src"],
"phpmd": ["./vendor/bin/phpmd --exclude src/Annotation src text ./phpmd.xml"],
"build": ["@cs", "@sa", "@pcov", "@metrics"]
"test": [
"./vendor/bin/phpunit"
],
"tests": [
"@cs",
"@test",
"@sa"
],
"coverage": [
"php -dzend_extension=xdebug.so -dxdebug.mode=coverage ./vendor/bin/phpunit --coverage-text --coverage-html=build/coverage"
],
"pcov": [
"php -dextension=pcov.so -d pcov.enabled=1 ./vendor/bin/phpunit --coverage-text --coverage-html=build/coverage --coverage-clover=coverage.xml"
],
"cs": [
"phpcs --standard=./phpcs.xml src tests"
],
"cs-fix": [
"./vendor/bin/phpcbf src tests"
],
"clean": [
"./vendor/bin/phpstan clear-result-cache",
"./vendor/bin/psalm --clear-cache",
"rm -rf tests/tmp/*.php"
],
"sa": [
"./vendor/bin/phpstan analyse -c phpstan.neon",
"psalm --show-info=true"
],
"metrics": [
"./vendor/bin/phpmetrics --report-html=build/metrics --exclude=Exception --junit=build/junit.xml src"
],
"phpmd": [
"./vendor/bin/phpmd --exclude src/Annotation src text ./phpmd.xml"
],
"build": [
"@cs",
"@sa",
"@pcov",
"@metrics"
],
"post-install-cmd": [
"@composer bin all install --ansi --ignore-platform-reqs"
],
"post-update-cmd": [
"@composer bin all install --ansi --ignore-platform-reqs"
]
},
"config": {
"allow-plugins": {
"bamarni/composer-bin-plugin": true
},
"platform": {
"php": "8.1"
}
},
"extra": {
Expand All @@ -57,4 +95,4 @@
"bin-links": true
}
}
}
}
5 changes: 0 additions & 5 deletions src/Annotation/UploadFiles.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,6 @@
use Attribute;
use Ray\Di\Di\Qualifier;

/**
* @Annotation
* @Target("METHOD")
* @Qualifier
*/
#[Attribute(Attribute::TARGET_METHOD), Qualifier]
final class UploadFiles
{
Expand Down
11 changes: 8 additions & 3 deletions src/HttpRequestProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,16 @@
use Nyholm\Psr7\Factory\Psr17Factory;
use Nyholm\Psr7Server\ServerRequestCreator;
use Psr\Http\Message\ServerRequestInterface;
use Ray\Di\ProviderInterface;

final class HttpRequestProvider implements RequestProviderInterface
/**
* @implements ProviderInterface<ServerRequestInterface>
* @psalm-suppress DeprecatedInterface
*/
final class HttpRequestProvider implements ProviderInterface, RequestProviderInterface
{
/**
* {@inheritdoc}
* {@inheritDoc}
*/
public function get(): ServerRequestInterface
{
Expand All @@ -21,7 +26,7 @@ public function get(): ServerRequestInterface
$psr17Factory, // ServerRequestFactory
$psr17Factory, // UriFactory
$psr17Factory, // UploadedFileFactory
$psr17Factory // StreamFactory
$psr17Factory, // StreamFactory
))->fromGlobals();
}
}
8 changes: 6 additions & 2 deletions src/HttpRequestRayProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,15 @@
use Psr\Http\Message\ServerRequestInterface;
use Ray\Di\ProviderInterface;

/** @implements ProviderInterface<ServerRequestInterface> */
/**
* @implements ProviderInterface<ServerRequestInterface>
* @deprecated
* @codeCoverageIgnore
*/
final class HttpRequestRayProvider implements ProviderInterface
{
/**
* {@inheritdoc}
* {@inheritDoc}
*/
public function get()
{
Expand Down
4 changes: 2 additions & 2 deletions src/Psr7Module.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ class Psr7Module extends AbstractModule
protected function configure()
{
$this->bind(RequestProviderInterface::class)->to(HttpRequestProvider::class);
$this->bind(ServerRequest::class)->toProvider(HttpRequestRayProvider::class);
$this->bind(ServerRequestInterface::class)->toProvider(HttpRequestRayProvider::class);
$this->bind(ServerRequest::class)->toProvider(HttpRequestProvider::class);
$this->bind(ServerRequestInterface::class)->toProvider(HttpRequestProvider::class);
$this->bind(UriInterface::class)->toProvider(UriProvider::class);
$this->bind()->annotatedWith(UploadFiles::class)->toProvider(UploadfilesProvider::class);
}
Expand Down
4 changes: 4 additions & 0 deletions src/RequestProviderInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@

use Psr\Http\Message\ServerRequestInterface;

/**
* @deprecated
* @codeCoverageIgnore
*/
interface RequestProviderInterface
{
public function get(): ServerRequestInterface;
Expand Down
2 changes: 1 addition & 1 deletion src/UploadfilesProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
final class UploadfilesProvider implements ProviderInterface
{
/**
* {@inheritdoc}
* {@inheritDoc}
*/
public function get()
{
Expand Down
2 changes: 1 addition & 1 deletion src/UriProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
final class UriProvider implements ProviderInterface
{
/**
* {@inheritdoc}
* {@inheritDoc}
*/
public function get()
{
Expand Down
8 changes: 2 additions & 6 deletions tests/Psr7HttpModuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,7 @@ public function testPsr7UploadFilesTest(): void
$this->assertSame('my-avatar3.png', $file->getClientFilename());
}

/**
* @return array<string>tests/Psr7HttpModuleTest.php
*/
/** @return array<string, string> */
public function superGlobalsServer(): array
{
return [
Expand All @@ -75,9 +73,7 @@ public function superGlobalsServer(): array
];
}

/**
* @return array<string, array<mixed>>
*/
/** @return array<string, array<mixed>> */
public function files(): array
{
return [
Expand Down
8 changes: 0 additions & 8 deletions tests/bootstrap.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,3 @@
<?php

declare(strict_types=1);

use Koriym\Attributes\AttributeReader;
use Ray\ServiceLocator\ServiceLocator;

// no annotation in PHP 8
if (PHP_MAJOR_VERSION >= 8) {
ServiceLocator::setReader(new AttributeReader());
}
4 changes: 2 additions & 2 deletions vendor-bin/tools/composer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"require": {
"doctrine/coding-standard": "^8.2",
"doctrine/coding-standard": "^13.0",
"phpmd/phpmd": "^2.9",
"phpmetrics/phpmetrics": "^2.7",
"phpstan/phpstan": "^1.10",
Expand All @@ -13,4 +13,4 @@
"dealerdirect/phpcodesniffer-composer-installer": true
}
}
}
}
Loading
Loading