One Hat Cyber Team
Your IP:
216.73.216.102
Server IP:
198.54.114.155
Server:
Linux server71.web-hosting.com 4.18.0-513.18.1.lve.el8.x86_64 #1 SMP Thu Feb 22 12:55:50 UTC 2024 x86_64
Server Software:
LiteSpeed
PHP Version:
5.6.40
Create File
|
Create Folder
Execute
Dir :
~
/
home
/
fluxyjvi
/
www
/
assets
/
images
/
View File Name :
Client.tar
Signature.php 0000644 00000007525 15107443646 0007241 0 ustar 00 <?php /** * Vonage Client Library for PHP * * @copyright Copyright (c) 2016-2022 Vonage, Inc. (http://vonage.com) * @license https://github.com/Vonage/vonage-php-sdk-core/blob/master/LICENSE.txt Apache License 2.0 */ declare(strict_types=1); namespace Vonage\Client; use InvalidArgumentException; use Vonage\Client\Exception\Exception as ClientException; use function hash_hmac; use function http_build_query; use function is_array; use function is_string; use function ksort; use function md5; use function str_replace; use function strtolower; use function strtoupper; use function time; use function urldecode; class Signature implements \Stringable { /** * Params with Signature (and timestamp if not present) * * @var array */ protected $signed; /** * Create a signature from a set of parameters. * * @throws ClientException */ public function __construct(/** * Params to Sign */ protected array $params, $secret, $signatureMethod) { $this->signed = $params; if (!isset($this->signed['timestamp'])) { $this->signed['timestamp'] = time(); } //remove signature if present unset($this->signed['sig']); //sort params ksort($this->signed); $signed = []; foreach ($this->signed as $key => $value) { $signed[$key] = str_replace(["&", "="], "_", (string) $value); } //create base string $base = '&' . urldecode(http_build_query($signed)); $this->signed['sig'] = $this->sign($signatureMethod, $base, $secret); } /** * @param $signatureMethod * @param $data * @param $secret * * @throws ClientException */ protected function sign($signatureMethod, $data, $secret): string { switch ($signatureMethod) { case 'md5hash': // md5hash needs the secret appended $data .= $secret; return md5($data); case 'md5': case 'sha1': case 'sha256': case 'sha512': return strtoupper(hash_hmac($signatureMethod, $data, $secret)); default: throw new ClientException( 'Unknown signature algorithm: ' . $signatureMethod . '. Expected: md5hash, md5, sha1, sha256, or sha512' ); } } /** * Get the original parameters. */ public function getParams(): array { return $this->params; } /** * Get the signature for the parameters. */ public function getSignature(): string { return $this->signed['sig']; } /** * Get a full set of parameters including the signature and timestamp. */ public function getSignedParams(): array { return $this->signed; } /** * Check that a signature (or set of parameters) is valid. * * First instantiate a Signature object: this will drop any supplied * signature parameter and calculate the correct one. Then call this * method and supply the signature that came in with the request. * * @param array|string $signature The incoming sig parameter to check (or all incoming params) * * @throws InvalidArgumentException */ public function check($signature): bool { if (is_array($signature) && isset($signature['sig'])) { $signature = $signature['sig']; } if (!is_string($signature)) { throw new InvalidArgumentException('signature must be string, or present in array or parameters'); } return strtolower($signature) === strtolower($this->signed['sig']); } /** * Allow easy comparison. */ public function __toString(): string { return $this->getSignature(); } } APIResource.php 0000644 00000031733 15107443646 0007417 0 ustar 00 <?php /** * Vonage Client Library for PHP * * @copyright Copyright (c) 2016-2022 Vonage, Inc. (http://vonage.com) * @license https://github.com/Vonage/vonage-php-sdk-core/blob/master/LICENSE.txt Apache License 2.0 */ declare(strict_types=1); namespace Vonage\Client; use Laminas\Diactoros\Request; use Psr\Log\LogLevel; use Vonage\Client\Credentials\Handler\BasicHandler; use Vonage\Entity\Filter\EmptyFilter; use Psr\Http\Message\RequestInterface; use Psr\Http\Message\ResponseInterface; use Vonage\Entity\IterableAPICollection; use Vonage\Entity\Filter\FilterInterface; use Psr\Http\Client\ClientExceptionInterface; use Vonage\Client\Credentials\Handler\HandlerInterface; use Vonage\Logger\LoggerTrait; use function is_null; use function json_decode; use function json_encode; use function http_build_query; class APIResource implements ClientAwareInterface { use ClientAwareTrait; use LoggerTrait; /** * @var HandlerInterface[] */ protected array $authHandler = []; /** * Base URL that we will hit. This can be overridden from the underlying * client or directly on this class. */ protected string $baseUrl = ''; protected string $baseUri = ''; protected string $collectionName = ''; protected ?IterableAPICollection $collectionPrototype = null; /** * Sets flag that says to check for errors even on 200 Success */ protected bool $errorsOn200 = false; /** * Error handler to use when reviewing API responses * * @var callable */ protected $exceptionErrorHandler; protected bool $isHAL = true; protected ?RequestInterface $lastRequest = null; protected ?ResponseInterface $lastResponse = null; /** * Adds authentication to a request * */ public function addAuth(RequestInterface $request): RequestInterface { $credentials = $this->getClient()->getCredentials(); if (is_array($this->getAuthHandler())) { foreach ($this->getAuthHandler() as $handler) { try { $request = $handler($request, $credentials); break; } catch (\RuntimeException $e) { continue; // We are OK if multiple are sent but only one match } throw new \RuntimeException( 'Unable to set credentials, please check configuration and supplied authentication' ); } return $request; } return $this->getAuthHandler()($request, $credentials); } /** * @throws ClientExceptionInterface * @throws Exception\Exception */ public function create(array $body, string $uri = '', array $headers = []): ?array { if (empty($headers)) { $headers = ['content-type' => 'application/json']; } $request = new Request( $this->getBaseUrl() . $this->getBaseUri() . $uri, 'POST', 'php://temp', $headers ); $request->getBody()->write(json_encode($body)); if ($this->getAuthHandler()) { $request = $this->addAuth($request); } $this->lastRequest = $request; $response = $this->getClient()->send($request); $status = (int)$response->getStatusCode(); $this->setLastResponse($response); if (($status < 200 || $status > 299) || $this->errorsOn200()) { $e = $this->getException($response, $request); if ($e) { $e->setEntity($body); throw $e; } } $response->getBody()->rewind(); return json_decode($response->getBody()->getContents(), true); } /** * @throws ClientExceptionInterface * @throws Exception\Exception */ public function delete(string $id, array $headers = []): ?array { $uri = $this->getBaseUrl() . $this->baseUri . '/' . $id; if (empty($headers)) { $headers = [ 'accept' => 'application/json', 'content-type' => 'application/json' ]; } $request = new Request( $uri, 'DELETE', 'php://temp', $headers ); if ($this->getAuthHandler()) { $request = $this->addAuth($request); } $response = $this->getClient()->send($request); $status = (int)$response->getStatusCode(); $this->lastRequest = $request; $this->setLastResponse($response); if ($status < 200 || $status > 299) { $e = $this->getException($response, $request); $e->setEntity($id); throw $e; } $response->getBody()->rewind(); return json_decode($response->getBody()->getContents(), true); } /** * @throws ClientExceptionInterface * @throws Exception\Exception */ public function get($id, array $query = [], array $headers = [], bool $jsonResponse = true, bool $uriOverride = false) { $uri = $this->getBaseUrl() . $this->baseUri . '/' . $id; // This is a necessary hack if you want to fetch a totally different URL but use Vonage Auth if ($uriOverride) { $uri = $id; } if (!empty($query)) { $uri .= '?' . http_build_query($query); } if (empty($headers)) { $headers = [ 'accept' => 'application/json', 'content-type' => 'application/json' ]; } $request = new Request( $uri, 'GET', 'php://temp', $headers ); if ($this->getAuthHandler()) { $request = $this->addAuth($request); } $response = $this->getClient()->send($request); $status = (int)$response->getStatusCode(); $this->lastRequest = $request; $this->setLastResponse($response); if ($status < 200 || $status > 299) { $e = $this->getException($response, $request); $e->setEntity($id); throw $e; } if (!$jsonResponse) { return $response->getBody(); } return json_decode($response->getBody()->getContents(), true); } public function getAuthHandler() { // If we have not set a handler, default to Basic and issue warning. if (!$this->authHandler) { $this->log( LogLevel::WARNING, 'Warning: no authorisation handler set for this Client. Defaulting to Basic which might not be the correct authorisation for this API call' ); return new BasicHandler(); } return $this->authHandler; } public function getBaseUrl(): ?string { if (!$this->baseUrl && $this->client) { $this->baseUrl = $this->client->getApiUrl(); } return $this->baseUrl; } public function getBaseUri(): ?string { return $this->baseUri; } public function getCollectionName(): string { return $this->collectionName; } public function getCollectionPrototype(): IterableAPICollection { if (is_null($this->collectionPrototype)) { $this->collectionPrototype = new IterableAPICollection(); } return clone $this->collectionPrototype; } public function getExceptionErrorHandler(): callable { if (is_null($this->exceptionErrorHandler)) { return new APIExceptionHandler(); } return $this->exceptionErrorHandler; } /** * Sets the error handler to use when reviewing API responses. */ public function setExceptionErrorHandler(callable $handler): self { $this->exceptionErrorHandler = $handler; return $this; } protected function getException(ResponseInterface $response, RequestInterface $request) { return $this->getExceptionErrorHandler()($response, $request); } public function getLastRequest(): ?RequestInterface { $this->lastRequest->getBody()->rewind(); return $this->lastRequest; } public function getLastResponse(): ?ResponseInterface { $this->lastResponse->getBody()->rewind(); return $this->lastResponse; } public function isHAL(): bool { return $this->isHAL; } public function partiallyUpdate(string $id, array $body, array $headers = []): ?array { return $this->updateEntity('PATCH', $id, $body, $headers); } public function search(?FilterInterface $filter = null, string $uri = ''): IterableAPICollection { if (is_null($filter)) { $filter = new EmptyFilter(); } $api = clone $this; if ($uri) { $api->setBaseUri($uri); } $collection = $this->getCollectionPrototype(); $collection ->setApiResource($api) ->setFilter($filter); $collection->setClient($this->client); return $collection; } /** * Set the auth handler(s). This can be a handler that extends off AbstractHandler, * or an array of handlers that will attempt to resolve at runtime * * @param HandlerInterface|array $handler * * @return $this */ public function setAuthHandler($handler): self { if (!is_array($handler)) { $handler = [$handler]; } $this->authHandler = $handler; return $this; } public function setBaseUrl(string $url): self { $this->baseUrl = $url; return $this; } public function setBaseUri(string $uri): self { $this->baseUri = $uri; return $this; } public function setCollectionName(string $name): self { $this->collectionName = $name; return $this; } public function setCollectionPrototype(IterableAPICollection $prototype): self { $this->collectionPrototype = $prototype; return $this; } public function setIsHAL(bool $state): self { $this->isHAL = $state; return $this; } public function setLastResponse(ResponseInterface $response): self { $this->lastResponse = $response; return $this; } public function setLastRequest(RequestInterface $request): self { $this->lastRequest = $request; return $this; } /** * Allows form URL-encoded POST requests. * * @throws ClientExceptionInterface * @throws Exception\Exception */ public function submit(array $formData = [], string $uri = '', array $headers = []): string { if (empty($headers)) { $headers = ['content-type' => 'application/x-www-form-urlencoded']; } $request = new Request( $this->baseUrl . $this->baseUri . $uri, 'POST', 'php://temp', $headers ); if ($this->getAuthHandler()) { $request = $this->addAuth($request); } $request->getBody()->write(http_build_query($formData)); $response = $this->getClient()->send($request); $status = $response->getStatusCode(); $this->lastRequest = $request; $this->setLastResponse($response); if ($status < 200 || $status > 299) { $e = $this->getException($response, $request); $e->setEntity($formData); throw $e; } return $response->getBody()->getContents(); } public function update(string $id, array $body, array $headers = []): ?array { return $this->updateEntity('PUT', $id, $body, $headers); } /** * @throws ClientExceptionInterface * @throws Exception\Exception */ protected function updateEntity(string $method, string $id, array $body, array $headers = []): ?array { if (empty($headers)) { $headers = ['content-type' => 'application/json']; } $request = new Request( $this->getBaseUrl() . $this->baseUri . '/' . $id, $method, 'php://temp', $headers ); if ($this->getAuthHandler()) { $request = $this->addAuth($request); } $request->getBody()->write(json_encode($body)); $response = $this->getClient()->send($request); $this->lastRequest = $request; $this->setLastResponse($response); $status = $response->getStatusCode(); if (($status < 200 || $status > 299) || $this->errorsOn200()) { $e = $this->getException($response, $request); $e->setEntity(['id' => $id, 'body' => $body]); throw $e; } return json_decode($response->getBody()->getContents(), true); } public function errorsOn200(): bool { return $this->errorsOn200; } public function setErrorsOn200(bool $value): self { $this->errorsOn200 = $value; return $this; } } Exception/Transport.php 0000644 00000000153 15107443647 0011221 0 ustar 00 <?php declare(strict_types=1); namespace Vonage\Client\Exception; class Transport extends Exception { } Exception/Server.php 0000644 00000000323 15107443647 0010472 0 ustar 00 <?php declare(strict_types=1); namespace Vonage\Client\Exception; use Vonage\Entity\HasEntityTrait; use Vonage\Entity\Psr7Trait; class Server extends Exception { use HasEntityTrait; use Psr7Trait; } Exception/Validation.php 0000644 00000000630 15107443647 0011317 0 ustar 00 <?php declare(strict_types=1); namespace Vonage\Client\Exception; use Throwable; class Validation extends Request { public function __construct(string $message = '', int $code = 0, Throwable $previous = null, private array $errors = []) { parent::__construct($message, $code, $previous); } public function getValidationErrors(): array { return $this->errors; } } Exception/Exception.php 0000644 00000000154 15107443647 0011164 0 ustar 00 <?php declare(strict_types=1); namespace Vonage\Client\Exception; class Exception extends \Exception { } Exception/Request.php 0000644 00000001245 15107443647 0010660 0 ustar 00 <?php declare(strict_types=1); namespace Vonage\Client\Exception; use Vonage\Entity\HasEntityTrait; use Vonage\Entity\Psr7Trait; class Request extends Exception { use HasEntityTrait; use Psr7Trait; protected string $requestId; protected string $networkId; public function setRequestId(string $requestId): void { $this->requestId = $requestId; } public function getRequestId(): string { return $this->requestId; } public function setNetworkId(string $networkId): void { $this->networkId = $networkId; } public function getNetworkId(): string { return $this->networkId; } } Exception/ThrottleException.php 0000644 00000000535 15107443647 0012715 0 ustar 00 <?php declare(strict_types=1); namespace Vonage\Client\Exception; class ThrottleException extends Server { /** * @var int */ protected $timeout; public function setTimeout(int $seconds): void { $this->timeout = $seconds; } public function getTimeout(): int { return $this->timeout; } } Exception/Conflict.php 0000644 00000000153 15107443650 0010760 0 ustar 00 <?php declare(strict_types=1); namespace Vonage\Client\Exception; class Conflict extends \Exception { } Exception/NotFound.php 0000644 00000000153 15107443650 0010753 0 ustar 00 <?php declare(strict_types=1); namespace Vonage\Client\Exception; class NotFound extends \Exception { } Exception/Credentials.php 0000644 00000000156 15107443650 0011457 0 ustar 00 <?php declare(strict_types=1); namespace Vonage\Client\Exception; class Credentials extends \Exception { } Credentials/CredentialsInterface.php 0000644 00000000542 15107443650 0013576 0 ustar 00 <?php /** * Vonage Client Library for PHP * * @copyright Copyright (c) 2016-2022 Vonage, Inc. (http://vonage.com) * @license https://github.com/Vonage/vonage-php-sdk-core/blob/master/LICENSE.txt Apache License 2.0 */ declare(strict_types=1); namespace Vonage\Client\Credentials; interface CredentialsInterface { public function asArray(); } Credentials/Container.php 0000644 00000003531 15107443650 0011443 0 ustar 00 <?php /** * Vonage Client Library for PHP * * @copyright Copyright (c) 2016-2022 Vonage, Inc. (http://vonage.com) * @license https://github.com/Vonage/vonage-php-sdk-core/blob/master/LICENSE.txt Apache License 2.0 */ declare(strict_types=1); namespace Vonage\Client\Credentials; use RuntimeException; use function func_get_args; use function is_array; class Container extends AbstractCredentials { protected array $types = [ Basic::class, SignatureSecret::class, Keypair::class ]; /** * @var array */ protected array $credentials; public function __construct($credentials) { if (!is_array($credentials)) { $credentials = func_get_args(); } foreach ($credentials as $credential) { $this->addCredential($credential); } } protected function addCredential(CredentialsInterface $credential): void { $type = $this->getType($credential); if (isset($this->credentials[$type])) { throw new RuntimeException('can not use more than one of a single credential type'); } $this->credentials[$type] = $credential; } protected function getType(CredentialsInterface $credential): ?string { foreach ($this->types as $type) { if ($credential instanceof $type) { return $type; } } return null; } public function get($type) { if (!isset($this->credentials[$type])) { throw new RuntimeException('credential not set'); } return $this->credentials[$type]; } public function has($type): bool { return isset($this->credentials[$type]); } public function generateJwt($claims) { return $this->credentials[Keypair::class]->generateJwt($claims); } } Credentials/Basic.php 0000644 00000001370 15107443650 0010541 0 ustar 00 <?php /** * Vonage Client Library for PHP * * @copyright Copyright (c) 2016-2022 Vonage, Inc. (http://vonage.com) * @license https://github.com/Vonage/vonage-php-sdk-core/blob/master/LICENSE.txt Apache License 2.0 */ declare(strict_types=1); namespace Vonage\Client\Credentials; /** * Class Basic * Read-only container for api key and secret. * * @property string api_key * @property string api_secret */ class Basic extends AbstractCredentials { /** * Create a credential set with an API key and secret. * * @param $key * @param $secret */ public function __construct($key, $secret) { $this->credentials['api_key'] = (string)$key; $this->credentials['api_secret'] = (string)$secret; } } Credentials/AbstractCredentials.php 0000644 00000001241 15107443650 0013436 0 ustar 00 <?php /** * Vonage Client Library for PHP * * @copyright Copyright (c) 2016-2022 Vonage, Inc. (http://vonage.com) * @license https://github.com/Vonage/vonage-php-sdk-core/blob/master/LICENSE.txt Apache License 2.0 */ declare(strict_types=1); namespace Vonage\Client\Credentials; abstract class AbstractCredentials implements CredentialsInterface { /** * @var array */ protected array $credentials = []; /** * @noinspection MagicMethodsValidityInspection */ public function __get($name) { return $this->credentials[$name]; } public function asArray(): array { return $this->credentials; } } Credentials/SignatureSecret.php 0000644 00000001270 15107443650 0012626 0 ustar 00 <?php /** * Vonage Client Library for PHP * * @copyright Copyright (c) 2016-2022 Vonage, Inc. (http://vonage.com) * @license https://github.com/Vonage/vonage-php-sdk-core/blob/master/LICENSE.txt Apache License 2.0 */ declare(strict_types=1); namespace Vonage\Client\Credentials; class SignatureSecret extends AbstractCredentials { /** * Create a credential set with an API key and signature secret. */ public function __construct($key, $signature_secret, string $method = 'md5hash') { $this->credentials['api_key'] = $key; $this->credentials['signature_secret'] = $signature_secret; $this->credentials['signature_method'] = $method; } } Credentials/Handler/HandlerInterface.php 0000644 00000000516 15107443651 0014275 0 ustar 00 <?php namespace Vonage\Client\Credentials\Handler; use Psr\Http\Message\RequestInterface; use Vonage\Client\Credentials\CredentialsInterface; interface HandlerInterface { /** * Add authentication to a request */ function __invoke(RequestInterface $request, CredentialsInterface $credentials): RequestInterface; } Credentials/Handler/AbstractHandler.php 0000644 00000001472 15107443651 0014142 0 ustar 00 <?php namespace Vonage\Client\Credentials\Handler; use Psr\Http\Message\RequestInterface; use Vonage\Client\Credentials\Container; use Vonage\Client\Credentials\CredentialsInterface; abstract class AbstractHandler implements HandlerInterface { abstract function __invoke(RequestInterface $request, CredentialsInterface $credentials): RequestInterface; protected function extract(string $class, CredentialsInterface $credentials): CredentialsInterface { if ($credentials instanceof $class) { return $credentials; } if ($credentials instanceof Container) { $creds = $credentials->get($class); if (!is_null($creds)) { return $creds; } } throw new \RuntimeException('Requested auth type not found'); } } Credentials/Handler/SignatureBodyHandler.php 0000644 00000002001 15107443651 0015143 0 ustar 00 <?php namespace Vonage\Client\Credentials\Handler; use Psr\Http\Message\RequestInterface; use Vonage\Client\Credentials\CredentialsInterface; use Vonage\Client\Credentials\SignatureSecret; use Vonage\Client\Signature; class SignatureBodyHandler extends AbstractHandler { public function __invoke(RequestInterface $request, CredentialsInterface $credentials): RequestInterface { $credentials = $this->extract(SignatureSecret::class, $credentials); $credentialsArray = $credentials->asArray(); $body = $request->getBody(); $body->rewind(); $content = $body->getContents(); $params = json_decode($content, true); $params['api_key'] = $credentialsArray['api_key']; $signature = new Signature( $params, $credentialsArray['signature_secret'], $credentialsArray['signature_method'] ); $body->rewind(); $body->write(json_encode($signature->getSignedParams())); return $request; } } Credentials/Handler/BasicHandler.php 0000644 00000001161 15107443651 0013413 0 ustar 00 <?php namespace Vonage\Client\Credentials\Handler; use Psr\Http\Message\RequestInterface; use Vonage\Client\Credentials\Basic; use Vonage\Client\Credentials\CredentialsInterface; class BasicHandler extends AbstractHandler { public function __invoke(RequestInterface $request, CredentialsInterface $credentials): RequestInterface { $credentials = $this->extract(Basic::class, $credentials); $c = $credentials->asArray(); $cx = base64_encode($c['api_key'] . ':' . $c['api_secret']); $request = $request->withHeader('Authorization', 'Basic ' . $cx); return $request; } } Credentials/Handler/TokenBodyFormHandler.php 0000644 00000001371 15107443651 0015117 0 ustar 00 <?php namespace Vonage\Client\Credentials\Handler; use Vonage\Client\Credentials\Basic; use Psr\Http\Message\RequestInterface; use Vonage\Client\Credentials\CredentialsInterface; class TokenBodyFormHandler extends AbstractHandler { public function __invoke(RequestInterface $request, CredentialsInterface $credentials): RequestInterface { $credentials = $this->extract(Basic::class, $credentials); $body = $request->getBody(); $body->rewind(); $content = $body->getContents(); $params = []; parse_str($content, $params); $params = array_merge($params, $credentials->asArray()); $body->rewind(); $body->write(http_build_query($params, '', '&')); return $request; } } Credentials/Handler/SignatureBodyFormHandler.php 0000644 00000002073 15107443651 0016000 0 ustar 00 <?php namespace Vonage\Client\Credentials\Handler; use Psr\Http\Message\RequestInterface; use Vonage\Client\Credentials\CredentialsInterface; use Vonage\Client\Credentials\SignatureSecret; use Vonage\Client\Signature; class SignatureBodyFormHandler extends AbstractHandler { public function __invoke(RequestInterface $request, CredentialsInterface $credentials): RequestInterface { $credentials = $this->extract(SignatureSecret::class, $credentials); $credentialsArray = $credentials->asArray(); $body = $request->getBody(); $body->rewind(); $content = $body->getContents(); $params = []; parse_str($content, $params); $params['api_key'] = $credentialsArray['api_key']; $signature = new Signature( $params, $credentialsArray['signature_secret'], $credentialsArray['signature_method'] ); $params = $signature->getSignedParams(); $body->rewind(); $body->write(http_build_query($params, '', '&')); return $request; } } Credentials/Handler/TokenQueryHandler.php 0000644 00000001256 15107443651 0014505 0 ustar 00 <?php namespace Vonage\Client\Credentials\Handler; use Vonage\Client\Credentials\Basic; use Psr\Http\Message\RequestInterface; use Vonage\Client\Credentials\CredentialsInterface; class TokenQueryHandler extends AbstractHandler { public function __invoke(RequestInterface $request, CredentialsInterface $credentials): RequestInterface { $credentials = $this->extract(Basic::class, $credentials); $query = []; parse_str($request->getUri()->getQuery(), $query); $query = array_merge($query, $credentials->asArray()); $request = $request->withUri($request->getUri()->withQuery(http_build_query($query))); return $request; } } Credentials/Handler/SignatureQueryHandler.php 0000644 00000001715 15107443652 0015367 0 ustar 00 <?php namespace Vonage\Client\Credentials\Handler; use Psr\Http\Message\RequestInterface; use Vonage\Client\Credentials\CredentialsInterface; use Vonage\Client\Credentials\SignatureSecret; use Vonage\Client\Signature; class SignatureQueryHandler extends AbstractHandler { public function __invoke(RequestInterface $request, CredentialsInterface $credentials): RequestInterface { $credentials = $this->extract(SignatureSecret::class, $credentials); $credentialsArray = $credentials->asArray(); $query = []; parse_str($request->getUri()->getQuery(), $query); $query['api_key'] = $credentialsArray['api_key']; $signature = new Signature( $query, $credentialsArray['signature_secret'], $credentialsArray['signature_method'] ); return $request->withUri( $request->getUri()->withQuery(http_build_query($signature->getSignedParams())) ); } } Credentials/Handler/KeypairHandler.php 0000644 00000001125 15107443652 0013777 0 ustar 00 <?php namespace Vonage\Client\Credentials\Handler; use Psr\Http\Message\RequestInterface; use Vonage\Client\Credentials\CredentialsInterface; use Vonage\Client\Credentials\Keypair; class KeypairHandler extends AbstractHandler { public function __invoke(RequestInterface $request, CredentialsInterface $credentials): RequestInterface { /** @var Keypair $credentials */ $credentials = $this->extract(Keypair::class, $credentials); $token = $credentials->generateJwt(); return $request->withHeader('Authorization', 'Bearer ' . $token->toString()); } } Credentials/Handler/TokenBodyHandler.php 0000644 00000001744 15107443652 0014300 0 ustar 00 <?php namespace Vonage\Client\Credentials\Handler; use Vonage\Client\Credentials\Basic; use Psr\Http\Message\RequestInterface; use Vonage\Client\Credentials\CredentialsInterface; class TokenBodyHandler extends AbstractHandler { public function __invoke(RequestInterface $request, CredentialsInterface $credentials): RequestInterface { $credentials = $this->extract(Basic::class, $credentials); // We have to do some clunky body pointer rewinding here $existingBody = $request->getBody(); $existingBody->rewind(); $existingBodyContent = $existingBody->getContents(); $existingBody->rewind(); $existingBodyArray = json_decode($existingBodyContent, true); // The request body will now be the existing body plus the basic creds $mergedBodyArray = array_merge($existingBodyArray, $credentials->asArray()); return $request->withBody(\GuzzleHttp\Psr7\Utils::streamFor(json_encode($mergedBodyArray))); } } Credentials/Handler/BasicQueryHandler.php 0000644 00000001173 15107443652 0014445 0 ustar 00 <?php namespace Vonage\Client\Credentials\Handler; use Psr\Http\Message\RequestInterface; use Vonage\Client\Credentials\Basic; use Vonage\Client\Credentials\CredentialsInterface; class BasicQueryHandler extends AbstractHandler { public function __invoke(RequestInterface $request, CredentialsInterface $credentials): RequestInterface { $credentials = $this->extract(Basic::class, $credentials); parse_str($request->getUri()->getQuery(), $query); $query = array_merge($query, $credentials->asArray()); return $request->withUri($request->getUri()->withQuery(http_build_query($query))); } } Credentials/Keypair.php 0000644 00000005274 15107443652 0011135 0 ustar 00 <?php /** * Vonage Client Library for PHP * * @copyright Copyright (c) 2016-2022 Vonage, Inc. (http://vonage.com) * @license https://github.com/Vonage/vonage-php-sdk-core/blob/master/LICENSE.txt Apache License 2.0 */ declare(strict_types=1); namespace Vonage\Client\Credentials; use Lcobucci\JWT\Configuration; use Lcobucci\JWT\Signer\Key; use Lcobucci\JWT\Signer\Key\InMemory; use Lcobucci\JWT\Signer\Rsa\Sha256; use Lcobucci\JWT\Token; use Vonage\Application\Application; use function base64_encode; use function mt_rand; use function time; /** * @property mixed application */ class Keypair extends AbstractCredentials { /** * @var Key */ protected $key; public function __construct($privateKey, $application = null) { $this->credentials['key'] = $privateKey; if ($application) { if ($application instanceof Application) { $application = $application->getId(); } $this->credentials['application'] = $application; } $this->key = InMemory::plainText($privateKey); } /** * @return Key */ public function getKey(): Key { return $this->key; } public function generateJwt(array $claims = []): Token { $config = Configuration::forSymmetricSigner(new Sha256(), $this->key); $exp = time() + 60; $iat = time(); $jti = base64_encode((string)mt_rand()); if (isset($claims['exp'])) { $exp = $claims['exp']; unset($claims['exp']); } if (isset($claims['iat'])) { $iat = $claims['iat']; unset($claims['iat']); } if (isset($claims['jti'])) { $jti = $claims['jti']; unset($claims['jti']); } $builder = $config->builder(); $builder->issuedAt((new \DateTimeImmutable())->setTimestamp($iat)) ->expiresAt((new \DateTimeImmutable())->setTimestamp($exp)) ->identifiedBy($jti); if (isset($claims['nbf'])) { $builder->canOnlyBeUsedAfter((new \DateTimeImmutable())->setTimestamp($claims['nbf'])); unset($claims['nbf']); } if (isset($this->credentials['application'])) { $builder->withClaim('application_id', $this->credentials['application']); } if (isset($claims['sub'])) { $builder->relatedTo($claims['sub']); unset($claims['sub']); } if (!empty($claims)) { foreach ($claims as $claim => $value) { $builder->withClaim($claim, $value); } } return $builder->getToken($config->signer(), $config->signingKey()); } } ClientAwareTrait.php 0000644 00000001320 15107443652 0010462 0 ustar 00 <?php /** * Vonage Client Library for PHP * * @copyright Copyright (c) 2016-2022 Vonage, Inc. (http://vonage.com) * @license https://github.com/Vonage/vonage-php-sdk-core/blob/master/LICENSE.txt Apache License 2.0 */ declare(strict_types=1); namespace Vonage\Client; use RuntimeException; use Vonage\Client; trait ClientAwareTrait { /** * @var Client */ protected $client; public function setClient(Client $client): self { $this->client = $client; return $this; } public function getClient(): ?Client { if (isset($this->client)) { return $this->client; } throw new RuntimeException('Vonage\Client not set'); } } Callback/Callback.php 0000644 00000003011 15107443652 0010447 0 ustar 00 <?php /** * Vonage Client Library for PHP * * @copyright Copyright (c) 2016-2022 Vonage, Inc. (http://vonage.com) * @license https://github.com/Vonage/vonage-php-sdk-core/blob/master/LICENSE.txt Apache License 2.0 */ declare(strict_types=1); namespace Vonage\Client\Callback; use InvalidArgumentException; use RuntimeException; use function array_diff; use function array_keys; use function array_merge; use function implode; use function strtolower; class Callback implements CallbackInterface { public const ENV_ALL = 'all'; public const ENV_POST = 'post'; public const ENV_GET = 'get'; /** * @var array */ protected $expected = []; /** * @var array */ protected $data; public function __construct(array $data) { $keys = array_keys($data); $missing = array_diff($this->expected, $keys); if ($missing) { throw new RuntimeException('missing expected callback keys: ' . implode(', ', $missing)); } $this->data = $data; } public function getData(): array { return $this->data; } /** * @return Callback|callable */ public static function fromEnv(string $source = self::ENV_ALL) { $data = match (strtolower($source)) { 'post' => $_POST, 'get' => $_GET, 'all' => array_merge($_GET, $_POST), default => throw new InvalidArgumentException('invalid source: ' . $source), }; return new static($data); } } Callback/CallbackInterface.php 0000644 00000000534 15107443652 0012277 0 ustar 00 <?php /** * Vonage Client Library for PHP * * @copyright Copyright (c) 2016-2022 Vonage, Inc. (http://vonage.com) * @license https://github.com/Vonage/vonage-php-sdk-core/blob/master/LICENSE.txt Apache License 2.0 */ declare(strict_types=1); namespace Vonage\Client\Callback; interface CallbackInterface { public function getData(); } ClientAwareInterface.php 0000644 00000000572 15107443653 0011310 0 ustar 00 <?php /** * Vonage Client Library for PHP * * @copyright Copyright (c) 2016-2022 Vonage, Inc. (http://vonage.com) * @license https://github.com/Vonage/vonage-php-sdk-core/blob/master/LICENSE.txt Apache License 2.0 */ declare(strict_types=1); namespace Vonage\Client; use Vonage\Client; interface ClientAwareInterface { public function setClient(Client $client); } APIClient.php 0000644 00000000537 15107443653 0007042 0 ustar 00 <?php /** * Vonage Client Library for PHP * * @copyright Copyright (c) 2016-2022 Vonage, Inc. (http://vonage.com) * @license https://github.com/Vonage/vonage-php-sdk-core/blob/master/LICENSE.txt Apache License 2.0 */ declare(strict_types=1); namespace Vonage\Client; interface APIClient { public function getAPIResource(): APIResource; } Factory/FactoryInterface.php 0000644 00000001165 15107443653 0012127 0 ustar 00 <?php /** * Vonage Client Library for PHP * * @copyright Copyright (c) 2016-2022 Vonage, Inc. (http://vonage.com) * @license https://github.com/Vonage/vonage-php-sdk-core/blob/master/LICENSE.txt Apache License 2.0 */ declare(strict_types=1); namespace Vonage\Client\Factory; /** * Interface FactoryInterface * * Factor create API clients (clients specific to single API, that leverages Vonage\Client for HTTP communication and * common functionality). */ interface FactoryInterface { public function hasApi(string $api): bool; public function getApi(string $api); public function make(string $key); } Factory/MapFactory.php 0000644 00000005461 15107443653 0010747 0 ustar 00 <?php /** * Vonage Client Library for PHP * * @copyright Copyright (c) 2016-2022 Vonage, Inc. (http://vonage.com) * @license https://github.com/Vonage/vonage-php-sdk-core/blob/master/LICENSE.txt Apache License 2.0 */ declare(strict_types=1); namespace Vonage\Client\Factory; use Psr\Container\ContainerInterface; use Psr\Log\LoggerInterface; use RuntimeException; use Vonage\Client; use Vonage\Logger\LoggerAwareInterface; use function is_callable; use function sprintf; class MapFactory implements FactoryInterface, ContainerInterface { /** * Map of instances. * * @var array */ protected $cache = []; /** * @param mixed[] $map */ public function __construct( /** * Map of api namespaces to classes. */ protected $map, /** * Vonage Client */ protected Client $client ) { } /** * @param string $id * * @noinspection PhpMissingParamTypeInspection */ public function has($id): bool { return isset($this->map[$id]); } /** * @deprecated Use has() instead */ public function hasApi(string $api): bool { return $this->has($api); } /** * @param string $id * * @noinspection PhpMissingParamTypeInspection */ public function get($id) { if (isset($this->cache[$id])) { return $this->cache[$id]; } $instance = $this->make($id); $this->cache[$id] = $instance; return $instance; } public function getClient(): Client { return $this->client; } /** * @deprecated Use get() instead */ public function getApi(string $api) { return $this->get($api); } public function make($key) { if (!$this->has($key)) { throw new RuntimeException( sprintf( 'no map defined for `%s`', $key ) ); } if (is_callable($this->map[$key])) { $instance = $this->map[$key]($this); } else { $class = $this->map[$key]; $instance = new $class(); if (is_callable($instance)) { $instance = $instance($this); } } if ($instance instanceof Client\ClientAwareInterface) { $instance->setClient($this->client); } if ($instance instanceof LoggerAwareInterface && $this->has(LoggerInterface::class)) { $instance->setLogger($this->get(LoggerInterface::class)); } return $instance; } public function set($key, $value): void { $this->map[$key] = $value; if (!is_callable($value)) { $this->cache[$key] = $value; } } } Response/Error.php 0000644 00000001653 15107443653 0010161 0 ustar 00 <?php /** * Vonage Client Library for PHP * * @copyright Copyright (c) 2016-2022 Vonage, Inc. (http://vonage.com) * @license https://github.com/Vonage/vonage-php-sdk-core/blob/master/LICENSE.txt Apache License 2.0 */ declare(strict_types=1); namespace Vonage\Client\Response; class Error extends Response { public function __construct(array $data) { //normalize the data if (isset($data['error_text'])) { $data['error-text'] = $data['error_text']; } $this->expected = ['status', 'error-text']; parent::__construct($data); } public function isError(): bool { return true; } public function isSuccess(): bool { return false; } public function getCode(): int { return (int)$this->data['status']; } public function getMessage(): string { return (string)$this->data['error-text']; } } Response/AbstractResponse.php 0000644 00000001274 15107443653 0012351 0 ustar 00 <?php /** * Vonage Client Library for PHP * * @copyright Copyright (c) 2016-2022 Vonage, Inc. (http://vonage.com) * @license https://github.com/Vonage/vonage-php-sdk-core/blob/master/LICENSE.txt Apache License 2.0 */ declare(strict_types=1); namespace Vonage\Client\Response; abstract class AbstractResponse implements ResponseInterface { /** * @var array */ protected $data; public function getData(): array { return $this->data; } public function isSuccess(): bool { return isset($this->data['status']) && (int)$this->data['status'] === 0; } public function isError(): bool { return !$this->isSuccess(); } } Response/ResponseInterface.php 0000644 00000000661 15107443653 0012505 0 ustar 00 <?php /** * Vonage Client Library for PHP * * @copyright Copyright (c) 2016-2022 Vonage, Inc. (http://vonage.com) * @license https://github.com/Vonage/vonage-php-sdk-core/blob/master/LICENSE.txt Apache License 2.0 */ declare(strict_types=1); namespace Vonage\Client\Response; interface ResponseInterface { public function getData(): array; public function isError(): bool; public function isSuccess(): bool; } Response/Response.php 0000644 00000001561 15107443653 0010664 0 ustar 00 <?php /** * Vonage Client Library for PHP * * @copyright Copyright (c) 2016-2022 Vonage, Inc. (http://vonage.com) * @license https://github.com/Vonage/vonage-php-sdk-core/blob/master/LICENSE.txt Apache License 2.0 */ declare(strict_types=1); namespace Vonage\Client\Response; use RuntimeException; use function array_diff; use function array_keys; use function implode; class Response extends AbstractResponse { /** * Allow specific responses to easily define required parameters. * * @var array */ protected $expected = []; public function __construct(array $data) { $keys = array_keys($data); $missing = array_diff($this->expected, $keys); if ($missing) { throw new RuntimeException('missing expected response keys: ' . implode(', ', $missing)); } $this->data = $data; } } Request/AbstractRequest.php 0000644 00000001042 15107443654 0012027 0 ustar 00 <?php /** * Vonage Client Library for PHP * * @copyright Copyright (c) 2016-2022 Vonage, Inc. (http://vonage.com) * @license https://github.com/Vonage/vonage-php-sdk-core/blob/master/LICENSE.txt Apache License 2.0 */ declare(strict_types=1); namespace Vonage\Client\Request; use function array_filter; abstract class AbstractRequest implements RequestInterface { /** * @var array */ protected $params = []; public function getParams(): array { return array_filter($this->params, 'is_scalar'); } } Request/RequestInterface.php 0000644 00000000613 15107443654 0012167 0 ustar 00 <?php /** * Vonage Client Library for PHP * * @copyright Copyright (c) 2016-2022 Vonage, Inc. (http://vonage.com) * @license https://github.com/Vonage/vonage-php-sdk-core/blob/master/LICENSE.txt Apache License 2.0 */ declare(strict_types=1); namespace Vonage\Client\Request; interface RequestInterface { public function getParams(): array; public function getURI(): string; } Request/WrapResponseInterface.php 0000644 00000000701 15107443654 0013165 0 ustar 00 <?php /** * Vonage Client Library for PHP * * @copyright Copyright (c) 2016-2022 Vonage, Inc. (http://vonage.com) * @license https://github.com/Vonage/vonage-php-sdk-core/blob/master/LICENSE.txt Apache License 2.0 */ declare(strict_types=1); namespace Vonage\Client\Request; use Vonage\Client\Response\ResponseInterface; interface WrapResponseInterface { public function wrapResponse(ResponseInterface $response): ResponseInterface; } APIExceptionHandler.php 0000644 00000005213 15107443654 0011055 0 ustar 00 <?php /** * Vonage Client Library for PHP * * @copyright Copyright (c) 2016-2022 Vonage, Inc. (http://vonage.com) * @license https://github.com/Vonage/vonage-php-sdk-core/blob/master/LICENSE.txt Apache License 2.0 */ declare(strict_types=1); namespace Vonage\Client; use Psr\Http\Message\RequestInterface; use Psr\Http\Message\ResponseInterface; use function is_string; use function json_decode; use function sprintf; class APIExceptionHandler { /** * Format to use for the rfc7807 formatted errors * * @var string */ protected $rfc7807Format = "%s: %s. See %s for more information"; public function setRfc7807Format(string $format): void { $this->rfc7807Format = $format; } /** * @throws Exception\Exception * * @return Exception\Request|Exception\Server */ public function __invoke(ResponseInterface $response, RequestInterface $request) { $body = json_decode($response->getBody()->getContents(), true); $response->getBody()->rewind(); $status = (int)$response->getStatusCode(); // Error responses aren't consistent. Some are generated within the // proxy and some are generated within voice itself. This handles // both cases // This message isn't very useful, but we shouldn't ever see it $errorTitle = 'Unexpected error'; if (isset($body['title'])) { // Have to do this check to handle VAPI errors if (isset($body['type']) && is_string($body['type'])) { $errorTitle = sprintf( $this->rfc7807Format, $body['title'], $body['detail'], $body['type'] ); } else { $errorTitle = $body['title']; } } if (isset($body['error_title'])) { $errorTitle = $body['error_title']; } if (isset($body['error-code-label'])) { $errorTitle = $body['error-code-label']; } if (isset($body['description'])) { $errorTitle = $body['description']; } if ($status >= 400 && $status < 500) { $e = new Exception\Request($errorTitle, $status); @$e->setRequest($request); @$e->setResponse($response); } elseif ($status >= 500 && $status < 600) { $e = new Exception\Server($errorTitle, $status); @$e->setRequest($request); @$e->setResponse($response); } else { $e = new Exception\Exception('Unexpected HTTP Status Code'); throw $e; } return $e; } }