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/ */
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,
);
// 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');