Skip to content

Commit 2fb22c2

Browse files
authored
refactor: rename App class to Http in utopia-php/http (#206)
1 parent 30a119d commit 2fb22c2

File tree

11 files changed

+1178
-180
lines changed

11 files changed

+1178
-180
lines changed

README.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@ Init your first application:
2121
```php
2222
require_once __DIR__ . '/../../vendor/autoload.php';
2323

24-
use Utopia\App;
24+
use Utopia\Http;
2525
use Utopia\Request;
2626
use Utopia\Response;
2727

28-
App::get('/hello-world') // Define Route
28+
Http::get('/hello-world') // Define Route
2929
->inject('request')
3030
->inject('response')
3131
->action(
@@ -38,9 +38,9 @@ App::get('/hello-world') // Define Route
3838
}
3939
);
4040

41-
App::setMode(App::MODE_TYPE_PRODUCTION); // Define Mode
41+
Http::setMode(Http::MODE_TYPE_PRODUCTION); // Define Mode
4242

43-
$app = new App('America/New_York');
43+
$app = new Http('America/New_York');
4444
$request = new Request();
4545
$response = new Response();
4646

@@ -54,17 +54,17 @@ There are three types of hooks, init hooks, shutdown hooks and error hooks. Init
5454
```php
5555
require_once __DIR__ . '/../../vendor/autoload.php';
5656

57-
use Utopia\App;
57+
use Utopia\Http;
5858
use Utopia\Request;
5959
use Utopia\Response;
6060

61-
App::init()
61+
Http::init()
6262
->inject('response')
6363
->action(function($response) {
6464
$response->addHeader('content-type', 'application/json');
6565
});
6666

67-
App::error()
67+
Http::error()
6868
->inject('error')
6969
->inject('response')
7070
->action(function($error, $response) {
@@ -73,7 +73,7 @@ App::error()
7373
->send('Error occurred ' . $error);
7474
});
7575

76-
App::get('/hello-world') // Define Route
76+
Http::get('/hello-world') // Define Route
7777
->inject('request')
7878
->inject('response')
7979
->action(
@@ -86,9 +86,9 @@ App::get('/hello-world') // Define Route
8686
}
8787
);
8888

89-
App::setMode(App::MODE_TYPE_PRODUCTION); // Define Mode
89+
Http::setMode(Http::MODE_TYPE_PRODUCTION); // Define Mode
9090

91-
$app = new App('America/New_York');
91+
$app = new Http('America/New_York');
9292
$request = new Request();
9393
$response = new Response();
9494

docs/Getting-Starting-Guide.md

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ If you’re new to Utopia, let’s get started by looking at an example of a bas
99
## Basic GET Route
1010

