hapio/hapio-sdk-php
最新稳定版本:1.1.0
Composer 安装命令:
composer require hapio/hapio-sdk-php
包简介
Hapio SDK for PHP.
README 文档
README
The Hapio SDK for PHP allows you to easily interact with the Hapio API for bookings and scheduling when using the PHP programming language.
Requirements
- PHP 8.2 or later
Getting started
The easiest way to install the Hapio SDK is by using Composer to require the package in your project:
composer require hapio/hapio-sdk-php
To use the SDK in your project you simply instantiate an API client, and then get to work:
// Require the Composer autoloader require __DIR__ . '/vendor/autoload.php'; use Hapio\Sdk\ApiClient; // Instantiate a Hapio API client $apiClient = new ApiClient('your-api-token'); // Get a list of all bookings this week $response = $apiClient->bookings()->list([ 'from' => new DateTime('monday this week 00:00:00'), 'to' => new DateTime('friday this week 23:59:59'), ]); while ($response) { foreach ($response->getItems() as $booking) { var_dump($booking); } if ($response->hasMoreItems()) { $response = $response->getNextPage(); } else { $response = null; } }
Documentation
API client
Provide your API token when you instantiate the API client:
use Hapio\Sdk\ApiClient; $apiClient = new ApiClient('your-api-token');
Models
The following models are available in the SDK:
Hapio\Sdk\Models\ProjectHapio\Sdk\Models\LocationHapio\Sdk\Models\ResourceHapio\Sdk\Models\ServiceHapio\Sdk\Models\ScheduleBlockHapio\Sdk\Models\RecurringScheduleHapio\Sdk\Models\RecurringScheduleBlockHapio\Sdk\Models\BookingHapio\Sdk\Models\BookingGroupHapio\Sdk\Models\BookableSlotHapio\Sdk\Models\TimeSpanHapio\Sdk\Models\ResourceServiceAssociation
These models are returned when fetching entities, as well as when you create or update entities. When instantiating a new model, you can provide an array of properties to set:
$location = new Location([ 'name' => 'My first location', 'time_zone' => 'Europe/Stockholm', 'resource_selection_strategy' => 'equalize', ]);
You can also set and get individual properties on the model object:
$location->name = 'My first location'; echo $location->name; // "My first location"
You can use either snake_case or camelCase for the property names. Property names in camelCase will be automatically converted to snake_case internally, since that is used when communicating with the API.
$location->timeZone = 'Europe/London'; echo $location->timeZone; // "Europe/London" echo $location->time_zone; // "Europe/London"
You can only set values for valid property names:
$location->nonExistentAttribute = 'A random value'; echo $location->nonExistentAttribute; // null
Repositories
The Hapio SDK provides a repository class for each type of entity available in Hapio:
Hapio\Sdk\Repositories\ProjectRepositoryHapio\Sdk\Repositories\LocationRepositoryHapio\Sdk\Repositories\ResourceRepositoryHapio\Sdk\Repositories\ServiceRepositoryHapio\Sdk\Repositories\ScheduleBlockRepositoryHapio\Sdk\Repositories\RecurringScheduleRepositoryHapio\Sdk\Repositories\RecurringScheduleBlockRepositoryHapio\Sdk\Repositories\BookingRepositoryHapio\Sdk\Repositories\BookingGroupRepository
These repositories are the communication gateway to the API, and are used to send and retrieve data.
The repositories are accessible through methods on the ApiClient class:
public function projects(): ProjectRepository; public function locations(): LocationRepository; public function resources(): ResourceRepository; public function services(): ServiceRepository; public function scheduleBlocks(): ScheduleBlockRepository; public function recurringSchedules(): RecurringScheduleRepository; public function recurringScheduleBlocks(): RecurringScheduleBlockRepository; public function bookings(): BookingRepository; public function bookingGroups(): BookingGroupRepository;
Each repository has a set of methods, corresponding to the endpoints available for the entity. These are listed for each repository below.
Hapio\Sdk\Repositories\ProjectRepository
public function getCurrentProject(): Project;
Hapio\Sdk\Repositories\LocationRepository
public function list(array $params = []): PaginatedResponse; public function get(string $id): Location; public function store(Location $location): Location; public function replace(string $id, Location $location): Location; public function patch(string $id, Location $location): Location; public function delete(string $id): bool;
Hapio\Sdk\Repositories\ResourceRepository
public function list(array $params = []): PaginatedResponse; public function get(string $id): Resource; public function store(Resource $resource): Resource; public function replace(string $id, Resource $resource): Resource; public function patch(string $id, Resource $resource): Resource; public function delete(string $id): bool; public function listSchedule(string $id, array $params = []): PaginatedResponse; public function listFullyBooked(string $id, array $params = []): PaginatedResponse; public function listAssociatedServices(string $resourceId): array; public function getAssociatedService(string $resourceId, string $serviceId): ResourceServiceAssociation; public function associateService(string $resourceId, string $serviceId): ResourceServiceAssociation; public function dissociateService(string $resourceId, string $serviceId): bool;
Hapio\Sdk\Repositories\ServiceRepository
public function list(array $params = []): PaginatedResponse; public function get(string $id): Service; public function store(Service $service): Service; public function replace(string $id, Service $service): Service; public function patch(string $id, Service $service): Service; public function delete(string $id): bool; public function listBookableSlots(string $serviceId, array $params = []): PaginatedResponse; public function listBookableSlots(string $serviceId, array $params = []): PaginatedResponse; public function listAssociatedResources(string $serviceId): array; public function getAssociatedResource(string $serviceId, string $resourceId): ResourceServiceAssociation; public function associateResource(string $serviceId, string $resourceId): ResourceServiceAssociation; public function dissociateResource(string $serviceId, string $resourceId): bool;
Hapio\Sdk\Repositories\ScheduleBlockRepository
public function list(array $parentIds, array $params = []): PaginatedResponse; public function get(array $parentIds, string $id): ScheduleBlock; public function store(array $parentIds, Service $service): ScheduleBlock; public function replace(array $parentIds, string $id, Service $service): ScheduleBlock; public function patch(array $parentIds, string $id, Service $service): ScheduleBlock; public function delete(array $parentIds, string $id): bool;
Hapio\Sdk\Repositories\RecurringScheduleRepository
public function list(array $parentIds, array $params = []): PaginatedResponse; public function get(array $parentIds, string $id): RecurringSchedule; public function store(array $parentIds, RecurringSchedule $service): RecurringSchedule; public function replace(array $parentIds, string $id, RecurringSchedule $service): RecurringSchedule; public function patch(array $parentIds, string $id, RecurringSchedule $service): RecurringSchedule; public function delete(array $parentIds, string $id): bool;
Hapio\Sdk\Repositories\RecurringScheduleBlockRepository
public function list(array $parentIds, array $params = []): PaginatedResponse; public function get(array $parentIds, string $id): RecurringScheduleBlock; public function store(array $parentIds, Service $service): RecurringScheduleBlock; public function replace(array $parentIds, string $id, Service $service): RecurringScheduleBlock; public function patch(array $parentIds, string $id, Service $service): RecurringScheduleBlock; public function delete(array $parentIds, string $id): bool;
Hapio\Sdk\Repositories\Booking
public function list(array $params = []): PaginatedResponse; public function get(string $id): Booking; public function store(Booking $booking): Booking; public function replace(string $id, Booking $booking): Booking; public function patch(string $id, Booking $booking): Booking; public function delete(string $id): bool;
Hapio\Sdk\Repositories\BookingGroupRepository
public function list(array $params = []): PaginatedResponse; public function get(string $id): BookingGroup; public function store(BookingGroup $bookingGroup): BookingGroup; public function replace(string $id, BookingGroup $bookingGroup): BookingGroup; public function patch(string $id, BookingGroup $bookingGroup): BookingGroup; public function delete(string $id): bool;
Paginated responses
All the methods for API endpoints that respond with a paginated list, will return an instance of Hapio\Sdk\PaginatedResponse. This class has a set of methods that make it easier for you to work with these paginated responses.
public function getItems(): ArrayIterator; public function hasMoreItems(): bool; public function getNextPage(): PaginatedResponse|null; public function getPreviousPage(): PaginatedResponse|null; public function getFirstPage(): PaginatedResponse|null; public function getLastPage(): PaginatedResponse|null; public function getCurrentPageNumber(): int; public function getLastPageNumber(): int; public function getFromIndex(): int; public function getToIndex(): int; public function getTotalItems(): int; public function getItemsPerPage(): int; public function getNextPageLink(): string|null; public function getPreviousPageLink(): string|null; public function getFirstPageLink(): string|null; public function getLastPageLink(): string|null;
Exceptions
Whenever the API responds with a 4XX or 5XX response, an exception will be thrown. Validation error responses with a status code of 422 will throw a Hapio\Sdk\Exceptions\ValidationException, and all other 4XX and 5XX status codes will throw a Hapio\Sdk\Exceptions\ErrorException. For both of these exceptions you can access the original Guzzle exception using the getPrevious() method, the message property of the response is available using the getMessage() method, and the status code can be fetched using the getCode() method. The ValidationException class also has a method for accessing validation errors, called getValidationErrors(). Other Guzzle exceptions are not caught by the SDK.
$resource = new Resource([ 'name' => '', ]); try { $resourceRepository->store($resource); } catch (ValidationException $e) { $e->getCode(); // 422 $e->getMessage(); // "The given data was invalid." $e->getValidationErrors(); // ["name" => ["The name field is required."]] }
Resources
hapio/hapio-sdk-php 适用场景与选型建议
hapio/hapio-sdk-php 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 34 次下载、GitHub Stars 达 3, 最近一次更新时间为 2023 年 10 月 27 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「api」 「client」 「sdk」 「scheduling」 「booking」 「hapio」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 hapio/hapio-sdk-php 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 hapio/hapio-sdk-php 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 hapio/hapio-sdk-php 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A PSR-7 compatible library for making CRUD API endpoints
Mock PSR-18 HTTP client
Asynchronous MQTT client built on React
Client for Google Directions API to add interpolated points to a route consisting of given coordinates.
A Flickr wrapper to allow you to call the Flickr api with Guzzle as the backend.Goal is to have 100% Flickr api coverage rather than just upload/display photos (currently at 23%).
统计信息
- 总下载量: 34
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 3
- 点击次数: 16
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2023-10-27