Last active
December 10, 2018 12:47
-
-
Save alister/8e3aa440c08b16c6ed48a0e52ff977d5 to your computer and use it in GitHub Desktop.
Sample use of Tombstones
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// ... other code - but NOT requireing 'vendor/autoload.php' | |
define('SRC_ROOT', __DIR__.'/../src'); | |
define('TOMBSTONE_LOG', dirname(__DIR__)."/var/logs/tombstones.log"); | |
use \Scheb\Tombstone\Tracing\TraceProvider; | |
use \Scheb\Tombstone\GraveyardProvider; | |
use \Scheb\Tombstone\Handler\StreamHandler; | |
if (!function_exists('tombstone')) { | |
/** | |
* @param string $date Any date format strtotime() understands | |
* @param string $author Your name | |
* @param string|null $label An optional label for the tombstone | |
*/ | |
function tombstone($date, $author, $label = null) { | |
try { | |
$trace = TraceProvider::getTraceHere(); | |
GraveyardProvider::getGraveyard()->setSourceDir(SRC_ROOT); | |
$streamHandler = new StreamHandler(TOMBSTONE_LOG); | |
GraveyardProvider::getGraveyard()->addHandler($streamHandler); | |
GraveyardProvider::getGraveyard()->tombstone($date, $author, $label, $trace); | |
// in dev, we `dump() and die` here. | |
} catch (\Exception $e) { | |
// in production - we swallow any errors from the Tombstone system | |
} | |
} | |
} | |
require '/../vendor/autoload.php'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace DemoCode; | |
class MightBeDead | |
{ | |
public function tombstoneExample() | |
{ | |
tombstone('2017-08-26', 'ab'); | |
// this function might be redundant | |
return false; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment