22
33namespace React \Filesystem ;
44
5+ use RuntimeException ;
56use React \EventLoop \LoopInterface ;
67use React \Filesystem \Node ;
78
@@ -16,14 +17,18 @@ class Filesystem implements FilesystemInterface
1617 * @param LoopInterface $loop
1718 * @param array $options
1819 * @return FilesystemInterface
20+ * @throws RuntimeException
1921 */
2022 public static function create (LoopInterface $ loop , array $ options = [])
2123 {
22- if (extension_loaded ('eio ' )) {
23- return static ::setFilesystemOnAdapter (static ::createFromAdapter (new Eio \Adapter ($ loop , $ options )));
24+ $ adapters = static ::getSupportedAdapters ();
25+
26+ if (!empty ($ adapters )) {
27+ $ adapter = "\\React \\Filesystem \\" .$ adapters [0 ]."\\Adapter " ;
28+ return static ::setFilesystemOnAdapter (static ::createFromAdapter (new $ adapter ($ loop , $ options )));
2429 }
2530
26- return static :: setFilesystemOnAdapter ( static :: createFromAdapter ( new ChildProcess \ Adapter ( $ loop , $ options )) );
31+ throw new RuntimeException ( ' No supported adapter found for this installation ' );
2732 }
2833
2934 /**
@@ -45,6 +50,24 @@ protected static function setFilesystemOnAdapter(FilesystemInterface $filesystem
4550 return $ filesystem ;
4651 }
4752
53+ /**
54+ * @return string[]
55+ */
56+ public static function getSupportedAdapters ()
57+ {
58+ $ adapters = [];
59+
60+ if (Eio \Adapter::isSupported ()) {
61+ $ adapters [] = 'Eio ' ;
62+ }
63+
64+ if (ChildProcess \Adapter::isSupported ()) {
65+ $ adapters [] = 'ChildProcess ' ;
66+ }
67+
68+ return $ adapters ;
69+ }
70+
4871 /**
4972 * Filesystem constructor.
5073 * @param AdapterInterface $adapter
0 commit comments