@@ -67,6 +67,17 @@ public function __construct(LoopInterface $loop)
6767 * });
6868 * ```
6969 *
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+ *
7081 * The optional `$flags` parameter is used to determine how to open the
7182 * SQLite database. By default, open uses `SQLITE3_OPEN_READWRITE | SQLITE3_OPEN_CREATE`.
7283 *
@@ -85,6 +96,7 @@ public function __construct(LoopInterface $loop)
8596 */
8697 public function open ($ filename , $ flags = null )
8798 {
99+ $ filename = $ this ->resolve ($ filename );
88100 return $ this ->useSocket ? $ this ->openSocketIo ($ filename , $ flags ) : $ this ->openProcessIo ($ filename , $ flags );
89101 }
90102
@@ -135,6 +147,17 @@ public function open($filename, $flags = null)
135147 * underlying `open()` method which resolves with a promise. For many
136148 * simple use cases it may be easier to create a lazy connection.
137149 *
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+ *
138161 * The optional `$flags` parameter is used to determine how to open the
139162 * SQLite database. By default, open uses `SQLITE3_OPEN_READWRITE | SQLITE3_OPEN_CREATE`.
140163 *
@@ -162,7 +185,7 @@ public function open($filename, $flags = null)
162185 */
163186 public function openLazy ($ filename , $ flags = null , array $ options = [])
164187 {
165- return new LazyDatabase ($ filename , $ flags , $ options , $ this , $ this ->loop );
188+ return new LazyDatabase ($ this -> resolve ( $ filename) , $ flags , $ options , $ this , $ this ->loop );
166189 }
167190
168191 private function openProcessIo ($ filename , $ flags = null )
@@ -318,4 +341,16 @@ private function which($bin)
318341 }
319342 return null ;
320343 }
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+ }
321356}
0 commit comments