tschope/flightlogger-php
Composer 安装命令:
composer require tschope/flightlogger-php
包简介
A PHP SDK for integrating with FlightLogger GraphQL API using Saloon
README 文档
README
A PHP SDK for integrating with FlightLogger's GraphQL API, built using Saloon.
Description
This package simplifies integration with the FlightLogger API, allowing you to fetch information about users, students, classes, flights, and training in a simple and intuitive way.
Installation
You can install the package via Composer:
composer require tschope/flightlogger-php
Requirements
- PHP 8.1 or higher
- cURL extension enabled
Configuration
Basic Configuration (Pure PHP)
First, you need to obtain your API token from FlightLogger. Then, you can initialize the connector in three ways:
1. Passing the token directly to the constructor
<?php use Tschope\FlightLogger\FlightLoggerConnector; $connector = new FlightLoggerConnector('your-api-token-here');
2. Using environment variable
Add to your .env file:
FLIGHTLOGGER_API_TOKEN=your-api-token-here
Then initialize without passing the token:
<?php use Tschope\FlightLogger\FlightLoggerConnector; // Token will be automatically read from environment variable $connector = new FlightLoggerConnector();
Laravel Configuration
The package has automatic integration with Laravel through auto-discovery.
1. Publish the configuration file (optional)
php artisan vendor:publish --tag=flightlogger-config
This will create the config/flightlogger.php file.
2. Configure in .env
Add to your .env file:
FLIGHTLOGGER_API_TOKEN=your-api-token-here
3. Use via Dependency Injection
In Laravel, you can inject the connector directly into your controllers or services:
<?php namespace App\Http\Controllers; use Tschope\FlightLogger\FlightLoggerConnector; use Tschope\FlightLogger\Requests\Users\GetUsersRequest; class FlightLoggerController extends Controller { public function __construct( protected FlightLoggerConnector $flightLogger ) {} public function index() { $request = new GetUsersRequest(['limit' => 10]); $response = $this->flightLogger->send($request); return response()->json($response->json()); } }
4. Or use Laravel's helper
use Tschope\FlightLogger\FlightLoggerConnector; $connector = app(FlightLoggerConnector::class);
Configuration Priority
The package looks for the API token in the following order:
- Token passed to constructor (highest priority)
- Laravel configuration file (
config/flightlogger.php) - Environment variable
FLIGHTLOGGER_API_TOKEN
If no token is found, a RuntimeException will be thrown.
Usage
Fetching Users
List all users
use Tschope\FlightLogger\Requests\Users\GetUsersRequest; $request = new GetUsersRequest([ 'limit' => 50, 'offset' => 0, 'orderBy' => 'firstName', 'orderDirection' => 'ASC' ]); $response = $connector->send($request); $data = $response->json(); // Accessing data foreach ($data['data']['users']['edges'] as $edge) { $user = $edge['node']; echo "Name: {$user['firstName']} {$user['lastName']}\n"; echo "Email: {$user['email']}\n"; }
Fetch a specific user
use Tschope\FlightLogger\Requests\Users\GetUserRequest; $request = new GetUserRequest('user-id-here'); $response = $connector->send($request); $user = $response->json()['data']['user']; echo "Name: {$user['firstName']} {$user['lastName']}\n";
Fetching Classes (Groups of Students)
use Tschope\FlightLogger\Requests\Classes\GetClassesRequest; $request = new GetClassesRequest([ 'first' => 20 ]); $response = $connector->send($request); $data = $response->json(); foreach ($data['data']['classes']['edges'] as $edge) { $class = $edge['node']; echo "Class: {$class['name']}\n"; // Listing students in the class foreach ($class['users'] as $student) { echo " - {$student['firstName']} {$student['lastName']}\n"; } }
Fetching Flights
use Tschope\FlightLogger\Requests\Flights\GetFlightsRequest; $request = new GetFlightsRequest([ 'first' => 50, 'from' => '2024-01-01T00:00:00Z', 'to' => '2024-12-31T23:59:59Z' ]); $response = $connector->send($request); $data = $response->json(); foreach ($data['data']['flights']['edges'] as $edge) { $flight = $edge['node']; echo "Flight: {$flight['id']}\n"; echo "Type: {$flight['flightType']}\n"; echo "Aircraft: {$flight['aircraft']['registration']}\n"; echo "From: {$flight['departureAirport']['icao']} to {$flight['arrivalAirport']['icao']}\n"; // Pilot/instructor information if (!empty($flight['primaryLog'])) { $pilot = $flight['primaryLog']['user']; echo "Pilot: {$pilot['firstName']} {$pilot['lastName']}\n"; } echo "\n"; }
Fetching Trainings
use Tschope\FlightLogger\Requests\Trainings\GetTrainingsRequest; $request = new GetTrainingsRequest([ 'first' => 30, 'status' => ['APPROVED', 'PENDING'] ]); $response = $connector->send($request); $data = $response->json(); foreach ($data['data']['trainings']['edges'] as $edge) { $training = $edge['node']; echo "Training: {$training['name']}\n"; echo "Status: {$training['status']}\n"; // Instructor information if (!empty($training['instructor'])) { echo "Instructor: {$training['instructor']['firstName']} {$training['instructor']['lastName']}\n"; } // Student information if (!empty($training['student'])) { echo "Student: {$training['student']['firstName']} {$training['student']['lastName']}\n"; } // Total time $hours = $training['totalSeconds'] / 3600; echo "Total hours: " . number_format($hours, 2) . "h\n"; echo "\n"; }
Custom Fields
You can customize the fields returned by queries by passing an array of fields as the second parameter:
$request = new GetUsersRequest( ['limit' => 10], ['id', 'firstName', 'lastName', 'email', 'phone'] );
For nested fields (like relationships), use GraphQL syntax:
$request = new GetFlightsRequest( ['first' => 10], [ 'id', 'flightType', 'aircraft { registration model type }', 'primaryLog { user { firstName lastName } role }' ] );
Pagination
FlightLogger queries use cursor-based pagination. You can navigate through results using the after, before, first, and last parameters:
// First page $request = new GetFlightsRequest(['first' => 20]); $response = $connector->send($request); $data = $response->json(); // Check if there's a next page if ($data['data']['flights']['pageInfo']['hasNextPage']) { $endCursor = $data['data']['flights']['pageInfo']['endCursor']; // Fetch next page $nextRequest = new GetFlightsRequest([ 'first' => 20, 'after' => $endCursor ]); $nextResponse = $connector->send($nextRequest); }
Error Handling
try { $response = $connector->send($request); if ($response->failed()) { echo "Request error: " . $response->status() . "\n"; echo $response->body(); } else { $data = $response->json(); // Process data } } catch (\Exception $e) { echo "Error: " . $e->getMessage() . "\n"; }
Contributing
Contributions are welcome! This package was created to start with the most common endpoints, but the FlightLogger API has many other available endpoints.
To add new endpoints:
- Create a new class that extends
GraphQLRequestorGraphQLMutation - Implement the
getQuery()(orgetMutation()) andgetVariables()methods - Define default fields in
getDefaultFields() - Add tests and documentation
Example structure for a new endpoint:
<?php namespace Tschope\FlightLogger\Requests\ResourceName; use Tschope\FlightLogger\Requests\GraphQLRequest; class GetResourceRequest extends GraphQLRequest { protected array $filters; protected array $fields; public function __construct(array $filters = [], array $fields = null) { $this->filters = $filters; $this->fields = $fields ?? $this->getDefaultFields(); } protected function getQuery(): string { // Your GraphQL query here } protected function getVariables(): array { return $this->filters; } protected function getDefaultFields(): array { // Default query fields } }
License
This package is open-source and available under the MIT license.
Links
Support
If you encounter any issues or have suggestions, please open an issue on GitHub.
Credits
Developed by tschope
This is an unofficial package and is not affiliated with FlightLogger.
tschope/flightlogger-php 适用场景与选型建议
tschope/flightlogger-php 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1.62k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 11 月 16 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「api」 「flight」 「graphql」 「aviation」 「saloon」 「flightlogger」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 tschope/flightlogger-php 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 tschope/flightlogger-php 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 tschope/flightlogger-php 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
GraphQL authentication for your headless Craft CMS applications.
This Bundle provides a wrapper for the FlightStats API
Authorize introspection documentarion for rebing/graphql-laravel
Sylius backend integration for Vue Storefront 2
A PSR-7 compatible library for making CRUD API endpoints
GraphQL client and query builder.
统计信息
- 总下载量: 1.62k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 16
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-11-16