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
9. GitHub will automatically delete the branch after the merge is done. (they can still be restored).
66
66
67
+
### Testing
68
+
69
+
-`docker-compose up -d`
70
+
-`docker-compose exec web vendor/bin/phpunit --configuration phpunit.xml`
71
+
-`docker-compose exec web vendor/bin/psalm --show-info=true`
72
+
67
73
## Introducing New Features
68
74
69
75
We would 💖 you to contribute to Framework, but we would also like to make sure Framework is as great as possible and loyal to its vision and mission statement 🙏.
Utopia Framework 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 Framework is dependencyfree. Any extra features such as authentication, caching will be available as standalone models in order to keep the framework core as clean, light and easy to learn.
11
+
Utopia Framework is dependency-free. Any extra features, such as authentication or caching, will be available as standalone models in order to keep the framework core clean, light, and easy to learn.
$http = new Http(new Server(), 'America/New_York');
46
+
$http->start();
47
+
```
42
48
43
-
$app = new App('America/New_York');
44
-
$request = new Request();
45
-
$response = new Response();
49
+
Run HTTP server:
46
50
47
-
$app->run($request, $response);
51
+
```bash
52
+
php -S localhost:8000 src/server2.php
48
53
```
49
54
50
-
### Hooks
55
+
Send HTTP request:
56
+
57
+
```bash
58
+
curl http://localhost:8000/hello-world
59
+
```
60
+
61
+
### Server Adapters
62
+
63
+
The library supports server adapters to be able to run on any PHP setup. For instance, you could use the FPM server or the Swoole server.
64
+
65
+
#### Use PHP FPM server
66
+
67
+
```php
68
+
use Utopia\Http\Http;
69
+
use Utopia\Http\Response;
70
+
use Utopia\Http\Adapter\FPM\Server;
71
+
72
+
Http::get('/')
73
+
->inject('response')
74
+
->action(
75
+
function(Response $response) {
76
+
$response->send('Hello from PHP FPM');
77
+
}
78
+
);
51
79
52
-
There are three types of hooks, init hooks, shutdown hooks and error hooks. Init hooks are executed before the route action is executed. Shutdown hook is executed after route action is executed before application shuts down. Finally error hooks are executed whenever there's an error in the application lifecycle. You can provide multiple hooks for each stage. If you do not assign groups to the hook, by default the hook will be executed for every route.
80
+
$http = new Http(new Server(), 'America/New_York');
81
+
$http->start();
82
+
```
83
+
84
+
> When using PHP FPM, you can use the command `php -S localhost:80 src/server.php` to run the HTTP server locally
$http = new Http(new Server('0.0.0.0', '80'), 'America/New_York');
104
+
$http->start();
105
+
```
106
+
107
+
> When using Swoole, you can use the command `php src/server.php` to run the HTTP server locally, but you need Swoole installed. For setup with Docker, check out our [example application](/example)
108
+
109
+
### Parameters
110
+
111
+
Parameters are used to receive input into endpoint action from the HTTP request. Parameters could be defined as URL parameters or in a body with a structure such as JSON.
112
+
113
+
Every parameter must have a validator defined. Validators are simple classes that verify the input and ensure the security of inputs. You can define your own validators or use some of [built-in validators](/src/Http/Validator).
114
+
115
+
Define an endpoint with params:
116
+
117
+
```php
118
+
Http::get('/')
119
+
->param('name', 'World', new Text(256), 'Name to greet. Optional, max length 256.', true)
It's always recommended to use params instead of getting params or body directly from the request resource. If you do that intentionally, always make sure to run validation right after fetching such a raw input.
135
+
136
+
### Hooks
137
+
138
+
There are three types of hooks:
56
139
57
-
use Utopia\App;
58
-
use Utopia\Request;
59
-
use Utopia\Response;
140
+
-**Init hooks** are executed before the route action is executed
141
+
-**Shutdown hooks** are executed after route action is finished, but before application shuts down
142
+
-**Error hooks** are executed whenever there's an error in the application lifecycle.
60
143
61
-
App::init()
144
+
You can provide multiple hooks for each stage. If you do not assign groups to the hook, by default, the hook will be executed for every route. If a group is defined on a hook, it will only run during the lifecycle of a request with the same group name on the action.
Hooks are designed to be actions that run during the lifecycle of requests. Hooks should include functional logic. Hooks are not designed to prepare dependencies or context for the request. For such a use case, you should use resources.
170
+
171
+
### Groups
172
+
173
+
Groups allow you to define common behavior for multiple endpoints.
174
+
175
+
You can start by defining a group on an endpoint. Keep in mind you can also define multiple groups on a single endpoint.
Groups are designed to be actions that run during the lifecycle of requests to endpoints that have some logic in common. Groups allow you to prevent code duplication and are designed to be defined anywhere in your source code to allow flexibility.
207
+
208
+
### Resources
209
+
210
+
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.
In advanced scenarios, resources can also be injected into other resources or endpoint parameters.
243
+
244
+
Resources are designed to prepare dependencies or context for the request. Resources are not meant to do functional logic or return callbacks. For such a use case, you should use hooks.
245
+
246
+
To learn more about Framework architecture and features, check out more in-depth [Getting started guide](/docs/Getting-Starting-Guide.md).
247
+
98
248
## System Requirements
99
249
100
250
Utopia Framework requires PHP 8.0 or later. We recommend using the latest PHP version whenever possible.
101
251
102
252
## More from Utopia
103
253
104
-
Our ecosystem support other thin PHP projects aiming to extend the core PHP Utopia framework.
254
+
Our ecosystem supports other thin PHP projects aiming to extend the core PHP Utopia framework.
105
255
106
256
Each project is focused on solving a single, very simple problem and you can use composer to include any of them in your next project.
107
257
108
-
Library | Description
109
-
--- | ---
110
-
**[Utopia AB](https://github.com/utopia-php/ab)** | Simple PHP library for managing AB testing on the server side.
111
-
**[Utopia Abuse](https://github.com/utopia-php/abuse)** | Simple PHP library for rate limiting usage of different features in your app or API.
112
-
**[Utopia Analytics](https://github.com/utopia-php/analytics)** | Simple PHP library to send information about events or pageviews to Google Analytics.
113
-
**[Utopia Audit](https://github.com/utopia-php/audit)** | Simple PHP library for audit logging users actions and system events
114
-
**[Utopia Cache](https://github.com/utopia-php/cache)** | Simple PHP library for managing cache with different storage adapters.
115
-
**[Utopia CLI](https://github.com/utopia-php/cli)** | Simple PHP library for for building simple command line tools.
116
-
**[Utopia Config](https://github.com/utopia-php/config)** | Simple PHP library for managing your app configuration.
117
-
**[Utopia Database](https://github.com/utopia-php/database)** | Simple PHP library for managing application persistency. It supports multiple database adapters.
118
-
**[Utopia Domains](https://github.com/utopia-php/domains)** | Simple PHP library for parsing domain names.
119
-
**[Utopia Image](https://github.com/utopia-php/image)** | Simple PHP library for creating common image manipulations that is easy to use.
120
-
**[Utopia Locale](https://github.com/utopia-php/locale)** | Simple PHP library for adding support to multiple locales in your app or API.
**[Utopia Registry](https://github.com/utopia-php/registry)** | Simple PHP library for dependency injection and lazy loading of objects or resources.
123
-
**[Utopia System](https://github.com/utopia-php/system)** | Simple PHP library for obtaining information about the host's system.
124
-
**[Utopia Storage](https://github.com/utopia-php/storage)** | Simple and lite PHP library for managing application storage. It supports multiple storage adapters.
258
+
You can find all libraries in [GitHub Utopia organization](https://github.com/utopia-php).
125
259
126
260
## Contributing
127
261
@@ -133,12 +267,6 @@ You can refer to the [Contributing Guide](https://github.com/utopia-php/framewor
133
267
134
268
For security issues, please email security@appwrite.io instead of posting a public issue in GitHub.
135
269
136
-
### Testing
137
-
138
-
-`docker-compose up -d`
139
-
-`docker-compose exec web vendor/bin/phpunit --configuration phpunit.xml`
140
-
-`docker-compose exec web vendor/bin/psalm --show-info=true`
141
-
142
270
## Copyright and license
143
271
144
272
The MIT License (MIT) [http://www.opensource.org/licenses/mit-license.php](http://www.opensource.org/licenses/mit-license.php)
0 commit comments