Skip to content

jeyroik/extas-protocols

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

29 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

tests codecov.io PHPStan Enabled Latest Stable Version Total Downloads Dependents

Описание

Пакет для поддержки протоколов для Extas'a.

Использование

Создаём протокол

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

Установка протокола

В extas-совместимой конфигурации

{
  "protocols": [
    {
      "name": "json",
      "title": "JSON protocol",
      "description": "JSON protocol, extracting from php://input",
      "accept": ["application/json", "json"],
      "class": "my\\extas\\protocols\\JsonProtocol"
    }
  ]
}

Установка

/vendor/bin/extas i

Применение

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
}

About

Protocols package for Extas

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages