Download the PHP package wachey/api without Composer
On this page you can find all versions of the php package wachey/api. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Package api
Short Description Packet for a simple management of the API request for our monitoring platform
License
Informations about the package api
Wachey API PHP Client
The Wachey\Api\Report
class provides a simple interface for reporting errors to the Wachey API. This class can be used in both Laravel and non-Laravel environments, with support for loading environment variables from a .env
file located in the public_html
folder.
Features
- Supports both Laravel and non-Laravel environments.
- Automatically loads environment variables from the
.env
file inpublic_html
for non-Laravel projects. - Uses Laravel's
env()
function when running in a Laravel environment. - Sends error reports to the Wachey API via
cURL
.
Installation
- Install via composer typing
composer require wachey/api
- Add the
Wachey\Api\Report
class to your PHP project. - Make sure you have a
.env
file in yourpublic_html
directory (or specify a custom path if needed). -
In a non-Laravel environment, the
.env
file should contain your Wachey API credentials, such as: - In Laravel, use Laravel’s built-in
.env
handling mechanism.
Usage
In Laravel
Laravel 9 and Above
For automatic exception management in Laravel 9 and above, you can modify the app.php
file.
Inside the ->withExceptions(function (Exceptions $exceptions) { ... })
section, add the following code:
This will automatically send exceptions to the Wachey API.
Older Versions of Laravel
For older versions of Laravel, modify the report()
method inside app/Exceptions/Handler.php
:
Add the following snippet inside the report()
method:
Ensure you also call the parent report()
method:
This will automatically report exceptions when they are caught by Laravel.
Manual Exception Reporting
If you prefer not to use automatic exception reporting, you can manually report exceptions within your application using try-catch
blocks.
Wherever you expect exceptions, wrap your code in a try-catch
and manually call Report::error()
inside the catch
block:
This gives you control over exactly which exceptions are reported.
Environment Variable Loading Logic
-
Laravel Projects: If the
env()
function exists (as in a Laravel environment), the class will use it to retrieve environment variables. - Non-Laravel Projects: In non-Laravel environments, the class will attempt to load the
.env
file from thepublic_html
folder using PHP’sputenv()
and$_ENV
. Ensure your server’s document root is set correctly.
Example .env
File:
If your server doesn't use the public_html
directory, you can adjust the path in the code or define a constant that points to your .env
location.
Configuration
By default, the .env
file is expected to be in the public_html
folder of your web server. If you are running a custom server configuration, make sure that the path to public_html
is correctly set in the code, or define your own path:
License
This project is open-source and available under the MIT License.