1111
```php
12-
use Utopia\App;
12+
use Utopia\Http;
1313
use Utopia\Swoole\Request;
1414
use Utopia\Swoole\Response;
1515
use Swoole\Http\Server;
@@ -18,7 +18,7 @@ use Swoole\Http\Response as SwooleResponse;
1818

1919
$http = new Server("0.0.0.0", 8080);
2020

21-
App::get('/')
21+
Http::get('/')
2222
->inject('request')
2323
->inject('response')
2424
->action(
@@ -33,7 +33,7 @@ App::get('/')
3333
$http->on('request', function (SwooleRequest $swooleRequest, SwooleResponse $swooleResponse) {
3434
$request = new Request($swooleRequest);
3535
$response = new Response($swooleResponse);
36-
$app = new App('America/Toronto');
36+
$app = new Http('America/Toronto');
3737
$app->run($request, $response);
3838
});
3939

@@ -59,7 +59,7 @@ You can perform basic CRUD operations like GET, POST, PUT and DELETE using Utopi
5959
You can create a PUT request to update a todo by passing it’s reference `id` along with the values to be updated as follows:
6060

6161
```php
62-
App::put('/todos/:id')
62+
Http::put('/todos/:id')
6363
->param('id', "", new Wildcard(), 'id of the todo')
6464
->param('task', "", new Wildcard(), 'name of the todo')
6565
->param('is_complete', true, new Wildcard(), 'task complete or not')
@@ -138,7 +138,7 @@ You can find the details of other status codes by visiting our [GitHub repositor
138138
Let's make the above example slightly advanced by adding more properties.
139139

140140
```php
141-
use Utopia\App;
141+
use Utopia\Http;
142142
use Utopia\Swoole\Request;
143143
use Utopia\Swoole\Response;
144144
use Swoole\Http\Server;
@@ -148,28 +148,28 @@ use Utopia\Validator\Wildcard;
148148

149149
$http = new Server("0.0.0.0", 8080);
150150

151-
App::init(function($response) {
151+
Http::init(function($response) {
152152
/*
153153
Example of global init method. Do stuff that is common to all your endpoints in all groups.
154154
This can include things like authentication and authorisation checks, implementing rate limits and so on..
155155
*/
156156
}, ['response']);
157157

158-
App::init(function($response) {
158+
Http::init(function($response) {
159159
/*
160160
Example of init method for group1. Do stuff that is common to all your endpoints in group1.
161161
This can include things like authentication and authorisation checks, implementing rate limits and so on..
162162
*/
163163
}, ['response'], 'group1');
164164

165-
App::init(function($response) {
165+
Http::init(function($response) {
166166
/*
167167
Example of init method for group2. Do stuff that is common to all your endpoints in group2.
168168
This can include things like authentication and authorisation checks, implementing rate limits and so on..
169169
*/
170170
}, ['response'], 'group2');
171171

172-
App::shutdown(function($request) {
172+
Http::shutdown(function($request) {
173173
/*
174174
Example of global shutdown method. Do stuff that needs to be performed at the end of each request for all groups.
175175
'*' (Wildcard validator) is optional.
@@ -178,15 +178,15 @@ App::shutdown(function($request) {
178178

179179
}, ['request'], '*');
180180

181-
App::shutdown(function($request) {
181+
Http::shutdown(function($request) {
182182
/*
183183
Example of shutdown method of group1. Do stuff that needs to be performed at the end of each request for all groups.
184184
This can include cleanups, logging information, recording usage stats, closing database connections and so on..
185185
*/
186186

187187
}, ['request'], 'group1');
188188

189-
App::put('/todos/:id')
189+
Http::put('/todos/:id')
190190
->desc('Update todo')
191191
->groups(['group1', 'group2'])
192192
->label('scope', 'public')
@@ -255,7 +255,7 @@ The init and shutdown methods take three params:
255255

256256
init method is executed in the beginning when the program execution begins. Here’s an example of the init method, where the init method is executed for all groups indicated by the wildcard symbol `'*'`.
257257
```php
258-
App::init(function($response) {
258+
Http::init(function($response) {
259259
/*
260260
Do stuff that is common to all your endpoints.
261261
This can include things like authentication and authorisation checks, implementing rate limits and so on..
@@ -268,7 +268,7 @@ App::init(function($response) {
268268
Utopia's shutdown callback is used to perform cleanup tasks after a request. This could include closing any open database connections, resetting certain flags, triggering analytics events (if any) and similar tasks.
269269

270270
```php
271-
App::shutdown(function($request) {
271+
Http::shutdown(function($request) {
272272
/*
273273
Do stuff that needs to be performed at the end of each request.
274274
This can include cleanups, logging information, recording usage stats, closing database connections and so on..

src/App.php

100755100644
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
use Utopia\Validator\Integer;
1313
use Utopia\Validator\Text;
1414

15-
class App
15+
class Http
1616
{
1717
public const COMPRESSION_MIN_SIZE_DEFAULT = 1024;
1818

@@ -126,7 +126,7 @@ class App
126126
* Compression
127127
*/
128128
protected bool $compression = false;
129-
protected int $compressionMinSize = App::COMPRESSION_MIN_SIZE_DEFAULT;
129+
protected int $compressionMinSize = Http::COMPRESSION_MIN_SIZE_DEFAULT;
130130
protected mixed $compressionSupported = [];
131131

132132
private Histogram $requestDuration;
@@ -135,7 +135,7 @@ class App
135135
private Histogram $responseBodySize;
136136

137137
/**
138-
* App
138+
* Http
139139
*
140140
* @param string $timezone
141141
*/

0 commit comments

Comments
 (0)