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
/
Edit File:
Entity.tar
CollectionAwareInterface.php 0000644 00000000673 15107447160 0012164 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\Entity; interface CollectionAwareInterface { public function setCollection(CollectionInterface $collection); public function getCollection(): CollectionInterface; } CollectionInterface.php 0000644 00000001130 15107447160 0011171 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\Entity; use Countable; use Iterator; interface CollectionInterface extends Countable, Iterator { public static function getCollectionName(): string; public static function getCollectionPath(): string; /** * @param $data * @param $idOrEntity */ public function hydrateEntity($data, $idOrEntity); } Filter/DateFilter.php 0000644 00000001712 15107447160 0010533 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\Entity\Filter; use DateTime; /** * Simple value object for application filtering. */ class DateFilter implements FilterInterface { public const FORMAT = 'Y:m:d:H:i:s'; protected $start; protected $end; public function __construct(DateTime $start, DateTime $end) { if ($start < $end) { $this->start = $start; $this->end = $end; } else { $this->start = $end; $this->end = $start; } } /** * @return string[] */ public function getQuery(): array { return [ 'date' => $this->start->format(self::FORMAT) . '-' . $this->end->format(self::FORMAT) ]; } } Filter/KeyValueFilter.php 0000644 00000001170 15107447160 0011401 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\Entity\Filter; /** * A very simple key-value filter that can be used when less magic is needed */ class KeyValueFilter implements FilterInterface { /** * @param array<string, string> $query */ public function __construct(protected array $query = []) { } public function getQuery(): array { return $this->query; } } Filter/FilterInterface.php 0000644 00000000531 15107447160 0011554 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\Entity\Filter; interface FilterInterface { public function getQuery(); } Filter/EmptyFilter.php 0000644 00000000622 15107447160 0010753 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\Entity\Filter; class EmptyFilter implements FilterInterface { public function getQuery(): array { return []; } } Hydrator/ArrayHydrator.php 0000644 00000001565 15107447160 0011660 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\Entity\Hydrator; class ArrayHydrator implements HydratorInterface { /** * @var ArrayHydrateInterface */ protected $prototype; public function hydrate(array $data): ArrayHydrateInterface { $object = clone $this->prototype; $object->fromArray($data); return $object; } /** * @param $object */ public function hydrateObject(array $data, $object) { $object->fromArray($data); return $object; } public function setPrototype(ArrayHydrateInterface $prototype): void { $this->prototype = $prototype; } } Hydrator/ConstructorHydrator.php 0000644 00000001553 15107447160 0013124 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\Entity\Hydrator; class ConstructorHydrator implements HydratorInterface { /** * Class to create * @var string */ protected $prototype; public function hydrate(array $data) { $className = $this->prototype; return new $className($data); } /** * @param $object */ public function hydrateObject(array $data, $object) { throw new \RuntimeException('Constructor Hydration can not happen on an existing object'); } public function setPrototype(string $prototype): void { $this->prototype = $prototype; } } Hydrator/ArrayHydrateInterface.php 0000644 00000001356 15107447160 0013303 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\Entity\Hydrator; /** * Interface for allowing an entity to be converted to/from an array * While the built-in `JsonSerializable` interface is nice, it's not * always semantically correct. This provides a much more clear set * of functions for handling this. Ideally, if an entity also * implements `JsonSerializable`, those functions can just wrap these */ interface ArrayHydrateInterface { public function fromArray(array $data); public function toArray(): array; } Hydrator/HydratorInterface.php 0000644 00000001123 15107447160 0012470 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\Entity\Hydrator; interface HydratorInterface { /** * Hydrate an object that the hydrator creates */ public function hydrate(array $data); /** * Hydrate an existing object created outside of the hydrator * * @param $object */ public function hydrateObject(array $data, $object); } Psr7Trait.php 0000644 00000005605 15107447160 0007127 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\Entity; use Psr\Http\Message\RequestInterface; use Psr\Http\Message\ResponseInterface; use Vonage\Entity\Hydrator\ArrayHydrateInterface; use function array_merge; use function get_class; use function is_array; use function json_decode; use function method_exists; use function parse_str; use function trigger_error; /** * Class Psr7Trait * * Allow an entity to contain last request / response objects. */ trait Psr7Trait { /** * @var RequestInterface */ protected $request; /** * @var ResponseInterface */ protected $response; public function setResponse(ResponseInterface $response): void { trigger_error( $this::class . '::setResponse() is deprecated and will be removed', E_USER_DEPRECATED ); $this->response = $response; $status = (int)$response->getStatusCode(); if ($this instanceof ArrayHydrateInterface && (200 === $status || 201 === $status)) { $this->fromArray($this->getResponseData()); } } public function setRequest(RequestInterface $request): void { trigger_error( $this::class . '::setRequest is deprecated and will be removed', E_USER_DEPRECATED ); $this->request = $request; $this->data = []; if (method_exists($request, 'getQueryParams')) { $this->data = $request->getQueryParams(); } $contentType = $request->getHeader('Content-Type'); if (!empty($contentType)) { if ($contentType[0] === 'application/json') { $body = json_decode($request->getBody()->getContents(), true); if (is_array($body)) { $this->data = array_merge( $this->data, $body ); } } } else { parse_str($request->getBody()->getContents(), $body); $this->data = array_merge($this->data, $body); } } public function getRequest(): ?RequestInterface { trigger_error( $this::class . '::getRequest() is deprecated. ' . 'Please get the APIResource from the appropriate client to get this information', E_USER_DEPRECATED ); return $this->request; } public function getResponse(): ?ResponseInterface { trigger_error( $this::class . '::getResponse() is deprecated. ' . 'Please get the APIResource from the appropriate client to get this information', E_USER_DEPRECATED ); return $this->response; } } JsonResponseTrait.php 0000644 00000002525 15107447160 0010722 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\Entity; use Exception; use Psr\Http\Message\ResponseInterface; use RuntimeException; use function json_decode; use function sprintf; /** * @deprecated This data will be better exposed at the model level */ trait JsonResponseTrait { protected $responseJson; /** * @throws Exception * * @return array|mixed */ public function getResponseData() { if (!($this instanceof EntityInterface)) { throw new RuntimeException( sprintf( '%s can only be used if the class implements %s', __TRAIT__, EntityInterface::class ) ); } if (($response = @$this->getResponse()) && ($response instanceof ResponseInterface)) { if ($response->getBody()->isSeekable()) { $response->getBody()->rewind(); } $body = $response->getBody()->getContents(); $this->responseJson = json_decode($body, true); return $this->responseJson; } return []; } } JsonSerializableInterface.php 0000644 00000000700 15107447160 0012340 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\Entity; use JsonSerializable; /** * Identifies the Entity as using JsonSerializable to prepare request data. */ interface JsonSerializableInterface extends JsonSerializable { } JsonUnserializableInterface.php 0000644 00000001304 15107447160 0012704 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\Entity; /** * Identifies the Entity as using JsonSerializable to prepare request data. * * @deprecated Please use a more appropriate hydrator, like ArrayHydrator */ interface JsonUnserializableInterface { /** * Update the object state with the json data (as an array) * * @deprecated Implement ArrayHydrator instead as it is more semantically correct */ public function jsonUnserialize(array $json): void; } ArrayAccessTrait.php 0000644 00000000617 15107447160 0010472 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\Entity; trait ArrayAccessTrait { abstract public function getResponseData(); abstract public function getRequestData(); } ModernCollectionTrait.php 0000644 00000001716 15107447160 0011533 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\Entity; use RuntimeException; /** * Common code for iterating over a collection, and using the collection class to discover the API path. */ trait ModernCollectionTrait { use CollectionTrait; /** * Count of total items */ public function count(): int { if (isset($this->page)) { return (int)$this->page['total_items']; } return 0; } /** * @return int|mixed */ public function getPage() { if (isset($this->page)) { return $this->page['page']; } if (isset($this->index)) { return $this->index; } throw new RuntimeException('page not set'); } } HasEntityTrait.php 0000644 00000001020 15107447160 0010167 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\Entity; trait HasEntityTrait { protected $entity; /** * @param $entity */ public function setEntity($entity): void { $this->entity = $entity; } public function getEntity() { return $this->entity; } } IterableAPICollection.php 0000644 00000037725 15107447160 0011375 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\Entity; use Countable; use Iterator; use Laminas\Diactoros\Request; use Psr\Http\Client\ClientExceptionInterface; use Psr\Http\Message\ResponseInterface; use RuntimeException; use Vonage\Client; use Vonage\Client\APIResource; use Vonage\Client\ClientAwareInterface; use Vonage\Client\ClientAwareTrait; use Vonage\Client\Exception as ClientException; use Vonage\Entity\Filter\EmptyFilter; use Vonage\Entity\Filter\FilterInterface; use function array_key_exists; use function array_merge; use function count; use function filter_var; use function http_build_query; use function is_null; use function json_decode; use function md5; use function strpos; /** * Common code for iterating over a collection, and using the collection class to discover the API path. */ class IterableAPICollection implements ClientAwareInterface, Iterator, Countable { use ClientAwareTrait; protected APIResource $api; /** * This allows for override if the endpoint API uses a different query key */ protected string $pageIndexKey = 'page_index'; /** * This allows for override if the endpoint API uses a different query key */ protected string $pageSizeKey = 'page_size'; /** * Determines if the collection will automatically go to the next page */ protected bool $autoAdvance = true; protected string $baseUrl = Client::BASE_API; /** * Holds a cache of various pages we have already polled * * @var array<string, string> */ protected array $cache = []; /** * Index of the current resource of the current page */ protected int $current = 0; /** * Count the items in the response instead of returning the count parameter * * @deprected This exists for legacy reasons, will be removed in v3 * * @var bool */ protected bool $naiveCount = false; /** * Current page data. */ protected ?array $pageData = null; /** * Last API Response */ protected ?ResponseInterface $response = null; /** * User set page index. */ protected ?int $index = 1; protected bool $isHAL = true; /** * Used to override the index, this is to hack inconsistent API behaviours */ protected bool $noIndex = false; /** * Used if there are HAL elements, but entities are all in one request * Specifically removes automatic pagination that adds request parameters */ protected bool $noQueryParameters = false; /** * User set pgge size. */ protected ?int $size = null; protected ?FilterInterface $filter = null; protected string $collectionName = ''; protected string $collectionPath = ''; protected $hydrator; /** * Used to override pagination to remove it from the URL page query * but differs from noQueryParameters when you want to use other filters */ protected bool $hasPagination = true; public function getPageIndexKey(): string { return $this->pageIndexKey; } public function setPageIndexKey(string $pageIndexKey): IterableAPICollection { $this->pageIndexKey = $pageIndexKey; return $this; } public function getPageSizeKey(): string { return $this->pageSizeKey; } public function setPageSizeKey(string $pageSizeKey): IterableAPICollection { $this->pageSizeKey = $pageSizeKey; return $this; } /** * @param $hydrator * * @return $this */ public function setHydrator($hydrator): self { $this->hydrator = $hydrator; return $this; } /** * @param $data * @param $id deprecated */ public function hydrateEntity($data, $id = null) { if ($this->hydrator) { return $this->hydrator->hydrate($data); } return $data; } public function getResourceRoot(): array { // Handles issues where an API returns empty for no results, as opposed // to a proper API response with a count field of 0 if (empty($this->pageData)) { return []; } $collectionName = $this->getApiResource()->getCollectionName(); if ($this->getApiResource()->isHAL()) { return $this->pageData['_embedded'][$collectionName]; } if (!empty($this->getApiResource()->getCollectionName())) { return $this->pageData[$collectionName]; } return $this->pageData; } /** * Return the current item, expects concrete collection to handle creating the object. * * @throws ClientExceptionInterface * @throws ClientException\Exception * @throws ClientException\Request * @throws ClientException\Server */ #[\ReturnTypeWillChange] public function current() { if (is_null($this->current)) { $this->rewind(); } return $this->hydrateEntity($this->getResourceRoot()[$this->current], $this->key()); } /** * No checks here, just advance the index. */ public function next(): void { $this->current++; } /** * Return the ID of the resource, in some cases this is `id`, in others `uuid`. * * @return string */ #[\ReturnTypeWillChange] public function key() { return $this->getResourceRoot()[$this->current]['id'] ?? $this->getResourceRoot()[$this->current]['uuid'] ?? $this->current; } /** * Handle pagination automatically (unless configured not to). * * @throws ClientExceptionInterface * @throws ClientException\Exception * @throws ClientException\Request * @throws ClientException\Server */ public function valid(): bool { //can't be valid if there's not a page (rewind sets this) if (!isset($this->pageData)) { return false; } //all hal collections have an `_embedded` object, we expect there to be a property matching the collection name if ( $this->getApiResource()->isHAL() && !isset($this->pageData['_embedded'][$this->getApiResource()->getCollectionName()]) ) { return false; } //if we have a page with no items, we've gone beyond the end of the collection if (!count($this->getResourceRoot())) { return false; } // If there is no item at the current counter, we've gone beyond the end of this page if (!$this->getAutoAdvance() && !isset($this->getResourceRoot()[$this->current])) { return false; } //index the start of a page at 0 if (is_null($this->current)) { $this->current = 0; } //if our current index is past the current page, fetch the next page if possible and reset the index if ($this->getAutoAdvance() && !isset($this->getResourceRoot()[$this->current])) { if (isset($this->pageData['_links'])) { if (isset($this->pageData['_links']['next'])) { $this->fetchPage($this->pageData['_links']['next']['href']); $this->current = 0; return true; } // We don't have a next page, so we're done return false; } if ($this->current === count($this->getResourceRoot())) { $this->index++; $this->current = 0; $this->fetchPage($this->getApiResource()->getBaseUri()); return !($this->count() === 0); } return false; } return true; } /** * Fetch the initial page * * @throws ClientExceptionInterface * @throws ClientException\Exception * @throws ClientException\Request * @throws ClientException\Server */ public function rewind(): void { $this->current = 0; $this->fetchPage($this->getApiResource()->getBaseUri()); } /** * @return $this */ public function setApiResource(APIResource $api): self { $this->api = $api; return $this; } public function getApiResource(): APIResource { return $this->api; } /** * Count of total items * * @throws ClientExceptionInterface * @throws ClientException\Exception * @throws ClientException\Request * @throws ClientException\Server */ public function count(): int { if (!isset($this->pageData)) { $this->rewind(); } if (isset($this->pageData)) { // Force counting the items for legacy reasons if ($this->getNaiveCount()) { return count($this->getResourceRoot()); } if (array_key_exists('total_items', $this->pageData)) { return $this->pageData['total_items']; } if (array_key_exists('count', $this->pageData)) { return $this->pageData['count']; } return count($this->getResourceRoot()); } return 0; } /** * @return $this */ public function setBaseUrl(string $url): self { $this->baseUrl = $url; return $this; } /** * @param $index * * @return $this */ public function setPage($index): self { $this->index = (int)$index; return $this; } /** * @return int|mixed */ public function getPage() { if (isset($this->pageData)) { if (array_key_exists('page', $this->pageData)) { return $this->pageData['page']; } return $this->pageData['page_index']; } if (isset($this->index)) { return $this->index; } throw new RuntimeException('page not set'); } /** * @throws ClientExceptionInterface * @throws ClientException\Exception * @throws ClientException\Request * @throws ClientException\Server */ public function getPageData(): ?array { if (is_null($this->pageData)) { $this->rewind(); } return $this->pageData; } public function setPageData(array $data): void { $this->pageData = $data; } /** * @return int|mixed|void */ public function getSize() { if (isset($this->pageData)) { if (array_key_exists('page_size', $this->pageData)) { return $this->pageData['page_size']; } return count($this->getResourceRoot()); } if (isset($this->size)) { return $this->size; } throw new RuntimeException('size not set'); } /** * @param $size * * @return $this */ public function setSize($size): self { $this->size = (int)$size; return $this; } /** * Filters reduce to query params and include paging settings. * * @return $this */ public function setFilter(FilterInterface $filter): self { $this->filter = $filter; return $this; } public function getFilter(): FilterInterface { if (!isset($this->filter)) { $this->setFilter(new EmptyFilter()); } return $this->filter; } /** * Fetch a page using the current filter if no query is provided. * * @param $absoluteUri * * @throws ClientException\Exception * @throws ClientException\Request * @throws ClientException\Server * @throws ClientExceptionInterface */ protected function fetchPage($absoluteUri): void { //use filter if no query provided if (false === strpos($absoluteUri, '?')) { $originalUri = $absoluteUri; $query = []; if (isset($this->size)) { $query[$this->pageSizeKey] = $this->size; } if (isset($this->index) && $this->hasPagination()) { $query[$this->pageIndexKey] = $this->index; } if (isset($this->filter)) { $query = array_merge($this->filter->getQuery(), $query); } $absoluteUri .= '?' . http_build_query($query); // This is an override to completely remove request parameters for single requests if ($this->getNoQueryParameters()) { $absoluteUri = $originalUri; } } $requestUri = $absoluteUri; if (filter_var($absoluteUri, FILTER_VALIDATE_URL) === false) { $requestUri = $this->getApiResource()->getBaseUrl() . $absoluteUri; } $cacheKey = md5($requestUri); if (array_key_exists($cacheKey, $this->cache)) { $this->pageData = $this->cache[$cacheKey]; return; } $request = new Request($requestUri, 'GET'); if ($this->getApiResource()->getAuthHandler()) { $request = $this->getApiResource()->addAuth($request); } $response = $this->client->send($request); $this->getApiResource()->setLastRequest($request); $this->response = $response; $this->getApiResource()->setLastResponse($response); $body = $this->response->getBody()->getContents(); $json = json_decode($body, true); $this->cache[md5($requestUri)] = $json; $this->pageData = $json; if ((int)$response->getStatusCode() !== 200) { throw $this->getException($response); } } /** * @throws ClientException\Exception * * @return ClientException\Request|ClientException\Server */ protected function getException(ResponseInterface $response) { $response->getBody()->rewind(); $body = json_decode($response->getBody()->getContents(), true); $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 = $body['error-code-label'] ?? $body['error_title'] ?? $body['title'] ?? 'Unexpected error'; if ($status >= 400 && $status < 500) { $e = new ClientException\Request($errorTitle, $status); } elseif ($status >= 500 && $status < 600) { $e = new ClientException\Server($errorTitle, $status); } else { $e = new ClientException\Exception('Unexpected HTTP Status Code'); throw $e; } return $e; } public function getAutoAdvance(): bool { return $this->autoAdvance; } /** * @return $this */ public function setAutoAdvance(bool $autoAdvance): self { $this->autoAdvance = $autoAdvance; return $this; } public function getNaiveCount(): bool { return $this->naiveCount; } /** * @return $this */ public function setNaiveCount(bool $naiveCount): self { $this->naiveCount = $naiveCount; return $this; } public function setNoQueryParameters(bool $noQueryParameters): self { $this->noQueryParameters = $noQueryParameters; return $this; } public function getNoQueryParameters(): bool { return $this->noQueryParameters; } public function setIndex(?int $index): IterableAPICollection { $this->index = $index; return $this; } /** * @return bool */ public function hasPagination(): bool { return $this->hasPagination; } public function setHasPagination(bool $hasPagination): static { $this->hasPagination = $hasPagination; return $this; } } CollectionAwareTrait.php 0000644 00000001356 15107447160 0011346 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\Entity; use RuntimeException; trait CollectionAwareTrait { /** * @var CollectionInterface */ protected $collection; public function setCollection(CollectionInterface $collection): void { $this->collection = $collection; } public function getCollection(): CollectionInterface { if (!isset($this->collection)) { throw new RuntimeException('missing collection'); } return $this->collection; } } NoRequestResponseTrait.php 0000644 00000002255 15107447160 0011736 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\Entity; use Psr\Http\Message\RequestInterface; use Psr\Http\Message\ResponseInterface; use RuntimeException; /** * Class NoRequestResponseTrait * * Allow an entity to contain last request / response objects. * * @deprecated This information will no longer be available at the model level but the API client level */ trait NoRequestResponseTrait { /** * @param ResponseInterface $response deprecated */ public function setResponse(ResponseInterface $response): void { throw new RuntimeException(__CLASS__ . ' does not support request / response'); } /** * @param RequestInterface $request deprecated */ public function setRequest(RequestInterface $request): void { throw new RuntimeException(__CLASS__ . ' does not support request / response'); } public function getRequest(): void { } public function getResponse(): void { } } Factory/FactoryInterface.php 0000644 00000000544 15107447160 0012124 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\Entity\Factory; interface FactoryInterface { public function create(array $data); } CollectionTrait.php 0000644 00000014605 15107447160 0010367 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\Entity; use Laminas\Diactoros\Request; use Psr\Http\Message\ResponseInterface; use RuntimeException; use Vonage\Entity\Filter\EmptyFilter; use Vonage\Entity\Filter\FilterInterface; use function array_merge; use function count; use function http_build_query; use function is_null; use function json_decode; use function strpos; /** * Common code for iterating over a collection, and using the collection class to discover the API path. */ trait CollectionTrait { /** * Index of the current resource of the current page * * @var int */ protected $current; /** * Current page data. * * @var array */ protected $page; /** * Last API Response * * @var ResponseInterface */ protected $response; /** * User set page index. * * @var int */ protected $index; /** * User set page size. * * @var int */ protected $size; /** * @var FilterInterface */ protected $filter; abstract public static function getCollectionName(): string; abstract public static function getCollectionPath(): string; /** * @param $data * @param $id */ abstract public function hydrateEntity($data, $id); /** * Return the current item, expects concrete collection to handle creating the object. */ public function current() { return $this->hydrateEntity($this->page['_embedded'][static::getCollectionName()][$this->current], $this->key()); } /** * No checks here, just advance the index. */ public function next(): void { $this->current++; } /** * Return the ID of the resource, in some cases this is `id`, in others `uuid`. * * @return string|int */ public function key() { return $this->page['_embedded'][static::getCollectionName()][$this->current]['id'] ?? $this->page['_embedded'][static::getCollectionName()][$this->current]['uuid'] ?? $this->current; } /** * Handle pagination automatically (unless configured not to). */ public function valid(): bool { //can't be valid if there's not a page (rewind sets this) if (!isset($this->page)) { return false; } //all hal collections have an `_embedded` object, we expect there to be a property matching the collection name if (!isset($this->page['_embedded'][static::getCollectionName()])) { return false; } //if we have a page with no items, we've gone beyond the end of the collection if (!count($this->page['_embedded'][static::getCollectionName()])) { return false; } //index the start of a page at 0 if (is_null($this->current)) { $this->current = 0; } //if our current index is past the current page, fetch the next page if possible and reset the index if (!isset($this->page['_embedded'][static::getCollectionName()][$this->current])) { if (isset($this->page['_links']['next'])) { $this->fetchPage($this->page['_links']['next']['href']); $this->current = 0; return true; } return false; } return true; } /** * Fetch the initial page */ public function rewind(): void { $this->fetchPage(static::getCollectionPath()); } /** * Count of total items */ public function count(): ?int { if (isset($this->page)) { return (int)$this->page['count']; } return null; } /** * @param $index * * @return $this */ public function setPage($index): CollectionTrait { $this->index = (int)$index; return $this; } /** * @return int|mixed */ public function getPage() { if (isset($this->page)) { return $this->page['page_index']; } if (isset($this->index)) { return $this->index; } throw new RuntimeException('page not set'); } /** * @return int|mixed */ public function getSize() { if (isset($this->page)) { return $this->page['page_size']; } if (isset($this->size)) { return $this->size; } throw new RuntimeException('size not set'); } /** * @param $size * * @return $this */ public function setSize($size): CollectionTrait { $this->size = (int)$size; return $this; } /** * Filters reduce to query params and include paging settings. * * @return $this */ public function setFilter(FilterInterface $filter): self { $this->filter = $filter; return $this; } public function getFilter(): FilterInterface { if (!isset($this->filter)) { $this->setFilter(new EmptyFilter()); } return $this->filter; } /** * Fetch a page using the current filter if no query is provided. * * @param $absoluteUri */ protected function fetchPage($absoluteUri): void { //use filter if no query provided if (false === strpos($absoluteUri, '?')) { $query = []; if (isset($this->size)) { $query['page_size'] = $this->size; } if (isset($this->index)) { $query['page_index'] = $this->index; } if (isset($this->filter)) { $query = array_merge($this->filter->getQuery(), $query); } $absoluteUri .= '?' . http_build_query($query); } $request = new Request( $this->getClient()->getApiUrl() . $absoluteUri, 'GET' ); $response = $this->client->send($request); if ((int)$response->getStatusCode() !== 200) { throw $this->getException($response); } $this->response = $response; $this->page = json_decode($this->response->getBody()->getContents(), true); } } RequestArrayTrait.php 0000644 00000005131 15107447160 0010715 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\Entity; use Exception; use RuntimeException; use Vonage\Client\Exception\Exception as ClientException; use function get_class; use function method_exists; use function parse_str; use function sprintf; /** * Implements getRequestData from EntityInterface with a simple array. Request data stored in an array, and locked once * a request object has been set. * * @deprecated This information will be available at API client level as opposed to the model level * @see EntityInterface::getRequestData() */ trait RequestArrayTrait { /** * @var array */ protected $requestData = []; /** * Get an array of params to use in an API request. * * @throws ClientException */ public function getRequestData(bool $sent = true): array { if (!($this instanceof EntityInterface)) { throw new ClientException( sprintf( '%s can only be used if the class implements %s', __TRAIT__, EntityInterface::class ) ); } if ($sent && ($request = $this->getRequest())) { $query = []; parse_str($request->getUri()->getQuery(), $query); return $query; } // Trigger a pre-getRequestData() hook for any last minute // decision making that needs to be done, but only if // it hasn't been sent already if (method_exists($this, 'preGetRequestDataHook')) { $this->preGetRequestDataHook(); } return $this->requestData; } /** * @throws Exception */ protected function setRequestData($name, $value): self { if (!($this instanceof EntityInterface)) { throw new RuntimeException( sprintf( '%s can only be used if the class implements %s', __TRAIT__, EntityInterface::class ) ); } if (@$this->getResponse()) { throw new RuntimeException( sprintf( 'can not set request parameter `%s` for `%s` after API request has be made', $name, $this::class ) ); } $this->requestData[$name] = $value; return $this; } } EntityInterface.php 0000644 00000001243 15107447160 0010357 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\Entity; use Psr\Http\Message\RequestInterface; use Psr\Http\Message\ResponseInterface; interface EntityInterface { public function getRequest(); public function getRequestData(bool $sent = true); public function getResponse(); public function getResponseData(); public function setResponse(ResponseInterface $response); public function setRequest(RequestInterface $request); } JsonSerializableTrait.php 0000644 00000003056 15107447160 0011532 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\Entity; use JsonSerializable; use Vonage\Client\Exception\Exception as ClientException; use function sprintf; /** * Implements getRequestData from EntityInterface based on the entity's jsonSerialize(). * * @see EntityInterface::getRequestData() * @deprecated Each model will handle serializing to/from JSON via hydrators */ trait JsonSerializableTrait { /** * Get an array of params to use in an API request. * * @param bool $sent * * @throws ClientException */ public function getRequestData($sent = true) { if (!($this instanceof EntityInterface)) { throw new ClientException( sprintf( '%s can only be used if the class implements %s', __TRAIT__, EntityInterface::class ) ); } if (!($this instanceof JsonSerializable)) { throw new ClientException( sprintf( '%s can only be used if the class implements %s', __TRAIT__, JsonSerializable::class ) ); } //TODO, figure out what the request data actually was $sent && $this->getRequest(); return $this->jsonSerialize(); } }
Simpan