PHP code example of webservco / http

1. Go to this page and download the library: Download webservco/http library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

webservco / http example snippets




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);