@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -require_once __DIR__.'/../vendor/autoload.php'; |
|
2 | +require_once __DIR__ . '/../vendor/autoload.php'; |
|
3 | 3 | |
4 | 4 | use Dazzle\Loop\Loop; |
5 | 5 | use Dazzle\Loop\Model\SelectLoop; |
@@ -18,12 +18,12 @@ discard block |
||
18 | 18 | 'dbname' => 'postgres' |
19 | 19 | ]); |
20 | 20 | |
21 | -$db->start()->then(function (Connection $conn) use ($loop) { |
|
22 | - $conn->query('select \'ok\'')->then(function (Tuple $ret) use ($loop) { |
|
21 | +$db->start()->then(function(Connection $conn) use ($loop) { |
|
22 | + $conn->query('select \'ok\'')->then(function(Tuple $ret) use ($loop) { |
|
23 | 23 | print_r($ret->fetchRow()); |
24 | 24 | }); |
25 | - $conn->prepare('select \'ok\'')->then(function (Prepared $prepared) use ($loop) { |
|
26 | - $prepared->execPreparedStmt()->then(function (TupleResultStatement $ret) use ($loop) { |
|
25 | + $conn->prepare('select \'ok\'')->then(function(Prepared $prepared) use ($loop) { |
|
26 | + $prepared->execPreparedStmt()->then(function(TupleResultStatement $ret) use ($loop) { |
|
27 | 27 | print_r($ret->fetchRow()); |
28 | 28 | $loop->stop(); |
29 | 29 | }); |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -require_once __DIR__.'/../vendor/autoload.php'; |
|
2 | +require_once __DIR__ . '/../vendor/autoload.php'; |
|
3 | 3 | |
4 | 4 | use Dazzle\Loop\Loop; |
5 | 5 | use Dazzle\PgSQL\Database; |
@@ -18,29 +18,29 @@ discard block |
||
18 | 18 | 'dbname' => 'postgres' |
19 | 19 | ]); |
20 | 20 | |
21 | -$db->on('transaction:begin', function () use ($loop, $db) { |
|
22 | - echo 'Transaction Stated'.PHP_EOL; |
|
21 | +$db->on('transaction:begin', function() use ($loop, $db) { |
|
22 | + echo 'Transaction Stated' . PHP_EOL; |
|
23 | 23 | }); |
24 | 24 | |
25 | -$db->on('transaction:end', function () use ($loop, $db) { |
|
26 | - $db->getConnection()->then(function (ConnectionInterface $conn) use ($loop) { |
|
25 | +$db->on('transaction:end', function() use ($loop, $db) { |
|
26 | + $db->getConnection()->then(function(ConnectionInterface $conn) use ($loop) { |
|
27 | 27 | $conn->query('select * from demo order by id desc limit 1') |
28 | - ->then(function (TupleResultStatement $tuple) use ($loop) { |
|
28 | + ->then(function(TupleResultStatement $tuple) use ($loop) { |
|
29 | 29 | print_r($tuple->fetchAll()); |
30 | 30 | $loop->stop(); |
31 | - echo 'Transaction End'.PHP_EOL; |
|
31 | + echo 'Transaction End' . PHP_EOL; |
|
32 | 32 | }); |
33 | 33 | }); |
34 | 34 | }); |
35 | 35 | |
36 | 36 | $db->beginTransaction() |
37 | - ->then(function (TransactionInterface $trans) use ($loop) { |
|
37 | + ->then(function(TransactionInterface $trans) use ($loop) { |
|
38 | 38 | $trans->query('select * from demo order by id desc limit 1') |
39 | - ->then(function (TupleResultStatement $tuple) { |
|
39 | + ->then(function(TupleResultStatement $tuple) { |
|
40 | 40 | print_r($tuple->fetchAll()); |
41 | 41 | }); |
42 | 42 | $trans->execute('insert into demo default values') |
43 | - ->then(function (CommandResult $result) use ($trans) { |
|
43 | + ->then(function(CommandResult $result) use ($trans) { |
|
44 | 44 | if ($result->getAffectedRows() > 0) { |
45 | 45 | $trans->rollback(); |
46 | 46 | } |
@@ -8,7 +8,7 @@ discard block |
||
8 | 8 | use Dazzle\PgSQL\Transaction\Transaction; |
9 | 9 | use Dazzle\Promise\Promise; |
10 | 10 | use Dazzle\Throwable\Exception; |
11 | -use Dazzle\PgSQL\Transaction\TransactionInterface ; |
|
11 | +use Dazzle\PgSQL\Transaction\TransactionInterface; |
|
12 | 12 | use Dazzle\Throwable\Exception\Runtime\ExecutionException; |
13 | 13 | |
14 | 14 | class Database extends BaseEventEmitter implements DatabaseInterface |
@@ -18,42 +18,42 @@ discard block |
||
18 | 18 | /** |
19 | 19 | * @var int |
20 | 20 | */ |
21 | - const STATE_INIT = 0; |
|
21 | + const STATE_INIT = 0; |
|
22 | 22 | |
23 | 23 | /** |
24 | 24 | * @var int |
25 | 25 | */ |
26 | - const STATE_CONNECT_PENDING = 4; |
|
26 | + const STATE_CONNECT_PENDING = 4; |
|
27 | 27 | |
28 | 28 | /** |
29 | 29 | * @var int |
30 | 30 | */ |
31 | - const STATE_CONNECT_FAILED = 2; |
|
31 | + const STATE_CONNECT_FAILED = 2; |
|
32 | 32 | |
33 | 33 | /** |
34 | 34 | * @var int |
35 | 35 | */ |
36 | - const STATE_CONNECT_SUCCEEDED = 6; |
|
36 | + const STATE_CONNECT_SUCCEEDED = 6; |
|
37 | 37 | |
38 | 38 | /** |
39 | 39 | * @var int |
40 | 40 | */ |
41 | - const STATE_AUTH_PENDING = 5; |
|
41 | + const STATE_AUTH_PENDING = 5; |
|
42 | 42 | |
43 | 43 | /** |
44 | 44 | * @var int |
45 | 45 | */ |
46 | - const STATE_AUTH_FAILED = 3; |
|
46 | + const STATE_AUTH_FAILED = 3; |
|
47 | 47 | |
48 | 48 | /** |
49 | 49 | * @var int |
50 | 50 | */ |
51 | - const STATE_AUTH_SUCCEEDED = 7; |
|
51 | + const STATE_AUTH_SUCCEEDED = 7; |
|
52 | 52 | |
53 | 53 | /** |
54 | 54 | * @var int |
55 | 55 | */ |
56 | - const STATE_DISCONNECT_PENDING = 8; |
|
56 | + const STATE_DISCONNECT_PENDING = 8; |
|
57 | 57 | |
58 | 58 | /** |
59 | 59 | * @var int |
@@ -203,7 +203,7 @@ discard block |
||
203 | 203 | return Promise::doResolve($trans); |
204 | 204 | } |
205 | 205 | //bad method: append 1 callback |
206 | - return $this->start()->success(function ($_) { |
|
206 | + return $this->start()->success(function($_) { |
|
207 | 207 | $trans = new Transaction($this->connector, $this); |
208 | 208 | |
209 | 209 | return $trans->begin(); |
@@ -24,7 +24,7 @@ discard block |
||
24 | 24 | |
25 | 25 | public function __construct($config) |
26 | 26 | { |
27 | - $this->stream = pg_connect($config, \PGSQL_CONNECT_ASYNC|\PGSQL_CONNECT_FORCE_NEW); |
|
27 | + $this->stream = pg_connect($config, \PGSQL_CONNECT_ASYNC | \PGSQL_CONNECT_FORCE_NEW); |
|
28 | 28 | $this->conn = new Connection(); |
29 | 29 | } |
30 | 30 | |
@@ -45,7 +45,7 @@ discard block |
||
45 | 45 | $promise = $this->conn->getPromise(); |
46 | 46 | |
47 | 47 | return $promise |
48 | - ->success(function (ConnectorInterface $connector) use ($connection) { |
|
48 | + ->success(function(ConnectorInterface $connector) use ($connection) { |
|
49 | 49 | $connection->setConnector($connector); |
50 | 50 | |
51 | 51 | return $connection; |
@@ -63,7 +63,7 @@ discard block |
||
63 | 63 | return Promise::doResolve($this); |
64 | 64 | } |
65 | 65 | |
66 | - return $this->connector->execute('BEGIN')->success(function (CommandResultStatement $result) { |
|
66 | + return $this->connector->execute('BEGIN')->success(function(CommandResultStatement $result) { |
|
67 | 67 | if ($result) { |
68 | 68 | $this->emitter->emit('transaction:begin'); |
69 | 69 | } |
@@ -78,7 +78,7 @@ discard block |
||
78 | 78 | */ |
79 | 79 | public function commit() |
80 | 80 | { |
81 | - return $this->connector->execute('COMMIT')->success(function (CommandResultStatement $result) { |
|
81 | + return $this->connector->execute('COMMIT')->success(function(CommandResultStatement $result) { |
|
82 | 82 | if ($result) { |
83 | 83 | $this->emitter->emit('transaction:end'); |
84 | 84 | } |
@@ -93,7 +93,7 @@ discard block |
||
93 | 93 | */ |
94 | 94 | public function rollback() |
95 | 95 | { |
96 | - return $this->connector->execute('ROLLBACK')->success(function (CommandResultStatement $result) { |
|
96 | + return $this->connector->execute('ROLLBACK')->success(function(CommandResultStatement $result) { |
|
97 | 97 | if ($result) { |
98 | 98 | $this->emitter->emit('transaction:end'); |
99 | 99 | } |
@@ -1,7 +1,7 @@ |
||
1 | 1 | <?php |
2 | 2 | namespace Dazzle\PgSQL\Result; |
3 | 3 | |
4 | -interface Result extends CommandResultStatement,TupleResultStatement |
|
4 | +interface Result extends CommandResultStatement, TupleResultStatement |
|
5 | 5 | { |
6 | 6 | |
7 | 7 | } |
8 | 8 | \ No newline at end of file |
@@ -16,7 +16,7 @@ |
||
16 | 16 | |
17 | 17 | public function getParams() |
18 | 18 | { |
19 | - return $this->params?:[]; |
|
19 | + return $this->params ?: []; |
|
20 | 20 | } |
21 | 21 | |
22 | 22 | public function setSQL($sql) |
@@ -4,7 +4,7 @@ |
||
4 | 4 | use Dazzle\PgSQL\Connection\ConnectorInterface; |
5 | 5 | use Dazzle\Promise\DeferredInterface; |
6 | 6 | |
7 | -interface Statement extends DeferredInterface,StatementHandler |
|
7 | +interface Statement extends DeferredInterface, StatementHandler |
|
8 | 8 | { |
9 | 9 | public function getSQL(); |
10 | 10 | public function setSQL($sql); |