### Using errorConfig Source: https://github.com/airbrake/phpbrake/blob/master/_autodocs/api-reference/remote-config.md Example of calling errorConfig and the expected return value. ```php $config = $rc->errorConfig(); // e.g. ['host' => 'remote-config.airbrake.io', 'enabled' => true] ``` -------------------------------- ### Install PHPBrake with Composer Source: https://github.com/airbrake/phpbrake/blob/master/README.md Use Composer to install the PHPBrake package. Run this command in your project directory to add the dependency. ```bash composer require airbrake/phpbrake ``` -------------------------------- ### Generate PHPDoc with phpDocumentor Source: https://github.com/airbrake/phpbrake/blob/master/README.md Installs phpDocumentor via Composer, generates documentation from the src directory, and opens the output in Firefox. ```bash composer require phpdocumentor/phpdocumentor vendor/bin/phpdoc -d src firefox output/index.html ``` -------------------------------- ### notify usage example Source: https://github.com/airbrake/phpbrake/blob/master/_autodocs/api-reference/notifier.md Shows how to use notify to report an exception, catching it and checking the returned notice for an 'error' key to handle failures. ```php try { throw new Exception('hello from phpbrake'); } catch (Exception $e) { $notice = $notifier->notify($e); if (isset($notice['error'])) { /* error handling */ } } ``` -------------------------------- ### Using notifyAsync Source: https://github.com/airbrake/phpbrake/blob/master/_autodocs/api-reference/notifier.md Example usage of notifyAsync. The promise resolves with the notice on success. ```php $promise = $notifier->notifyAsync($e); $promise->then(function ($notice) { // notice['id'] set on success }); $promise->wait(); ``` -------------------------------- ### Configure httpClient Source: https://github.com/airbrake/phpbrake/blob/master/README.md Supplies a custom HTTP client that implements GuzzleHttp\ClientInterface. The example creates a GuzzleClient with a timeout of 3 seconds. ```php // Supply your own client. $client = new Airbrake\Http\GuzzleClient( new GuzzleHttp\Client(['timeout' => 3]) ); $notifier = new Airbrake\Notifier([ // ... 'httpClient' => $client, // ... ]); ``` -------------------------------- ### Quickstart: Create notifier, register handlers, and notify Source: https://github.com/airbrake/phpbrake/blob/master/README.md Creates a new Airbrake\Notifier with projectId and projectKey, sets it as the global instance, registers error and exception handlers via Airbrake\ErrorHandler, and sends a test exception using Airbrake\Instance::notify(). Replace the placeholder projectId and projectKey values before use. ```php // Create new Notifier instance. $notifier = new Airbrake\Notifier([ 'projectId' => 12345, // FIX ME 'projectKey' => 'abcdefg' // FIX ME ]); // Set global notifier instance. Airbrake\Instance::set($notifier); // Register error and exception handlers. $handler = new Airbrake\ErrorHandler($notifier); $handler->register(); // Somewhere in the app... try { throw new Exception('hello from phpbrake'); } catch(Exception $e) { Airbrake\Instance::notify($e); } ``` -------------------------------- ### Run tests locally with Composer and PHPUnit Source: https://github.com/airbrake/phpbrake/blob/master/README.md Installs dependencies with Composer and runs the PHPUnit test suite locally. Requires PHP and Composer. ```bash composer install vendor/bin/phpunit ``` -------------------------------- ### Run tests via Docker Compose Source: https://github.com/airbrake/phpbrake/blob/master/README.md Runs the test suite using Docker Compose. Requires Docker and Docker Compose installed. ```bash docker compose run tests ``` -------------------------------- ### Using sendNoticeAsync Source: https://github.com/airbrake/phpbrake/blob/master/_autodocs/api-reference/notifier.md Example usage of sendNoticeAsync. The promise resolves with the response or rejects with the error string. ```php $promise = $notifier->sendNoticeAsync($notice); $promise->then(function ($resp) { // success path }, function ($reason) { // $reason is the error string }); ``` -------------------------------- ### Send notice with Airbrake\Instance::sendNotice Source: https://github.com/airbrake/phpbrake/blob/master/_autodocs/api-reference/instance.md Sends a pre-built notice and returns the notice array with 'id' on success or 'error' on failure. The example checks for an error key. ```php $resp = Airbrake\Instance::sendNotice($notice); if (isset($resp['error'])) { /* failure */ } ``` -------------------------------- ### Send notice asynchronously with Airbrake\Instance::sendNoticeAsync Source: https://github.com/airbrake/phpbrake/blob/master/_autodocs/api-reference/instance.md Sends a notice asynchronously, returning a promise. The example uses then() to handle success or failure. ```php Airbrake\Instance::sendNoticeAsync($notice)->then(function ($resp) { // success }, function ($reason) { // $reason is the error string }); ``` -------------------------------- ### Notify asynchronously with Airbrake\Instance::notifyAsync Source: https://github.com/airbrake/phpbrake/blob/master/_autodocs/api-reference/instance.md Builds and sends a notice asynchronously in one call. The example waits on the returned promise. ```php $promise = Airbrake\Instance::notifyAsync($e); $promise->wait(); ``` -------------------------------- ### Notify with Airbrake\Instance::notify Source: https://github.com/airbrake/phpbrake/blob/master/_autodocs/api-reference/instance.md Builds and sends a notice for an exception in one call. The example catches an exception and notifies Airbrake. ```php try { throw new Exception('hello from phpbrake'); } catch (Exception $e) { Airbrake\Instance::notify($e); } ``` -------------------------------- ### Get code hunk with CodeHunk::get() Source: https://github.com/airbrake/phpbrake/blob/master/_autodocs/api-reference/code-hunk.md Returns an array of trimmed source lines for the window line-2 to line+2, or null if the file does not exist or cannot be opened. The result is cached by the composite key $file . $line. ```php $lines = $codeHunk->get('/var/www/project/src/app.php', 42); // e.g. [40 => 'try {', 41 => ' risky();', 42 => '} catch (Exception $e) {', ...] $lines = $codeHunk->get('/nonexistent.php', 10); // file_exists fails // null — the miss itself is cached under the key '/nonexistent.php10' ``` -------------------------------- ### sendNotice usage example Source: https://github.com/airbrake/phpbrake/blob/master/_autodocs/api-reference/notifier.md Calls sendNotice with a notice array and checks the response for an 'error' key to handle failure, otherwise retrieves the notice id from the 'id' key. ```php $resp = $notifier->sendNotice($notice); if (isset($resp['error'])) { // handle failure } else { $id = $resp['id']; } ``` -------------------------------- ### CodeHunk::get() with caching Source: https://github.com/airbrake/phpbrake/blob/master/_autodocs/api-reference/code-hunk.md Shows the full get method that uses the LRU cache to store both hits and misses. The cache key is the string concatenation of $file and $line. ```php public function get($file, $line) { $cacheKey = $file . $line; $lines = $this->cache->get($cacheKey, false); if ($lines !== false) { return $lines; } $lines = $this->_get($file, $line); $this->cache->put($cacheKey, $lines); return $lines; } ``` -------------------------------- ### Create a Notifier with projectId and projectKey Source: https://github.com/airbrake/phpbrake/blob/master/_autodocs/api-reference/notifier.md Instantiates the notifier with required options. The constructor throws an exception if projectId or projectKey are missing. ```php $notifier = new Airbrake\Notifier([ 'projectId' => 12345, 'projectKey' => 'abcdefg' ]); ``` -------------------------------- ### Configure rootDirectory Source: https://github.com/airbrake/phpbrake/blob/master/README.md Sets the project root directory to filter repetitive backtrace data and link to GitHub files. Expects a String or Pathname. ```php $notifier = new Airbrake\Notifier([ // ... 'rootDirectory' => '/var/www/project', // ... ]); ``` -------------------------------- ### Notifier integration methods Source: https://github.com/airbrake/phpbrake/blob/master/_autodocs/api-reference/remote-config.md Internal methods in Notifier that use remoteErrorConfig to get host and enabled status. ```php protected function errorHost() // src/Notifier.php:550 { if (isset($this->opt['host'])) { return $this->opt['host']; } else { return $this->remoteErrorConfig()['host']; } } protected function errorNotifications() // src/Notifier.php:559 { return $this->remoteErrorConfig()['enabled']; } ``` -------------------------------- ### Create a TempCache instance with custom filename and TTL Source: https://github.com/airbrake/phpbrake/blob/master/_autodocs/api-reference/temp-cache.md Shows how to instantiate the cache with a custom file name and TTL of 300 seconds. The constructor stores the file in the system temp directory. ```php $cache = new Airbrake\TempCache('my_cache.json', 300); ``` -------------------------------- ### new Airbrake\RemoteConfig($projectId) Source: https://github.com/airbrake/phpbrake/blob/master/_autodocs/api-reference/remote-config.md Constructs a RemoteConfig instance. Builds the remote URL, creates an HTTP client with timeouts, and initializes a temp cache. ```APIDOC ## Constructor: `__construct($projectId)` ### Description Creates a new RemoteConfig instance for the given project ID. Builds the remote configuration URL, sets up an HTTP client with 10-second timeouts, and initializes a disk cache. ### Method Constructor ### Signature ```php public function __construct($projectId) ``` ### Parameters - **$projectId** (int) - Required - Airbrake project id; substitutes the `%d` in the remote config URL. ### Example ```php $rc = new Airbrake\RemoteConfig(12345); ``` ``` -------------------------------- ### Build notice with Airbrake\Instance::buildNotice Source: https://github.com/airbrake/phpbrake/blob/master/_autodocs/api-reference/instance.md Builds an Airbrake notice array from an exception or error object. Returns the notice array. ```php $notice = Airbrake\Instance::buildNotice($e); ``` -------------------------------- ### Catching Airbrake\Exception for invalid httpClient Source: https://github.com/airbrake/phpbrake/blob/master/_autodocs/api-reference/exception.md Example of catching Airbrake\Exception when httpClient does not implement GuzzleHttp\ClientInterface. The catch block logs the message 'phpbrake: httpClient must implement GuzzleHttp\ClientInterface'. ```php try { $notifier = new Airbrake\Notifier([ 'projectId' => 12345, 'projectKey' => 'k', 'httpClient' => new SomeOtherClient(), // not a GuzzleHttp\ClientInterface ]); } catch (Airbrake\Exception $e) { error_log($e->getMessage()); // 'phpbrake: httpClient must implement GuzzleHttp\ClientInterface' } ``` -------------------------------- ### Constructor signature Source: https://github.com/airbrake/phpbrake/blob/master/_autodocs/api-reference/remote-config.md Public constructor that takes a project ID. Builds the remote URL, creates an HTTP client with timeouts, and creates a TempCache. ```php public function __construct($projectId) ``` -------------------------------- ### Constructor Source: https://github.com/airbrake/phpbrake/blob/master/_autodocs/api-reference/temp-cache.md Creates a new TempCache instance with a specified filename and TTL. ```APIDOC ## Constructor ### Description Creates a new TempCache instance. The cache file is stored under the system temp directory with the given filename. The TTL defines the freshness window in seconds. ### Method Constructor ### Signature `public function __construct($filename = 'airbrake_temp_cache.json', $ttl = 600)` ### Parameters - **$filename** (string) - Optional - Default: `'airbrake_temp_cache.json'` - File name; stored under `getSystemTempDirectory() . "/" . $filename` - **$ttl** (int) - Optional - Default: `600` - Cache freshness window in seconds ### Example ```php $cache = new Airbrake\TempCache('my_cache.json', 300); ``` ``` -------------------------------- ### Instantiate CodeHunk with new Airbrake\CodeHunk() Source: https://github.com/airbrake/phpbrake/blob/master/_autodocs/api-reference/code-hunk.md Creates a new CodeHunk instance with an empty LRUCache(1000). ```php $codeHunk = new Airbrake\CodeHunk(); ``` -------------------------------- ### Catching Airbrake\Exception for missing projectId/projectKey Source: https://github.com/airbrake/phpbrake/blob/master/_autodocs/api-reference/exception.md Example of catching Airbrake\Exception around Notifier construction when projectId or projectKey is missing. The catch block logs the message 'phpbrake: Notifier requires projectId and projectKey'. ```php try { $notifier = new Airbrake\Notifier(['projectId' => 12345]); } catch (Airbrake\Exception $e) { error_log('phpbrake construction failed: ' . $e->getMessage()); // 'phpbrake: Notifier requires projectId and projectKey' } ``` -------------------------------- ### Configure host Source: https://github.com/airbrake/phpbrake/blob/master/README.md Sets a custom host for the notifier. Default is api.airbrake.io. Scheme and port are optional; https and port 80 are assumed if omitted. ```php $notifier = new Airbrake\Notifier([ // ... 'host' => 'errbit.example.com', // put your errbit host here // ... ]); ``` -------------------------------- ### Check if cache is expired with expired method Source: https://github.com/airbrake/phpbrake/blob/master/_autodocs/api-reference/temp-cache.md The expired() method returns true when the cache file does not exist or when its modification time plus the TTL is less than the current time. This example shows a conditional refetch pattern. ```php if ($cache->expired()) { // refetch } ``` -------------------------------- ### Instantiate RemoteConfig Source: https://github.com/airbrake/phpbrake/blob/master/_autodocs/api-reference/remote-config.md Creates a new RemoteConfig instance with project ID 12345. ```php $rc = new Airbrake\RemoteConfig(12345); ``` -------------------------------- ### GET https://notifier-configs.airbrake.io/2020-06-18/config/{projectId}/config.json Source: https://github.com/airbrake/phpbrake/blob/master/_autodocs/endpoints.md Fetches remote notifier configuration for a given project. The response provides the error reporting endpoint and enabled flag, which override local settings. Falls back to default configuration on any error or unexpected response. ```APIDOC ## GET https://notifier-configs.airbrake.io/2020-06-18/config/{projectId}/config.json ### Description Fetches remote notifier configuration for a given project. The response provides the error reporting endpoint and enabled flag, which override local settings. Falls back to default configuration on any error or unexpected response. ### Method GET ### Endpoint https://notifier-configs.airbrake.io/2020-06-18/config/{projectId}/config.json ### Parameters #### Path Parameters - **projectId** (string) - Required - The project identifier for which to fetch configuration. #### Query Parameters - **notifier_name** (string) - Required - Set to `phpbrake`. - **notifier_version** (string) - Required - The notifier version, from `AIRBRAKE_NOTIFIER_VERSION`. - **os** (string) - Required - The operating system, from `PHP_OS`. - **language** (string) - Required - The language and version, e.g., `PHP8.0`. ### Request Example GET https://notifier-configs.airbrake.io/2020-06-18/config/12345/config.json?notifier_name=phpbrake¬ifier_version=1.0.0&os=Linux&language=PHP8.0 ### Response #### Success Response (200) - **settings** (array of objects) - List of configuration settings. Each entry contains: - **name** (string) - Setting name, matched against `'errors'`. - **endpoint** (string) - The notice host override. If missing or null, defaults to `api.airbrake.io`. - **enabled** (bool) - Whether notifications are enabled. If missing, defaults to `true`. #### Response Example { "settings": [ { "name": "errors", "endpoint": "https://example.com/notices", "enabled": true } ] } ### Error Handling - **Non-200 status** (e.g., 403) - Returns default config: `{"host": "api.airbrake.io", "enabled": true}`. - **JSON decode failure** - Returns default config. - **HTTP exception** - Returns default config. - **Missing `settings` key** - Returns default config. - **No `errors` setting** - Returns default config. ### Notes - No authentication required. - Response is cached on disk with TTL 600 seconds. - The fetched config is used by `Notifier::errorHost()` and `Notifier::errorNotifications()` on every notice send. ``` -------------------------------- ### Configure environment Source: https://github.com/airbrake/phpbrake/blob/master/README.md Sets the application environment to help the dashboard distinguish exceptions. Not set by default. ```php $notifier = new Airbrake\Notifier([ // ... 'environment' => 'staging', // ... ]); ``` -------------------------------- ### Configure appVersion Source: https://github.com/airbrake/phpbrake/blob/master/README.md Sets the application version to differentiate exceptions between versions. Not set by default. ```php $notifier = new Airbrake\Notifier([ // ... 'appVersion' => '1.2.3', // ... ]); ``` -------------------------------- ### Set global notifier instance Source: https://github.com/airbrake/phpbrake/blob/master/_autodocs/api-reference/instance.md Creates a new Notifier and stores it as the global instance via Airbrake\Instance::set(). The notifier is configured with projectId and projectKey. ```php $notifier = new Airbrake\Notifier([ 'projectId' => 12345, 'projectKey' => 'abcdefg' ]); Airbrake\Instance::set($notifier); ``` -------------------------------- ### Configure keysBlocklist Source: https://github.com/airbrake/phpbrake/blob/master/README.md Specifies a list of regex patterns for sensitive keys to filter out from error reports. ```php $notifier = new Airbrake\Notifier([ // ... 'keysBlocklist' => ['/secret/i', '/password/i'], // ... ]); ``` -------------------------------- ### errorConfig method signature Source: https://github.com/airbrake/phpbrake/blob/master/_autodocs/api-reference/remote-config.md Returns an array with 'host' and 'enabled' keys. Reads from cache or fetches remotely, falling back to DEFAULT_CONFIG on error. ```php public function errorConfig() ``` -------------------------------- ### buildNoticesURL - Construct notice endpoint URL Source: https://github.com/airbrake/phpbrake/blob/master/_autodocs/endpoints.md Builds the URL for the create notice v3 endpoint. Ensures the scheme is https if not provided, and preserves an existing http/https scheme. Uses the project ID from options. ```php protected function buildNoticesURL() { $schemeAndHost = $this->errorHost(); if (!preg_match('~^https?://~i', $schemeAndHost)) { $schemeAndHost = "https://$schemeAndHost"; } return sprintf( '%s/api/v3/projects/%d/notices', $schemeAndHost, $this->opt['projectId'] ); } ``` -------------------------------- ### notify Source: https://github.com/airbrake/phpbrake/blob/master/_autodocs/api-reference/notifier.md Shortcut method that combines buildNotice and sendNotice. Accepts a Throwable or Exception and returns the notice array with 'id' or 'error' set. ```APIDOC ## notify ### Description Shortcut method that combines buildNotice and sendNotice. Accepts a Throwable or Exception and returns the notice array with 'id' or 'error' set. ### Method notify ### Endpoint notify($exc) ### Parameters #### Path Parameters - **$exc** (\Throwable/\Exception) - Required - Error to report ### Request Example ```php try { throw new Exception('hello from phpbrake'); } catch (Exception $e) { $notice = $notifier->notify($e); } ``` ### Response #### Success Response - **id** (string) - Notice id from Airbrake on success - **error** (string) - Error message on failure #### Response Example ```php ['id' => '12345'] // success ['error' => '...'] // failure ``` ``` -------------------------------- ### Basic usage: push Airbrake\MonologHandler to a Monolog logger Source: https://github.com/airbrake/phpbrake/blob/master/_autodocs/api-reference/monolog-handler.md Creates a Monolog logger named 'billing' and pushes the Airbrake handler with the default error level and bubble behavior. ```php $log = new Monolog\Logger('billing'); $log->pushHandler(new Airbrake\MonologHandler($notifier)); ``` -------------------------------- ### CodeHunk::__construct Source: https://github.com/airbrake/phpbrake/blob/master/_autodocs/api-reference/code-hunk.md Creates a new CodeHunk instance with an empty LRUCache of capacity 1000. ```APIDOC ## CodeHunk::__construct ### Description Creates a new CodeHunk instance with an empty LRUCache of capacity 1000. ### Method __construct ### Signature public function __construct() ### Parameters None ### Returns A new CodeHunk instance. ### Example ```php $codeHunk = new Airbrake\CodeHunk(); ``` ``` -------------------------------- ### Log an error with context and observe notice mapping Source: https://github.com/airbrake/phpbrake/blob/master/_autodocs/api-reference/monolog-handler.md Logs an error with a context array. The resulting notice has errors[0].type set to 'billing.ERROR', context.severity to 'ERROR', and params.monolog_context containing the context. ```php $log->addError('charge failed', ['client_id' => 123]); // -> notice: errors[0].type = 'billing.ERROR', // context.severity = 'ERROR', // params.monolog_context = ['client_id' => 123] ``` -------------------------------- ### Throw site for missing projectId or projectKey Source: https://github.com/airbrake/phpbrake/blob/master/_autodocs/api-reference/exception.md Verbatim code from src/Notifier.php:71-73. Throws Airbrake\Exception with message 'phpbrake: Notifier requires projectId and projectKey' when either option is empty. ```php if (empty($opt['projectId']) || empty($opt['projectKey'])) { throw new Exception('phpbrake: Notifier requires projectId and projectKey'); } ``` -------------------------------- ### register(): Register all handlers Source: https://github.com/airbrake/phpbrake/blob/master/_autodocs/api-reference/error-handler.md Registers the onError, onException, and onShutdown handlers in one call. This is the recommended way to enable all error reporting. ```php set_error_handler([$this, 'onError'], error_reporting()); set_exception_handler([$this, 'onException']); register_shutdown_function([$this, 'onShutdown']); ``` ```php $handler = new Airbrake\ErrorHandler($notifier); $handler->register(); ``` -------------------------------- ### Constructor: Create ErrorHandler instance Source: https://github.com/airbrake/phpbrake/blob/master/_autodocs/api-reference/error-handler.md Instantiates an ErrorHandler with a Notifier instance. The notifier is used to send error notices. ```php $handler = new Airbrake\ErrorHandler($notifier); ``` -------------------------------- ### write Source: https://github.com/airbrake/phpbrake/blob/master/_autodocs/api-reference/temp-cache.md Serializes and writes a value to the cache file. ```APIDOC ## write ### Description Serializes the given value and writes it to the cache file. Returns `true` on success, `false` on failure (including when writing throws). Never throws. ### Method write ### Signature `public function write($value)` ### Parameters - **$value** (mixed) - Required - Value to serialize and store ### Returns - **bool** - `true` if the write succeeded, `false` otherwise. ### Example ```php $ok = $cache->write(['host' => 'api.airbrake.io', 'enabled' => true]); ``` ``` -------------------------------- ### register() Source: https://github.com/airbrake/phpbrake/blob/master/_autodocs/api-reference/error-handler.md Registers all three handlers (onError, onException, onShutdown) in one call. ```APIDOC ## register ### Description Registers all three handlers in one call. ### Method register ### Endpoint `register()` ### Parameters None ### Request Example ```php $handler = new Airbrake\ErrorHandler($notifier); $handler->register(); ``` ``` -------------------------------- ### CodeHunk::get Source: https://github.com/airbrake/phpbrake/blob/master/_autodocs/api-reference/code-hunk.md Retrieves a window of source code lines around a given line number. Returns null if the file does not exist or cannot be opened. Results are cached by file and line. ```APIDOC ## CodeHunk::get ### Description Retrieves a window of source code lines around a given line number. Returns null if the file does not exist or cannot be opened. Results are cached by file and line. ### Method public function get($file, $line) ### Parameters - **$file** (string) - Required - Absolute or relative path of the source file. - **$line** (int) - Required - 1-based error line number. ### Returns - **array|null** - An associative array mapping actual 1-based line numbers to trimmed source text for the window `line-2` to `line+2`. Returns `null` if the file does not exist or cannot be opened. ### Example ```php $lines = $codeHunk->get('/var/www/project/src/app.php', 42); // e.g. [40 => 'try {', 41 => ' risky();', 42 => '} catch (Exception $e) {', ...] $lines = $codeHunk->get('/nonexistent.php', 10); // file_exists fails // null — the miss itself is cached under the key '/nonexistent.php10' ``` ``` -------------------------------- ### Write a value to cache with write method Source: https://github.com/airbrake/phpbrake/blob/master/_autodocs/api-reference/temp-cache.md The write() method serializes the provided value and stores it via file_put_contents. Returns true on success, false on failure (including when writing throws). The parameter $value is required and mixed. ```php $ok = $cache->write(['host' => 'api.airbrake.io', 'enabled' => true]); ``` -------------------------------- ### errorConfig() Source: https://github.com/airbrake/phpbrake/blob/master/_autodocs/api-reference/remote-config.md Returns the error configuration as an array with 'host' and 'enabled' keys. Reads from cache or fetches from remote, falling back to DEFAULT_CONFIG on any error. ```APIDOC ## Method: `errorConfig()` ### Description Returns the error configuration array containing 'host' and 'enabled' keys. Reads the config from the on-disk cache or fetches it from the remote when the cache is expired; falls back to DEFAULT_CONFIG on any error. ### Method GET (conceptual - fetches remote configuration) ### Signature ```php public function errorConfig() ``` ### Returns - **array** - `['host' => string, 'enabled' => bool]` ### Example ```php $config = $rc->errorConfig(); // e.g. ['host' => 'remote-config.airbrake.io', 'enabled' => true] ``` ``` -------------------------------- ### Add custom data to the notice with addFilter Source: https://github.com/airbrake/phpbrake/blob/master/README.md Uses addFilter to set the 'environment' context field to 'production' on every notice. The filter must return the modified notice to take effect. ```php $notifier->addFilter(function ($notice) { $notice['context']['environment'] = 'production'; return $notice; }); ``` -------------------------------- ### write method signature for Airbrake\MonologHandler Source: https://github.com/airbrake/phpbrake/blob/master/_autodocs/api-reference/monolog-handler.md Protected method that processes each Monolog record, converting it into an Airbrake notice. Returns void. ```php protected function write(array $record): void ``` -------------------------------- ### sendNotice Source: https://github.com/airbrake/phpbrake/blob/master/_autodocs/api-reference/instance.md Sends a pre-built notice to Airbrake synchronously. Returns the notice array with 'id' set on success or 'error' on failure. ```APIDOC ## sendNotice ### Description Sends a pre-built notice to Airbrake synchronously. Returns the notice array with 'id' set on success or 'error' on failure. ### Method sendNotice ### Parameters #### Parameters - `$notice` (array) - Required - The notice array to send ### Returns Array - The notice array with 'id' (success) or 'error' (failure) set ### Example ```php $resp = Airbrake\Instance::sendNotice($notice); if (isset($resp['error'])) { /* failure */ } ``` ``` -------------------------------- ### Constructor signature for Airbrake\TempCache Source: https://github.com/airbrake/phpbrake/blob/master/_autodocs/api-reference/temp-cache.md Defines the constructor parameters: $filename (string, default 'airbrake_temp_cache.json') and $ttl (int, default 600). The file is stored under the system temp directory. This snippet declares the method signature. ```php public function __construct($filename = 'airbrake_temp_cache.json', $ttl = 600) ``` -------------------------------- ### Log an error with an exception in context Source: https://github.com/airbrake/phpbrake/blob/master/_autodocs/api-reference/monolog-handler.md Logs an error with an exception in the context. The exception is extracted from the context, and the backtrace is taken from $e->getTrace(). ```php $log->addError('charge failed', ['client_id' => 123, 'exception' => $e]); // -> exception from context, backtrace from $e->getTrace() ``` -------------------------------- ### Protected API signatures for TempCache Source: https://github.com/airbrake/phpbrake/blob/master/_autodocs/api-reference/temp-cache.md Lists the protected method signatures used internally: readCacheFile, writeCacheFile, and getSystemTempDirectory. These are not intended for public use but are documented for reference. ```php protected function readCacheFile() ``` ```php protected function writeCacheFile($value) ``` ```php protected function getSystemTempDirectory() ``` -------------------------------- ### Add user data to the notice with addFilter Source: https://github.com/airbrake/phpbrake/blob/master/README.md Uses addFilter to populate the notice's context user fields with a name, email, and id. The filter must return the modified notice. ```php $notifier->addFilter(function ($notice) { $notice['context']['user']['name'] = 'Avocado Jones'; $notice['context']['user']['email'] = 'AJones@guacamole.com'; $notice['context']['user']['id'] = 12345; return $notice; }); ```