vogelyt/absence-io-client 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

vogelyt/absence-io-client

Composer 安装命令:

composer require vogelyt/absence-io-client

包简介

Comprehensive PHP client library for the absence.io API with full CRUD operations, OAuth support, and advanced querying

README 文档

README

A comprehensive, production-ready PHP client library for the absence.io API with full CRUD operations, Hawk and OAuth 2.0 authentication, and advanced querying capabilities.

Features

  • Full API Coverage: CRUD operations for all absence.io entities (absences, users, teams, departments, etc.)
  • Dual Authentication: Support for both Hawk and OAuth 2.0 authentication
  • Advanced Querying: Powerful query builder with filters, sorting, relations, and pagination
  • Type-Safe: Built with PHP 8.1+ with strict types
  • Well-Tested: Comprehensive test suite with 59+ unit tests
  • Error Handling: Custom exceptions for different API error scenarios
  • Easy to Use: Simple, fluent API for developers

Installation

Using Composer (Recommended)

composer require vogelyt/absence-io-client

Manual Installation

Clone the repository and install dependencies:

git clone https://github.com/vogelyt/absence-io-client.git
cd absence-io-client
composer install

Quick Start

Using Hawk Authentication

<?php

use Vogelyt\AbsenceIoClient\AbsenceClient;
use Vogelyt\AbsenceIoClient\Config\Config;

// Initialize with Hawk credentials
$config = new Config('your-hawk-id', 'your-hawk-key');
$client = new AbsenceClient($config);

// Fetch all users
$users = $client->users()->getAll();

foreach ($users as $user) {
    echo "User: " . $user['name'] . "\n";
}
?>

Using OAuth 2.0

<?php

use Vogelyt\AbsenceIoClient\AbsenceClient;
use Vogelyt\AbsenceIoClient\Config\Config;

// Initialize with OAuth credentials
$config = Config::withOAuth('your-client-id', 'your-client-secret');
$client = new AbsenceClient($config);

// Use the client as normal (token fetching is automatic)
$absences = $client->absences()->getAll();
?>

Authentication

Hawk Authentication

Hawk is a built-in authentication method that signs each request. You'll need your Hawk ID and Key:

$config = new Config('hawk-id', 'hawk-key');
$client = new AbsenceClient($config);

OAuth 2.0

OAuth 2.0 provides token-based authentication. The client automatically handles token fetching and renewal:

$config = Config::withOAuth('client-id', 'client-secret');
$client = new AbsenceClient($config);

// Bearer token is automatically added to requests

API Endpoints

The client provides access to all absence.io entities (paths are plural):

$client->absences();        // Absences  (/api/v2/absences)
$client->users();           // Users    (/api/v2/users)
$client->teams();           // Teams    (/api/v2/teams)
$client->departments();     // Departments (/api/v2/departments)
$client->locations();       // Locations (/api/v2/locations)
$client->reasons();         // Reasons  (/api/v2/reasons)
$client->allowanceTypes();  // Allowance types (/api/v2/allowanceTypes)
$client->timespans();       // Timespans (/api/v2/timespans)
$client->holidays();        // Holidays (/api/v2/holidays)

CRUD Operations

Each endpoint supports full CRUD operations:

Create

Users cannot be created directly via the API; you must send an invitation instead. The invite endpoint accepts extra fields such as firstName, lastName, roleId, company id, etc. Example payload that passes server validation:

$invite = $client->users()->invite('foo2.bar@bar.com', [
    'firstName' => 'foo',
    'lastName' => 'foo',
    'roleId' => '000000000000000000001000',
]);
echo "Invite sent to " . $invite['email'];

For other entities (e.g. absences) use the standard create method:

$absence = $client->absences()->create([
    'assignedToId' => '...',
    'start' => '2026-03-10',
    'end' => '2026-03-12',
    'reasonId' => '...'
]);

Read (Single)

$user = $client->users()->getSingle(123);
echo $user['name'];

Read (List)

$users = $client->users()->getAll();

Update

$updated = $client->users()->update(123, [
    'name' => 'Jane Doe'
]);

Delete

$client->users()->delete(123);

Query Builder

The query builder provides a fluent interface for constructing complex queries:

Basic Filtering

$query = $client->absences()->query()
    ->where('status', 'approved')
    ->whereGreaterThan('created_at', '2024-01-01');

$absences = $client->absences()->getAll($query);

