/** * @inheritdoc * * @param Task $task */ public function handle(Task $task) { $config = $task->getData(); if ($config["driver"] === "mysql") { $config += ["host" => "127.0.0.1", "port" => 3306, "charset" => "utf8", "socket" => null]; } if ($config["remit"]["driver"] === "zeromq") { $config["remit"]["server"] += ["host" => "127.0.0.1"]; $config["remit"]["client"] += ["host" => "127.0.0.1"]; $server = new ZeroMqServer(new InMemoryLocation($config["remit"]["client"]["host"], $config["remit"]["client"]["port"])); $client = new ZeroMqClient(new InMemoryLocation($config["remit"]["server"]["host"], $config["remit"]["server"]["port"])); } $connection = new ExtendedPdo(new PDO($this->newConnectionString($config), $config["username"], $config["password"])); $server->addListener("q", function ($query, $values, $id) use($client, $connection) { $client->emit("r", [$connection->fetchAll($query, $values), $id]); }); $server->addListener("d", function () use($connection, $server, $client) { $client->emit("dd"); try { $connection->disconnect(); } catch (Exception $exception) { // TODO: find an elegant way to deal with this } $server->disconnect(); $client->disconnect(); Loop\stop(); }); Loop\periodic(0, function () use($server) { $server->tick(); }); Loop\run(); }
/** * Returns all the results in the table that match the specified criteria * Criteria must be an array, with the DB column the key and the DB value the value * * @param array $criteria Search criteria * @param string $table Table to search against * @param string $order SQL order clause * @return array */ public function fetchAllBy($criteria, $table, $order = 'id ASC') { $select = $this->buildSelectQuery($table, $criteria, array('*'), $order); return $this->db->fetchAll($select->__toString(), $select->getBindValues()); }
/** * @inheritdoc * * @param string $query * @param array $values * * @return PromiseInterface * * @throws InvalidArgumentException */ public function query($query, $values) { return Promise\resolve($this->connection->fetchAll($query, $values)); }