wachey/api
最新稳定版本:1.2.0
Composer 安装命令:
composer require wachey/api
包简介
Packet for a simple management of the API request for our monitoring platform
README 文档
README
A lightweight PHP client for sending error reports to the Wachey API, compatible with both Laravel and vanilla PHP projects.
Version: 1.0.0 License: MIT Repository: https://github.com/wachey-com/wachey-php
Features
- Laravel support via
config()/env(). - Non-Laravel support with automatic loading of a
.envfile inpublic_html. - Zero external dependencies (uses native cURL).
- Simple integration with exception handlers.
Installation
composer require wachey/api
Configuration
In Laravel
-
In your
config/services.php, add:'wachey' => [ 'key' => env('WACHEY_API_KEY'), 'password' => env('WACHEY_PASSWORD'), ],
-
Make sure your
.envincludes:WACHEY_API_KEY=your_api_key WACHEY_PASSWORD=your_password
In Vanilla PHP
-
Place a
.envfile in yourpublic_html/directory containing:WACHEY_API_KEY=your_api_key WACHEY_PASSWORD=your_password APP_ENV=production
-
If your document root differs, define a constant before using the client:
define('PUBLIC_HTML_PATH', '/path/to/your/public_html'); ```
Usage
Automatic Exception Reporting in Laravel
In Laravel 9+ inside app/Exceptions/Handler.php, register a reportable callback:
use Wachey\Api\Report; public function register(): void { $this->reportable(function (Throwable $e) { Report::error( $e->getMessage(), $e->getFile(), $e->getLine(), request()->ip(), optional(Auth::user())->email ); }); }
Manual Reporting
Wrap your code in a try-catch and call Report::error():
use Wachey\Api\Report; try { // code that may throw } catch (\Exception $e) { Report::error( $e->getMessage(), $e->getFile(), $e->getLine(), $_SERVER['REMOTE_ADDR'] ?? null, 'optional_user_identifier' ); }
API
public static function error( ?string $error = null, ?string $path = null, ?int $line = null, ?string $ip = null, ?string $user = null );
- Returns:
\stdClasson success, orfalseif the JSON response is invalid. - Throws:
\RuntimeExceptionon cURL errors or missing.env.
Env Loading Logic
- Laravel: Uses
config('services.wachey.key')andconfig('services.wachey.password'). - Non-Laravel: Parses
.envunderpublic_htmlviaputenv()and$_ENV.
Adjust the path as needed via a PUBLIC_HTML_PATH constant if you don’t use public_html.
Project Structure
src/
└── Report.php
composer.json
README.md
LICENSE
License
This project is released under the MIT License. See LICENSE for details.
统计信息
- 总下载量: 1.08k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: Unknown
- 更新时间: 2024-05-18