https://github.com/yiisoft/request-provider
Provides current PSR-7 request as a dependency.
https://github.com/yiisoft/request-provider
http psr psr-7 request yii3
Last synced: 4 months ago
JSON representation
Provides current PSR-7 request as a dependency.
- Host: GitHub
- URL: https://github.com/yiisoft/request-provider
- Owner: yiisoft
- License: bsd-3-clause
- Created: 2024-02-22T08:52:57.000Z (almost 2 years ago)
- Default Branch: master
- Last Pushed: 2024-03-04T16:32:07.000Z (almost 2 years ago)
- Last Synced: 2024-04-13T23:52:01.700Z (almost 2 years ago)
- Topics: http, psr, psr-7, request, yii3
- Language: PHP
- Homepage: https://www.yiiframework.com
- Size: 25.4 KB
- Stars: 5
- Watchers: 13
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: .github/CONTRIBUTING.md
- Funding: .github/FUNDING.yml
- License: LICENSE.md
- Code of conduct: .github/CODE_OF_CONDUCT.md
- Security: .github/SECURITY.md
Awesome Lists containing this project
README
Yii Request Provider
[](https://packagist.org/packages/yiisoft/request-provider)
[](https://packagist.org/packages/yiisoft/request-provider)
[](https://github.com/yiisoft/request-provider/actions/workflows/build.yml)
[](https://codecov.io/gh/yiisoft/request-provider)
[](https://dashboard.stryker-mutator.io/reports/github.com/yiisoft/request-provider/master)
[](https://github.com/yiisoft/request-provider/actions?query=workflow%3A%22static+analysis%22)
[](https://shepherd.dev/github/yiisoft/request-provider)
[](https://shepherd.dev/github/yiisoft/request-provider)
The package provides the current PSR-7 request as a dependency.
## Requirements
- PHP 8.1 or higher.
## Installation
The package can be installed with [Composer](https://getcomposer.org):
```shell
composer require yiisoft/request-provider
```
## General usage
First, add the `Yiisoft\RequestProvider\RequestCatcherMiddleware` to your application middleware stack.
Then, when you need the current request, get the `RequestProviderInterface` as a dependency and obtain the request from it:
```php
use Yiisoft\RequestProvider\RequestProviderInterface;
final class MyService
{
public function __construct(
private readonly RequestProviderInterface $requestProvider
)
{
}
public function doIt()
{
$request = $this->requestProvider->get();
// ...
}
}
```
### Request cookies provider
You can work with cookies as follows:
```php
class MyClass
{
public function __construct(
private \Yiisoft\RequestProvider\RequestCookieProvider $cookies
) {}
public function go(): void
{
$this->cookies->has('foo');
$this->cookies->get('bar');
}
}
```
### Request headers provider
You can work with headers as follows:
```php
class MyClass
{
public function __construct(
private \Yiisoft\RequestProvider\RequestHeaderProvider $headers
) {}
public function go(): void
{
$this->headers->has('X-Foo');
$this->headers->get('X-Foo');
$this->headers->getLine('X-Foo');
$this->headers->getAll();
$this->headers->getFirstHeaders();
}
}
```
## Documentation
- [Internals](docs/internals.md)
If you need help or have a question, the [Yii Forum](https://forum.yiiframework.com/c/yii-3-0/63) is a helpful resource.
You may also check out other resources at [Yii Community Resources](https://www.yiiframework.com/community).
## License
The Yii Request Provider is free software. It is released under the terms of the BSD License.
Please see [`LICENSE`](./LICENSE.md) for more information.
Maintained by [Yii Software](https://www.yiiframework.com/).
## Support the project
[](https://opencollective.com/yiisoft)
## Follow updates
[](https://www.yiiframework.com/)
[](https://twitter.com/yiiframework)
[](https://t.me/yii3en)
[](https://www.facebook.com/groups/yiitalk)
[](https://yiiframework.com/go/slack)