jeyroik / extas-protocols
Extas protocols package
Installs: 1 306
Dependents: 9
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
Requires
Requires (Dev)
README
Описание
Пакет для поддержки протоколов для 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 }