Last active
August 29, 2015 14:27
-
-
Save cspray/83914ed57e6eb2621013 to your computer and use it in GitHub Desktop.
labrador.cspray.net quick-start example
This file contains hidden or 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 | |
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