Filter Operators

$query = $client->users()->query()
    ->whereIn('id', [1, 2, 3])                  // IN
    ->whereNotIn('status', ['inactive'])        // NOT IN
    ->whereGreaterThan('salary', 50000)         // Greater than
    ->whereGreaterThanOrEqual('age', 18)        // Greater or equal
    ->whereLessThan('experience', 5)            // Less than
    ->whereLessThanOrEqual('days_left', 10)     // Less or equal
    ->whereLike('name', 'John');                // Case-insensitive substring

Sorting

$query = $client->absences()->query()
    ->orderBy('created_at')                      // Ascending
    ->orderByDesc('name');                       // Descending

Pagination

// Using skip/limit
$query = $client->users()->query()
    ->skip(20)
    ->limit(10);

// Or using page/perPage
$query = $client->users()->query()
    ->page(3, 50);  // Page 3, 50 items per page

Relations

Resolve related entity IDs to full objects:

$query = $client->absences()->query()
    ->with(['assignedToId', 'departmentId']);

$absences = $client->absences()->getAll($query);

Complex Queries

Chain multiple conditions:

$query = $client->absences()->query()
    ->where('status', 'pending')
    ->whereGreaterThan('start_date', '2024-01-01')
    ->whereLike('reason', 'vacation')
    ->orderByDesc('created_at')
    ->page(1, 25)
    ->with(['assignedToId', 'teamId']);

$absences = $client->absences()->getAll($query);

User-Specific Operations

The users endpoint provides additional operations:

Invite a User

$result = $client->users()->invite('newuser@example.com');
echo "Invitation sent to: " . $result['email'];

Error Handling

The client throws specific exceptions for different error scenarios:

<?php

use Vogelyt\AbsenceIoClient\Exception\AuthException;
use Vogelyt\AbsenceIoClient\Exception\ValidationException;
use Vogelyt\AbsenceIoClient\Exception\NotFoundException;
use Vogelyt\AbsenceIoClient\Exception\ApiException;

try {
    $user = $client->users()->getSingle(999);
} catch (NotFoundException $e) {
    echo "User not found";
} catch (AuthException $e) {
    echo "Authentication failed: " . $e->getMessage();
} catch (ValidationException $e) {
    echo "Validation error: " . $e->getMessage();
} catch (ApiException $e) {
    echo "API error: " . $e->getMessage();
}
?>

Configuration

Customize the client configuration:

$config = new Config('hawk-id', 'hawk-key');

// Set custom base URL (optional, defaults to absence.io)
$config->setBaseUrl('https://custom.absence.io/api/v2');

$client = new AbsenceClient($config);

Testing

Run Tests

composer test

or directly:

./vendor/bin/phpunit

Docker Development

Build and start Docker environment:

docker compose build
docker compose run --rm php composer install

Run tests in Docker:

docker compose run --rm php ./vendor/bin/phpunit

Examples

Fetch All Absences for a User

$query = $client->absences()->query()
    ->where('assignedToId', 123)
    ->orderByDesc('start_date');

$absences = $client->absences()->getAll($query);

Create an Absence

$absence = $client->absences()->create([
    'assignedToId' => 123,
    'start' => '2024-02-01',
    'end' => '2024-02-05',
    'reasonId' => 1
]);

Update an Absence Status

$updated = $client->absences()->update(456, [
    'status' => 'approved'
]);

Get Users from a Specific Team

$query = $client->users()->query()
    ->where('teamId', 789)
    ->orderBy('name')
    ->page(1, 50);

$users = $client->users()->getAll($query);

Find Departments

$query = $client->departments()->query()
    ->whereLike('name', 'engineering')
    ->with(['parentId']);

$departments = $client->departments()->getAll($query);

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

This package is open-sourced software licensed under the MIT license.

Support

For issues, questions, or feature requests, please use the GitHub Issues.

API Documentation

For complete API documentation, visit: https://docs.absence.io/

vogelyt/absence-io-client 适用场景与选型建议

vogelyt/absence-io-client 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 853 次下载、GitHub Stars 达 0, 最近一次更新时间为 2026 年 03 月 10 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「php」 「api」 「client」 「Leave」 「vacation」 「absence」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 vogelyt/absence-io-client 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 vogelyt/absence-io-client 我们能提供哪些服务?
定制开发 / 二次开发

基于 vogelyt/absence-io-client 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 853
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-03-10