webservco / http
PHP 组件/库。
v0.11.0
2024-08-23 15:59 UTC
Requires
Requires (Dev)
- pds/skeleton: ^1
- phan/phan: ^5
- php-parallel-lint/php-console-highlighter: ^1
- php-parallel-lint/php-parallel-lint: ^1
- phpcompatibility/php-compatibility: ^9
- phpmd/phpmd: ^2
- phpstan/phpstan: ^1
- phpstan/phpstan-phpunit: ^1
- phpstan/phpstan-strict-rules: ^1
- phpunit/phpunit: ^10
- slevomat/coding-standard: ^8
- squizlabs/php_codesniffer: ^3
- vimeo/psalm: ^5
- webservco/coding-standards: ^0
- webservco/component-common: ^0
README
一个极简的 PHP PSR 实现。
实现
提供
psr/http-factory-implementation
psr/http-message-implementation
故障排除
php-http/discovery
如果使用需要 php-http/discovery
的项目/库,将强制列出 9 个“知名”实现。
安装您选择的自定义实现的解决方案
- 创建自定义策略 - 实现
Http\Discovery\Strategy\DiscoveryStrategy
<?php declare(strict_types=1); namespace Project\Factory\Http\Discovery; use Http\Discovery\Strategy\DiscoveryStrategy; use Psr\Http\Message\RequestFactoryInterface; use Psr\Http\Message\StreamFactoryInterface; // A RequestFactoryInterface implementation of your choice: use WebServCo\Http\Factory\Message\Request\RequestFactory; // A StreamFactoryInterface implementation of your choice: use WebServCo\Http\Factory\Message\Stream\StreamFactory; final class Psr17DiscoveryStrategy implements DiscoveryStrategy { /** * @inheritDoc * @param string $type * @return array<array<string, string>> */ public static function getCandidates($type) { if ($type === RequestFactoryInterface::class) { return [ [ 'class' => RequestFactory::class, ], ]; } if ($type === StreamFactoryInterface::class) { return [ [ 'class' => StreamFactory::class, ], ]; } return []; } }
- 使用自定义策略
use Http\Discovery\ClassDiscovery; use Project\Factory\Http\Discovery\Psr17DiscoveryStrategy; // Before instantiating the class that uses `php-http/discovery` ClassDiscovery::prependStrategy(Psr17DiscoveryStrategy::class);
- 解决方案归功于: Popus Razvan Adrian
- 文档: 策略