Skip to content

Instantly share code, notes, and snippets.

@cspray
Last active August 29, 2015 14:27
Show Gist options
  • Save cspray/83914ed57e6eb2621013 to your computer and use it in GitHub Desktop.
Save cspray/83914ed57e6eb2621013 to your computer and use it in GitHub Desktop.
labrador.cspray.net quick-start example
<?php
require_once __DIR__ . '/vendor/autoload.php';
use Cspray\Labrador\Services;
use Cspray\Labrador\Engine;
use Cspray\Labrador\Event\ExceptionThrownEvent;
/** @var Auryn\Injector $injector */
$injector = (new Services)->createInjector();
/** @var Cspray\Labrador\CoreEngine $engine */
$engine = $injector->make(Engine::class);
$engine->onEnvironmentInitialize(function() {
echo "Environment initialize\n";
});
$engine->onAppExecute(function() {
echo "Perform your app logic\n";
});
$engine->onAppExecute(function() {
throw new Exception('oops');
});
$engine->onAppCleanup(function() {
echo "Cleanup your app, runs even on exception\n";
echo "Check out https://labrador.cspray.net for more information";
});
$engine->onExceptionThrown(function(ExceptionThrownEvent $event) {
$exc = get_class($event->getException());
$msg = $event->getException()->getMessage();
echo "Handle exception of type {$exc} with message \"{$msg}\"\n";
});
$engine->run();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment