PHP code example of yiisoft / http

1. Go to this page and download the library: Download yiisoft/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/ */

    

yiisoft / http example snippets


use Yiisoft\Http\Method;

Method::GET;
Method::POST;
Method::PUT;
Method::DELETE;
Method::PATCH;
Method::HEAD;
Method::OPTIONS;

use Yiisoft\Http\Method;

Method::ALL;

use Yiisoft\Http\Status;

Status::NOT_FOUND;

use Yiisoft\Http\Status;

Status::TEXTS[Status::NOT_FOUND];

use Yiisoft\Http\ContentDispositionHeader;

$name = ContentDispositionHeader::name();

$value = ContentDispositionHeader::value(
    ContentDispositionHeader::INLINE,
    'avatar.png',
);

$value = ContentDispositionHeader::inline('document.pdf');

$value = ContentDispositionHeader::attachment('document.pdf');

use Yiisoft\Http\HeaderValueHelper;

// Result: ['a' => '1', 'b' => '2']
HeaderValueHelper::getParameters('a=1;b=2');

// Result: ['value', 'a' => '1', 'b' => '2']
HeaderValueHelper::getValueAndParameters('value;a=1;b=2'));

// Result: [['value2', 'q' => 1.0], ['value1', 'q' => 0.2]]
HeaderValueHelper::getSortedValueAndParameters('value1;q=0.2,value2'));

// Result: ['text/xml', 'text/html']
HeaderValueHelper::getSortedAcceptTypes('text/html;q=0.2,text/xml;q=0.4'));

use Psr\Http\Message\ResponseFactoryInterface;
use Psr\Http\Message\ResponseInterface;
use Yiisoft\Http\Header;
use Yiisoft\Http\Status;

class StaticController
{
    private ResponseFactoryInterface $responseFactory;

    public function actionIndex(): ResponseInterface
    {
        return $this->responseFactory
            ->createResponse()
            ->withStatus(Status::OK)
            ->withoutHeader(Header::ACCEPT);
    }
}