/** * Build singleton instance storage engine. * * @param string $engine * @param string $host * @param int $port * @param string $database * @param string|null $user * @param string|null $pass * * @return StorageInterface */ public static function instance($engine, $host, $port, $database, $user = null, $pass = null) { if (!isset(self::$instances[$engine])) { $engine = new StorageManager($engine, $host, $port, $database, $user, $pass); return $engine->getEngine(); } return self::$instances[$engine]; }
public function __construct() { parent::__construct(); /** @var Pdo $storage */ $this->storage = $storage = StorageManager::instance('mysql', 'localhost', 5432, 'app', 'root', 'root'); $storage->exec('DROP TABLE IF EXISTS People'); $storage->exec('DROP TABLE IF EXISTS ClassRoom'); $storage->exec(' CREATE TABLE People( id CHAR(13) PRIMARY KEY, studentName VARCHAR(150) NOT NULL, age INT(10) NOT NULL ); '); $storage->exec(' CREATE TABLE ClassRoom( id CHAR(13) PRIMARY KEY, lesson VARCHAR(150) NOT NULL, peopleId CHAR(13) NOT NULL ); '); $this->people = new People('55d40f0064dcd', 'Ibal', 10); $this->storage->save($this->people, 'People'); $this->people = new People('55d40f0064dcc', 'Iqbal', 25); $this->storage->save($this->people, 'People'); }
public function __construct() { parent::__construct(); $this->bus = $bus = new QueryBus(); $bus->register('Borobudur\\Cqrs\\Test\\AllMovieQuery', 'Borobudur\\Cqrs\\Test\\AllMovieQueryHandler'); $bus->register('Borobudur\\Cqrs\\Test\\DetailMovieQuery', 'Borobudur\\Cqrs\\Test\\DetailMovieQueryHandler'); /** @var Pdo $storage */ $this->storage = $storage = StorageManager::instance('mysql', 'localhost', 5432, 'app', 'root'); self::$repository = new MovieRepository($this->storage); $storage->exec('DROP TABLE IF EXISTS Movie'); $storage->exec(' CREATE TABLE Movie( id CHAR(13) PRIMARY KEY, name VARCHAR(100) NOT NULL, schedule DATETIME NOT NULL, price INT NULL, buyers INT NULL, deleted INT(1) NOT NULL ); '); $data = array(array('name' => 'San Andreas', 'schedule' => new \DateTime(), 'price' => 25000, 'buyers' => 5), array('name' => 'Godzila', 'schedule' => new \DateTime(), 'price' => 30000, 'buyers' => 1), array('name' => 'Social Network', 'schedule' => new \DateTime('+1 month'), 'price' => 50000, 'buyers' => 6), array('name' => 'Pixed', 'schedule' => new \DateTime('+1 day'), 'price' => 100000, 'buyers' => 10), array('name' => 'Ace ventura', 'schedule' => new \DateTime('-1 month'), 'price' => 80000, 'buyers' => 3)); foreach ($data as $record) { self::$repository->save(new MovieReadModel(uniqid(), $record['name'], $record['schedule']->format('Y-m-d H:i:s'), $record['price'], $record['buyers'])); } }
public function __construct() { parent::__construct(); /** @var Pdo $storage */ $this->storage = $storage = StorageManager::instance('mysql', 'localhost', 3128, 'app', 'root', 'root'); $storage->exec('DROP TABLE IF EXISTS ClassRoom'); $storage->exec(' CREATE TABLE ClassRoom( id CHAR(13) PRIMARY KEY, lesson VARCHAR(150) NOT NULL, studentName VARCHAR(150) NOT NULL, age FLOAT NOT NULL ); '); }
public function __construct() { parent::__construct(); /** @var Pdo $storage */ $this->storage = $storage = StorageManager::instance('mysql', 'localhost', 5432, 'app', 'root'); $this->repository = new StudentRepository($this->storage); $storage->exec('DROP TABLE IF EXISTS Student'); $storage->exec(' CREATE TABLE Student( id CHAR(13) PRIMARY KEY, studentName VARCHAR(100) NOT NULL, classRoom CHAR(2) NOT NULL, major VARCHAR(50) NOT NULL ); '); }
/** * Build read model storage. * * @param array $config * * @return StorageInterface */ private function buildReadModelStorage(array $config) { return function () use($config) { return ReadModelStorageManager::instance($config['engine'], $config['host'], $config['port'], $config['database'], $config['username'], $config['password']); }; }