PHP code example of jeyroik / extas-protocols

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

    

jeyroik / extas-protocols example snippets


namespace my\extas\protocols;

use extas\components\protocols\Protocol;use Psr\Http\Message\RequestInterface;

class JsonProtocol extends Protocol
{
    public function __invoke(array &$args = [], RequestInterface $request = null) : void{
    {
        $json = file_get_contents('php://input');
        if ($json) {
            $jsonData = json_decode($json, true);
            $args = array_merge($args, $jsonData);
        }
    }
}

use extas\interafces\protocols\IProtocol;
use extas\components\SystemContainer;

/**
 * @param Psr\Http\Message\RequestInterface $request
 * @param Psr\Http\Message\ResponseInterface $response
 * @param array $args
 */
function ($request, $response, $args) {
    /**
     * @var $protocols IProtocol[]
     */
    $protocols = $this->protocolRepository()->all([
        IProtocol::FIELD__ACCEPT => [$request->getHeader('ACCEPT'), '*']
    ]);
    
    foreach ($protocols as $protocol) {
        $protocol($args, $request);
    }
    
    print_r($args); // содержит данные из json
}