PHP code example of timefrontiers / php-has-errors

1. Go to this page and download the library: Download timefrontiers/php-has-errors library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

timefrontiers / php-has-errors example snippets


/** @var array{0: int, 1: int, 2: string, 3: string, 4: int} $error */
$error = [$minimumRank, $code, $message, $file, $line];

/** @var array<string, list<array{0: int, 1: int, 2: string, 3: string, 4: int}>> $errors */
$errors = ['save' => [$error]];

use TimeFrontiers\Contract\ErrorProvider;
use TimeFrontiers\Helper\HasErrors;

final class ImportService implements ErrorProvider
{
    use HasErrors;

    public function import(array $records): bool
    {
        if ($records === []) {
            $this->_userError('import', 'Select at least one record.');
            return false;
        }

        return true;
    }
}

use TimeFrontiers\AccessRank;

$this->_addError(
    context: 'save',
    message: 'Persistence operation failed; see the protected log reference.',
    min_rank: AccessRank::DEVELOPER->value,
    code: E_USER_ERROR,
);

$messages = $service->publicErrorMessages('import');
$first = $service->firstPublicError('import');

// One source context, retaining its name.
$this->_mergeErrors($repository, 'save');

// One source context renamed for the receiver.
$this->_mergeErrors($repository, 'save', 'create');

// All source contexts flattened in deterministic order into "merged".
$this->_mergeErrors($repository);

// All source contexts flattened into an explicit target.
$this->_mergeErrors($repository, '', 'create');

$all = $service->getErrors();
$hasAny = $service->hasErrors();
$hasSave = $service->hasErrors('save');
$count = $service->errorCount('save');

$firstDiagnostic = $service->firstError('save');
$guestRankedDiagnostics = $service->errorMessages(
    'save',
    AccessRank::GUEST->value,
);

$service->clearErrors('save');
$service->clearErrors();
bash
composer