Skip to content

Commit e4e9107

Browse files
committed
mini cleanup of examples
1 parent 43aa00f commit e4e9107

File tree

4 files changed

+25
-47
lines changed

4 files changed

+25
-47
lines changed

examples/collection.php

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,7 @@
22

33
namespace triagens\Avocado;
44

5-
require dirname(__FILE__) . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'autoload.php';
6-
7-
/* set up a trace function that will be called for each communication with the server */
8-
$traceFunc = function($type, $data) {
9-
print "TRACE FOR ". $type . PHP_EOL;
10-
var_dump($data);
11-
};
12-
13-
/* set up connection options */
14-
$connectionOptions = array(
15-
ConnectionOptions::OPTION_PORT => 9000,
16-
ConnectionOptions::OPTION_HOST => "localhost",
17-
ConnectionOptions::OPTION_TIMEOUT => 3,
18-
ConnectionOptions::OPTION_TRACE => $traceFunc,
19-
ConnectionOptions::OPTION_CREATE => false,
20-
ConnectionOptions::OPTION_UPDATE_POLICY => "last",
21-
);
5+
require dirname(__FILE__) . DIRECTORY_SEPARATOR . 'init.php';
226

237
try {
248
$connection = new Connection($connectionOptions);

examples/document.php

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,8 @@
22

33
namespace triagens\Avocado;
44

5-
require dirname(__FILE__) . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'autoload.php';
5+
require dirname(__FILE__) . DIRECTORY_SEPARATOR . 'init.php';
66

7-
/* set up a trace function that will be called for each communication with the server */
8-
$traceFunc = function($type, $data) {
9-
print "TRACE FOR ". $type . PHP_EOL;
10-
var_dump($data);
11-
};
12-
13-
/* set up connection options */
14-
$connectionOptions = array(
15-
ConnectionOptions::OPTION_PORT => 9000, // port to connect to
16-
ConnectionOptions::OPTION_HOST => "localhost", // host to connect to
17-
ConnectionOptions::OPTION_TIMEOUT => 3, // timeout in seconds
18-
ConnectionOptions::OPTION_TRACE => $traceFunc, // tracer function
19-
ConnectionOptions::OPTION_CREATE => false, // do not create unknown collections automatically
20-
ConnectionOptions::OPTION_UPDATE_POLICY => UpdatePolicy::LAST, // last update wins
21-
);
227

238
try {
249
$connection = new Connection($connectionOptions);

examples/init.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
3+
namespace triagens\Avocado;
4+
5+
require dirname(__FILE__) . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'autoload.php';
6+
7+
/* set up a trace function that will be called for each communication with the server */
8+
$traceFunc = function($type, $data) {
9+
print "TRACE FOR ". $type . PHP_EOL;
10+
var_dump($data);
11+
};
12+
13+
/* set up connection options */
14+
$connectionOptions = array(
15+
ConnectionOptions::OPTION_PORT => 8529, // port to connect to
16+
ConnectionOptions::OPTION_HOST => "localhost", // host to connect to
17+
ConnectionOptions::OPTION_TIMEOUT => 3, // timeout in seconds
18+
ConnectionOptions::OPTION_TRACE => $traceFunc, // tracer function
19+
ConnectionOptions::OPTION_CREATE => false, // do not create unknown collections automatically
20+
ConnectionOptions::OPTION_UPDATE_POLICY => UpdatePolicy::LAST, // last update wins
21+
);
22+

examples/select.php

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace triagens\Avocado;
44

5-
require dirname(__FILE__) . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'autoload.php';
5+
require dirname(__FILE__) . DIRECTORY_SEPARATOR . 'init.php';
66

77
/* set up some example statements */
88
$statements = array(
@@ -17,19 +17,6 @@
1717
"select u from users u where u.id == @id@ && u.name != @name@" => array("id" => 6, "name" => "fux"),
1818
);
1919

20-
/* set up a trace function that will be called for each communication with the server */
21-
$traceFunc = function($type, $data) {
22-
print "TRACE FOR ". $type . PHP_EOL;
23-
var_dump($data);
24-
};
25-
26-
/* set up connection options */
27-
$connectionOptions = array(
28-
ConnectionOptions::OPTION_PORT => 9000,
29-
ConnectionOptions::OPTION_HOST => "localhost",
30-
ConnectionOptions::OPTION_TIMEOUT => 3,
31-
ConnectionOptions::OPTION_TRACE => $traceFunc,
32-
);
3320

3421
try {
3522
$connection = new Connection($connectionOptions);

0 commit comments

Comments
 (0)