Skip to content

Commit 63d9a10

Browse files
committed
Unified driver create methods
1 parent e480312 commit 63d9a10

File tree

3 files changed

+63
-41
lines changed

3 files changed

+63
-41
lines changed

src/Bolt/BoltDriver.php

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -62,36 +62,42 @@ public function __construct(
6262
$this->formatter = $formatter;
6363
}
6464

65-
/**
66-
* @param string|UriInterface $uri
67-
*
68-
* @return self<OGMResults>
69-
*/
70-
public static function create($uri, ?DriverConfiguration $configuration = null, ?AuthenticateInterface $authenticate = null): self
71-
{
72-
return self::createWithFormatter($uri, OGMFormatter::create(), $configuration, $authenticate);
73-
}
74-
7565
/**
7666
* @template U
7767
*
78-
* @param string|UriInterface $uri
7968
* @param FormatterInterface<U> $formatter
69+
* @param string|UriInterface $uri
8070
*
81-
* @return self<U>
71+
* @return (
72+
* func_num_args() is 4
73+
* ? self<U>
74+
* : self<OGMResults>
75+
* )
76+
* @psalm-mutation-free
8277
*/
83-
public static function createWithFormatter($uri, FormatterInterface $formatter, ?DriverConfiguration $configuration = null, ?AuthenticateInterface $authenticate = null): self
78+
public static function create($uri, ?DriverConfiguration $configuration = null, ?AuthenticateInterface $authenticate = null, FormatterInterface $formatter = null): self
8479
{
8580
if (is_string($uri)) {
8681
$uri = Uri::create($uri);
8782
}
8883

84+
if ($formatter !== null) {
85+
return new self(
86+
$uri,
87+
$authenticate ?? Authenticate::fromUrl(),
88+
new BoltConnectionPool(),
89+
$configuration ?? DriverConfiguration::default(),
90+
$formatter
91+
);
92+
}
93+
94+
8995
return new self(
9096
$uri,
9197
$authenticate ?? Authenticate::fromUrl(),
9298
new BoltConnectionPool(),
9399
$configuration ?? DriverConfiguration::default(),
94-
$formatter
100+
OGMFormatter::create()
95101
);
96102
}
97103

src/Http/HttpDriver.php

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -86,34 +86,38 @@ public function __construct(
8686
$this->auth = $auth;
8787
}
8888

89-
/**
90-
* @param string|UriInterface $uri
91-
*
92-
* @return self<OGMResults>
93-
*/
94-
public static function create($uri, ?DriverConfiguration $configuration = null, ?AuthenticateInterface $authenticate = null): self
95-
{
96-
return self::createWithFormatter($uri, OGMFormatter::create(), $configuration, $authenticate);
97-
}
98-
9989
/**
10090
* @template U
10191
*
102-
* @param string|UriInterface $uri
10392
* @param FormatterInterface<U> $formatter
93+
* @param string|UriInterface $uri
10494
*
105-
* @return self<U>
95+
* @return (
96+
* func_num_args() is 4
97+
* ? self<U>
98+
* : self<OGMResults>
99+
* )
100+
* @psalm-mutation-free
106101
*/
107-
public static function createWithFormatter($uri, FormatterInterface $formatter, ?DriverConfiguration $configuration = null, ?AuthenticateInterface $authenticate = null): self
102+
public static function create($uri, ?DriverConfiguration $configuration = null, ?AuthenticateInterface $authenticate = null, FormatterInterface $formatter = null): self
108103
{
109104
if (is_string($uri)) {
110105
$uri = Uri::create($uri);
111106
}
112107

108+
if ($formatter !== null) {
109+
return new self(
110+
$uri,
111+
$configuration ?? DriverConfiguration::default(),
112+
$formatter,
113+
$authenticate ?? Authenticate::fromUrl()
114+
);
115+
}
116+
113117
return new self(
114118
$uri,
115119
$configuration ?? DriverConfiguration::default(),
116-
$formatter,
120+
OGMFormatter::create(),
117121
$authenticate ?? Authenticate::fromUrl()
118122
);
119123
}

src/Neo4j/Neo4jDriver.php

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,15 @@
2727
use Laudis\Neo4j\Contracts\SessionInterface;
2828
use Laudis\Neo4j\Databags\DriverConfiguration;
2929
use Laudis\Neo4j\Databags\SessionConfiguration;
30-
use Laudis\Neo4j\Formatter\BasicFormatter;
30+
use Laudis\Neo4j\Formatter\OGMFormatter;
3131
use Psr\Http\Message\UriInterface;
3232

3333
/**
3434
* @template T
3535
*
3636
* @implements DriverInterface<T>
37+
*
38+
* @psalm-import-type OGMResults from \Laudis\Neo4j\Formatter\OGMFormatter
3739
*/
3840
final class Neo4jDriver implements DriverInterface
3941
{
@@ -63,30 +65,40 @@ public function __construct(
6365
}
6466

6567
/**
66-
* @param string|UriInterface $uri
67-
*/
68-
public static function create($uri, ?DriverConfiguration $configuration = null, ?AuthenticateInterface $authenticate = null): self
69-
{
70-
return self::createWithFormatter($uri, new BasicFormatter(), $configuration, $authenticate);
71-
}
72-
73-
/**
74-
* @param string|UriInterface $uri
68+
* @template U
7569
*
76-
* @throws Exception
70+
* @param FormatterInterface<U> $formatter
71+
* @param string|UriInterface $uri
72+
*
73+
* @return (
74+
* func_num_args() is 4
75+
* ? self<U>
76+
* : self<OGMResults>
77+
* )
78+
* @psalm-mutation-free
7779
*/
78-
public static function createWithFormatter($uri, FormatterInterface $formatter, ?DriverConfiguration $configuration = null, ?AuthenticateInterface $authenticate = null): self
80+
public static function create($uri, ?DriverConfiguration $configuration = null, ?AuthenticateInterface $authenticate = null, FormatterInterface $formatter = null): self
7981
{
8082
if (is_string($uri)) {
8183
$uri = Uri::create($uri);
8284
}
8385

86+
if ($formatter !== null) {
87+
return new self(
88+
$uri,
89+
$authenticate ?? Authenticate::fromUrl(),
90+
new Neo4jConnectionPool(new BoltConnectionPool()),
91+
$configuration ?? DriverConfiguration::default(),
92+
$formatter
93+
);
94+
}
95+
8496
return new self(
8597
$uri,
8698
$authenticate ?? Authenticate::fromUrl(),
8799
new Neo4jConnectionPool(new BoltConnectionPool()),
88100
$configuration ?? DriverConfiguration::default(),
89-
$formatter
101+
OGMFormatter::create()
90102
);
91103
}
92104

0 commit comments

Comments
 (0)