PHP code example of coercive / fatalnotifyer

1. Go to this page and download the library: Download coercive/fatalnotifyer 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/ */

    

coercive / fatalnotifyer example snippets



use Coercive\Utility\FatalNotifyer\FatalNotifyer;

# Instanciate
$oFatal = new FatalNotifyer;

# Display errors or not
$oFatal->displayError(true || false);

# Set your own email subject, with your project name for example
$oFatal->setMailSubject('Hello, an error occured on my website');

# Add your email(s) and error list to send
$oFatal->mail('[email protected]');
$oFatal->mail(['[email protected]', '[email protected]']);
$oFatal->mail('[email protected]', E_COMPILE_ERROR);
$oFatal->mail('[email protected]', E_NOTICE | E_USER_NOTICE);
	// ...

# Or just notify (not the full backtrace but short message)
$oFatal->notify('[email protected]');
$oFatal->notify(['[email protected]', '[email protected]'], E_NOTICE | E_USER_NOTICE);

# Register type error for internal class handle
$oFatal->register(E_FATAL);

	// E_ERROR, E_WARNING, E_PARSE, E_NOTICE, E_CORE_ERROR,
	// E_CORE_WARNING, E_COMPILE_ERROR, E_COMPILE_WARNING,
	// E_USER_ERROR:, E_USER_WARNING, E_USER_NOTICE, E_STRICT,
	// E_RECOVERABLE_ERROR, E_DEPRECATED, E_USER_DEPRECATED

# Save type error in personal file
$oFatal->save('/my/personal/log/directory/fatal', E_FATAL);
$oFatal->save('/my/personal/log/directory/notice', E_NOTICE);
// See after for explore errors datas


# You can try an autotest for 3 errors type
FatalNotifyer::autoTest();

# And you have a reset function
FatalNotifyer::reset();


use Coercive\Utility\FatalNotifyer\FatalLog;

# For example, you can imagine an ajax system that retrieve error list ...

# Load
$oLog = new FatalLog('/my/personal/log/directory/fatal');

# Retreive days list directories
# ['2017-07-22', '2017-07-21', '2017-07-20', ...]

$aDays = $oLog->getDayList();

# Retreive file list by directories
# ['2017-07-22' => ['15_14_57', '15_14_58', ...], ...]

$aLists = [];
foreach ($aDays as $sDay) {
	$aLists[$sDay] = $oLog->getFileList($sDay);
}

# Retrieve one (example)

$oLog->getOne("/my/personal/log/directory/fatal/2017-07-22/15_14_57");

# Loop retrieve (example)

$aErrors = [];
foreach ($aLists as $sDay => $aFiles) {
	foreach ($aFiles as $sFile) {
		$aErrors[$sDay . '@' . $sFile] = $oLog->getOne("/my/personal/log/directory/fatal/$sDay/$sFile");
	}
}

# See results

echo '<pre>';
var_dump($aDays);
var_dump($aLists);
var_dump($aErrors);
echo '</pre>';