/** * @param string $name * @param string $vhost * @param string $config * @param string $write * @param string $read * * @return bool * @throws Exception * @throws \Retrinko\Scylla\Exceptions\Exception * @throws \Retrinko\UrlComposer\Exceptions\UrlException */ public function setUserPermissions($name, $vhost = '%2f', $config = '', $write = '', $read = '') { // Build URL: /permissions/$vhost/$name $url = new UrlComposer($this->apiUrl); $url->addToPath('permissions')->addToPath($vhost)->addToPath($name); // Build request $request = new JsonRequest($url->__toString(), RequestInterface::REQUEST_METHOD_PUT); $request->setAuth($this->user, $this->pass); $request->addParam('configure', $config)->addParam('write', $write)->addParam('read', $read); // Execute request /** @var ResponseInterface $response */ $response = $this->httpClient->exec($request)->current(); $loggerEnv['code'] = $response->getCode(); $loggerEnv['msg'] = $response->getMessage(); // Check response code $this->executeRequest($request); return true; }
<?php use Retrinko\Scylla\Client; use Retrinko\Scylla\Request\Requests\JsonRequest; use Retrinko\Scylla\Request\RequestsCollection; use Retrinko\Scylla\Response\Factories\JsonResponsesFactory; use Retrinko\Scylla\Response\ResponseInterface; use Retrinko\Scylla\Util\HttpCodes; require_once __DIR__ . '/../vendor/autoload.php'; date_default_timezone_set('UTC'); $logger = new Monolog\Logger('test'); $logger->pushHandler(new \Monolog\Handler\StreamHandler('php://stdout')); try { // Instance new client $client = new Client(); // Configure your client $client->setLogger($logger); $client->setResponsesFactory(new JsonResponsesFactory()); $client->usePipelining(true); // Create requests $urls = ['ip' => 'https://httpbin.org/ip', 'userAgent' => 'https://httpbin.org/user-agent', 'get' => 'https://httpbin.org/get']; $requestsCollection = new RequestsCollection(); foreach ($urls as $id => $url) { // Configure request $request = new JsonRequest($url); $request->setId($id); // Add request to requests collecction $requestsCollection->add($request); } // Execute requests $responsesCollection = $client->exec($requestsCollection);
<?php use Retrinko\Scylla\Client; use Retrinko\Scylla\Request\Requests\DefaultRequest; use Retrinko\Scylla\Util\HttpCodes; require_once __DIR__ . '/../vendor/autoload.php'; date_default_timezone_set('UTC'); $logger = new Monolog\Logger('test'); $logger->pushHandler(new \Monolog\Handler\StreamHandler('php://stdout')); try { // Instance new client $client = new Client(); // Configure your client $client->setLogger($logger); // Configure your requests $sampleRequest = new DefaultRequest('https://httpbin.org/html'); $sampleRequest->verificatePeersSSLCertificate(true); // Execute requests $responsesCollection = $client->exec($sampleRequest); // Get current response /** @var Retrinko\Scylla\Response\ResponseInterface $response */ $response = $responsesCollection->current(); // Check http code and read response data or error message $code = $response->getCode(); if (false == HttpCodes::isError($code)) { $logger->notice('Execution success!'); // Get response body $resposeBody = $response->getDecodedContent(); var_dump($resposeBody); } else { // Get response message (error)