Ejemplo n.º 1
0
// Event Dispatcher Listener ... ish
function thisIsMyListener(Event $event)
{
    echo "Hello, I am the Symfony2 Event Dispatcher Listener!" . PHP_EOL;
    var_dump($event->event());
}
// Now create our integration class and pass in the dispatcher
$symfony2EventDispatcherSubscriber = new symfony2EventDispatcherSubscriber($symfony2EventDispatcher);
// We need an EventStore. We'll use the DBAL with in-memory sqlite
$eventStore = DBALEventStore::createWithOptions('events', ['driver' => 'pdo_sqlite', 'memory' => true]);
// Register :D
$eventStore->registerEventSubscriber($symfony2EventDispatcherSubscriber);
// Create the table we need
$eventStore->createTable();
// Initialise a repository with this event store
$userRepository = new UserRepository($eventStore);
// Create a user
$user = User::createWithUsername("David");
// We can output the users username and there's no sign of an event
//  event anywhere! Nifty
echo "Hello, {$user->username()}!" . PHP_EOL;
// We can even save this user, still no mention of an event
$userRepository->save($user);
// Lets backup the identifier so that we can discard and reload
$userIdentifier = $user->identifier();
unset($user);
// Load the user from the EventStore, using our repository
$user = $userRepository->load($userIdentifier);
// Viola!
echo "Hello, {$user->username()}!" . PHP_EOL;
var_dump($user);
Ejemplo n.º 2
0
<?php

require_once '../autoloader.php';
use example\UserRepository;
$conn = new \PDO('mysql:host=localhost;dbname=testar;', 'root', '', array(\PDO::FETCH_OBJ));
$conn->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
$ipRepository = new \annotation\repository\PDORepository("\\example\\IPLog", $conn);
$userRepository = new UserRepository($conn);
debug($userRepository->find(11));