PHP 组件/库。


README

一个极简的 PHP PSR 实现。

实现

提供

  • psr/http-factory-implementation
  • psr/http-message-implementation

故障排除

php-http/discovery

如果使用需要 php-http/discovery 的项目/库,将强制列出 9 个“知名”实现。

安装您选择的自定义实现的解决方案

  1. 创建自定义策略 - 实现 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 [];
    }
}
  1. 使用自定义策略
use Http\Discovery\ClassDiscovery;
use Project\Factory\Http\Discovery\Psr17DiscoveryStrategy;

// Before instantiating the class that uses `php-http/discovery`
ClassDiscovery::prependStrategy(Psr17DiscoveryStrategy::class);