15
15
16
16
use Http \Discovery \Psr17FactoryDiscovery ;
17
17
use Http \Discovery \Psr18ClientDiscovery ;
18
+ use Laudis \Neo4j \Contracts \Injections ;
18
19
use Psr \Http \Client \ClientInterface ;
19
20
use Psr \Http \Message \RequestFactoryInterface ;
20
21
use Psr \Http \Message \StreamFactoryInterface ;
21
22
22
- final class HttpInjections
23
+ final class HttpInjections implements Injections
23
24
{
24
25
/** @var ClientInterface|callable():ClientInterface */
25
26
private $ client ;
@@ -29,6 +30,8 @@ final class HttpInjections
29
30
private $ requestFactory ;
30
31
/** @var string|callable():string */
31
32
private $ database ;
33
+ /** @var bool|callable():bool */
34
+ private $ autoRouting ;
32
35
33
36
/**
34
37
* Injector constructor.
@@ -37,8 +40,9 @@ final class HttpInjections
37
40
* @param ClientInterface|callable():ClientInterface|null $client
38
41
* @param StreamFactoryInterface|callable():StreamFactoryInterface|null $streamFactory
39
42
* @param RequestFactoryInterface|callable():RequestFactoryInterface|null $requestFactory
43
+ * @param bool|callable():bool $autoRouting
40
44
*/
41
- public function __construct ($ database = null , $ client = null , $ streamFactory = null , $ requestFactory = null )
45
+ public function __construct ($ database = null , $ client = null , $ streamFactory = null , $ requestFactory = null , $ autoRouting = null )
42
46
{
43
47
$ this ->database = $ database ?? static function (): string {
44
48
return 'neo4j ' ;
@@ -52,6 +56,7 @@ public function __construct($database = null, $client = null, $streamFactory = n
52
56
$ this ->requestFactory = $ requestFactory ?? static function (): RequestFactoryInterface {
53
57
return Psr17FactoryDiscovery::findRequestFactory ();
54
58
};
59
+ $ this ->autoRouting = $ autoRouting ?? false ;
55
60
}
56
61
57
62
public static function create (): self
@@ -73,31 +78,31 @@ public function client(): ClientInterface
73
78
*/
74
79
public function withClient ($ client ): self
75
80
{
76
- return new self ($ this ->database , $ client , $ this ->streamFactory , $ this ->requestFactory );
81
+ return new self ($ this ->database , $ client , $ this ->streamFactory , $ this ->requestFactory , $ this -> autoRouting );
77
82
}
78
83
79
84
/**
80
85
* @param StreamFactoryInterface|callable():StreamFactoryInterface $factory
81
86
*/
82
87
public function withStreamFactory ($ factory ): self
83
88
{
84
- return new self ($ this ->database , $ this ->client , $ factory , $ this ->requestFactory );
89
+ return new self ($ this ->database , $ this ->client , $ factory , $ this ->requestFactory , $ this -> autoRouting );
85
90
}
86
91
87
92
/**
88
93
* @param RequestFactoryInterface|callable():RequestFactoryInterface $factory
89
94
*/
90
95
public function withRequestFactory ($ factory ): self
91
96
{
92
- return new self ($ this ->database , $ this ->client , $ this ->streamFactory , $ factory );
97
+ return new self ($ this ->database , $ this ->client , $ this ->streamFactory , $ factory, $ this -> autoRouting );
93
98
}
94
99
95
100
/**
96
101
* @param string|callable():string $database
97
102
*/
98
103
public function withDatabase ($ database ): self
99
104
{
100
- return new self ($ database , $ this ->client , $ this ->streamFactory , $ this ->requestFactory );
105
+ return new self ($ database , $ this ->client , $ this ->streamFactory , $ this ->requestFactory , $ this -> autoRouting );
101
106
}
102
107
103
108
public function streamFactory (): StreamFactoryInterface
@@ -126,4 +131,24 @@ public function database(): string
126
131
127
132
return $ this ->database ;
128
133
}
134
+
135
+ public function withAutoRouting ($ routing ): Injections
136
+ {
137
+ return new self (
138
+ $ this ->database ,
139
+ $ this ->client ,
140
+ $ this ->streamFactory ,
141
+ $ this ->requestFactory ,
142
+ $ routing
143
+ );
144
+ }
145
+
146
+ public function hasAutoRouting (): bool
147
+ {
148
+ if (is_callable ($ this ->autoRouting )) {
149
+ $ this ->autoRouting = call_user_func ($ this ->autoRouting );
150
+ }
151
+
152
+ return $ this ->autoRouting ;
153
+ }
129
154
}
0 commit comments