You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+26-15Lines changed: 26 additions & 15 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -8,7 +8,7 @@
8
8
9
9
Utopia HTTP is a PHP MVC based framework with minimal must-have features for professional, simple, advanced and secure web development. This library is maintained by the [Appwrite team](https://appwrite.io).
10
10
11
-
Utopia HTTP is dependency-free. Any extra features, such as authentication or caching are available as standalone models in order to keep the framework core clean, light, and easy to learn.
11
+
Utopia HTTP keeps routing and request lifecycle concerns separate from resource wiring by relying on the standalone Utopia DI package for dependency injection.
12
12
13
13
## Getting Started
14
14
@@ -23,11 +23,14 @@ Init your first application in `src/server.php`:
$http = new Http(new Server(), 'America/New_York');
49
+
$http = new Http(new Server(), 'America/New_York', $container);
47
50
$http->start();
48
51
```
49
52
@@ -66,10 +69,13 @@ The library supports server adapters to be able to run on any PHP setup. You cou
66
69
#### Use PHP FPM server
67
70
68
71
```php
72
+
use Utopia\DI\Container;
69
73
use Utopia\Http\Http;
70
74
use Utopia\Http\Response;
71
75
use Utopia\Http\Adapter\FPM\Server;
72
76
77
+
$container = new Container();
78
+
73
79
Http::get('/')
74
80
->inject('response')
75
81
->action(
@@ -78,7 +84,7 @@ Http::get('/')
78
84
}
79
85
);
80
86
81
-
$http = new Http(new Server(), 'America/New_York');
87
+
$http = new Http(new Server(), 'America/New_York', $container);
82
88
$http->start();
83
89
```
84
90
@@ -87,11 +93,14 @@ $http->start();
87
93
#### Using Swoole server
88
94
89
95
```php
96
+
use Utopia\DI\Container;
90
97
use Utopia\Http\Http;
91
98
use Utopia\Http\Request;
92
99
use Utopia\Http\Response;
93
100
use Utopia\Http\Adapter\Swoole\Server;
94
101
102
+
$container = new Container();
103
+
95
104
Http::get('/')
96
105
->inject('request')
97
106
->inject('response')
@@ -101,7 +110,7 @@ Http::get('/')
101
110
}
102
111
);
103
112
104
-
$http = new Http(new Server('0.0.0.0', '80'), 'America/New_York');
113
+
$http = new Http(new Server('0.0.0.0', '80'), 'America/New_York', $container);
105
114
$http->start();
106
115
```
107
116
@@ -208,35 +217,37 @@ Groups are designed to be actions that run during the lifecycle of requests to e
208
217
209
218
### Resources
210
219
211
-
Resources allow you to prepare dependencies for requests such as database connection or the user who sent the request. A new instance of a resource is created for every request.
220
+
Resources allow you to prepare dependencies for requests such as database connections or shared services. Register application dependencies on the DI container with `set()`. Runtime values such as `request`, `response`, `route`, `error`, and `context` are scoped by `Http`for each request.
212
221
213
-
Define a resource:
222
+
Define a dependency on the DI container:
214
223
215
224
```php
216
-
Http::setResource('timing', function() {
225
+
$container->set('bootTime', function() {
217
226
return \microtime(true);
218
227
});
219
228
```
220
229
221
230
Inject resource into endpoint action:
222
231
223
232
```php
233
+
$http = new Http(new Server(), 'America/New_York', $container);
0 commit comments