@@ -67,6 +67,17 @@ public function __construct(LoopInterface $loop)
67
67
* });
68
68
* ```
69
69
*
70
+ * The `$filename` parameter is the path to the SQLite database file or
71
+ * `:memory:` to create a temporary in-memory database. As of PHP 7.0.10, an
72
+ * empty string can be given to create a private, temporary on-disk database.
73
+ * Relative paths will be resolved relative to the current working directory,
74
+ * so it's usually recommended to pass absolute paths instead to avoid any
75
+ * ambiguity.
76
+ *
77
+ * ```php
78
+ * $promise = $factory->open(__DIR__ . '/users.db');
79
+ * ```
80
+ *
70
81
* The optional `$flags` parameter is used to determine how to open the
71
82
* SQLite database. By default, open uses `SQLITE3_OPEN_READWRITE | SQLITE3_OPEN_CREATE`.
72
83
*
@@ -85,6 +96,7 @@ public function __construct(LoopInterface $loop)
85
96
*/
86
97
public function open ($ filename , $ flags = null )
87
98
{
99
+ $ filename = $ this ->resolve ($ filename );
88
100
return $ this ->useSocket ? $ this ->openSocketIo ($ filename , $ flags ) : $ this ->openProcessIo ($ filename , $ flags );
89
101
}
90
102
@@ -135,6 +147,17 @@ public function open($filename, $flags = null)
135
147
* underlying `open()` method which resolves with a promise. For many
136
148
* simple use cases it may be easier to create a lazy connection.
137
149
*
150
+ * The `$filename` parameter is the path to the SQLite database file or
151
+ * `:memory:` to create a temporary in-memory database. As of PHP 7.0.10, an
152
+ * empty string can be given to create a private, temporary on-disk database.
153
+ * Relative paths will be resolved relative to the current working directory,
154
+ * so it's usually recommended to pass absolute paths instead to avoid any
155
+ * ambiguity.
156
+ *
157
+ * ```php
158
+ * $db = $factory->openLazy(__DIR__ . '/users.db');
159
+ * ```
160
+ *
138
161
* The optional `$flags` parameter is used to determine how to open the
139
162
* SQLite database. By default, open uses `SQLITE3_OPEN_READWRITE | SQLITE3_OPEN_CREATE`.
140
163
*
@@ -162,7 +185,7 @@ public function open($filename, $flags = null)
162
185
*/
163
186
public function openLazy ($ filename , $ flags = null , array $ options = [])
164
187
{
165
- return new LazyDatabase ($ filename , $ flags , $ options , $ this , $ this ->loop );
188
+ return new LazyDatabase ($ this -> resolve ( $ filename) , $ flags , $ options , $ this , $ this ->loop );
166
189
}
167
190
168
191
private function openProcessIo ($ filename , $ flags = null )
@@ -318,4 +341,16 @@ private function which($bin)
318
341
}
319
342
return null ;
320
343
}
344
+
345
+ /**
346
+ * @param string $filename
347
+ * @return string
348
+ */
349
+ private function resolve ($ filename )
350
+ {
351
+ if ($ filename !== '' && $ filename !== ':memory: ' && !\preg_match ('/^\/|\w+\: \\\\/ ' , $ filename )) {
352
+ $ filename = \getcwd () . \DIRECTORY_SEPARATOR . $ filename ;
353
+ }
354
+ return $ filename ;
355
+ }
321
356
}
0 commit comments