• Stars
    star
    255
  • Rank 159,302 (Top 4 %)
  • Language
    PHP
  • License
    MIT License
  • Created over 5 years ago
  • Updated about 1 month ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Lite & fast micro PHP HTTP framework that is easy to learn.

Logo

Build Status Total Downloads Discord

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.

Utopia Framework is dependency free. 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.

Getting Started

Install using composer:

composer require utopia-php/framework

Init your first application:

require_once __DIR__ . '/../../vendor/autoload.php';

use Utopia\App;
use Utopia\Request;
use Utopia\Response;

App::get('/hello-world') // Define Route
    ->inject('request')
    ->inject('response')
    ->action(
        function($request, $response) {
            $response
              ->addHeader('Cache-Control', 'no-cache, no-store, must-revalidate')
              ->addHeader('Expires', '0')
              ->addHeader('Pragma', 'no-cache')
              ->json(['Hello' => 'World']);
        }
    );

App::setMode(App::MODE_TYPE_PRODUCTION); // Define Mode

$app        = new App('America/New_York');
$request    = new Request();
$response   = new Response();

$app->run($request, $response);

Hooks

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.

require_once __DIR__ . '/../../vendor/autoload.php';

use Utopia\App;
use Utopia\Request;
use Utopia\Response;

App::init()
    ->inject('response')
    ->action(function($response) {
        $response->addHeader('content-type', 'application/json');
    });

App::error()
    ->inject('error')
    ->inject('response')
    ->action(function($error, $response) {
        $response
            ->setStatusCode(500)
            ->send('Error occurred ' . $error);
    });

App::get('/hello-world') // Define Route
    ->inject('request')
    ->inject('response')
    ->action(
        function($request, $response) {
            $response
              ->addHeader('Cache-Control', 'no-cache, no-store, must-revalidate')
              ->addHeader('Expires', '0')
              ->addHeader('Pragma', 'no-cache')
              ->json(['Hello' => 'World']);
        }
    );

App::setMode(App::MODE_TYPE_PRODUCTION); // Define Mode

$app        = new App('America/New_York');
$request    = new Request();
$response   = new Response();

$app->run($request, $response);

System Requirements

Utopia Framework requires PHP 8.0 or later. We recommend using the latest PHP version whenever possible.

More from Utopia

Our ecosystem support other thin PHP projects aiming to extend the core PHP Utopia framework.

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.

Library Description
Utopia AB Simple PHP library for managing AB testing on the server side.
Utopia Abuse Simple PHP library for rate limiting usage of different features in your app or API.
Utopia Analytics Simple PHP library to send information about events or pageviews to Google Analytics.
Utopia Audit Simple PHP library for audit logging users actions and system events
Utopia Cache Simple PHP library for managing cache with different storage adapters.
Utopia CLI Simple PHP library for for building simple command line tools.
Utopia Config Simple PHP library for managing your app configuration.
Utopia Database Simple PHP library for managing application persistency. It supports multiple database adapters.
Utopia Domains Simple PHP library for parsing domain names.
Utopia Image Simple PHP library for creating common image manipulations that is easy to use.
Utopia Locale Simple PHP library for adding support to multiple locales in your app or API.
Utopia Preloader Simple PHP library for managing PHP preloading configuration.
Utopia Registry Simple PHP library for dependency injection and lazy loading of objects or resources.
Utopia System Simple PHP library for obtaining information about the host's system.
Utopia Storage Simple and lite PHP library for managing application storage. It supports multiple storage adapters.

Contributing

All code contributions - including those of people having commit access - must go through a pull request and approved by a core developer before being merged. This is to ensure proper review of all the code.

Fork the project, create a feature branch, and send us a pull request.

You can refer to the Contributing Guide for more info.

For security issues, please email [email protected] instead of posting a public issue in GitHub.

Testing

  • docker-compose up -d
  • docker-compose exec web vendor/bin/phpunit --configuration phpunit.xml
  • docker-compose exec web vendor/bin/psalm --show-info=true

Copyright and license

The MIT License (MIT) http://www.opensource.org/licenses/mit-license.php

More Repositories

1

database

Lite & fast micro PHP database abstraction library that is **easy to use**.
PHP
62
star
2

domains

Lite & fast micro PHP domain parsing library that is **easy to use**.
PHP
47
star
3

cli

Lite & fast micro PHP framework for building CLI tools that is **easy to learn**.
PHP
38
star
4

cache

Lite & fast micro PHP cache library that is **easy to use**.
PHP
29
star
5

storage

Lite & fast micro PHP storage library that is **easy to use**.
PHP
28
star
6

abuse

Lite & fast micro PHP abuse library that is **easy to use**.
PHP
25
star
7

locale

Lite & fast micro PHP locale library that is **easy to use**.
PHP
24
star
8

system

Lite & fast micro PHP system library that is **easy to use**.
PHP
22
star
9

audit

Lite & fast micro PHP audit log library that is **easy to use**.
PHP
20
star
10

swoole

An extension for Utopia Framework to work with PHP Swoole as a PHP FPM alternative
PHP
18
star
11

registry

Lite & fast micro PHP dependency management library that is **easy to use**.
PHP
17
star
12

messaging

Lite & fast micro PHP messaging library that is **easy to use**.
PHP
14
star
13

analytics

Lite & fast micro PHP analytics library that is **easy to use**.
PHP
14
star
14

config

Lite & fast micro PHP configuration management library that is **easy to use**.
PHP
14
star
15

orchestration

Lite & fast micro PHP abstraction library for container orchestration that is **easy to use**.
PHP
13
star
16

preloader

Lite & fast micro PHP library for managing memory preloading that is **easy to use**.
PHP
12
star
17

ab

Lite & fast micro PHP AB Tests library that is **easy to use**.
PHP
12
star
18

image

Lite & fast micro PHP library for creating common image manipulations that is **easy to use**.
PHP
11
star
19

websocket

Lite & fast micro PHP WebSocket server abstraction that is **easy to use**.
PHP
11
star
20

platform

PHP
10
star
21

logger

Lite & fast micro PHP logging library that is **easy to use**.
PHP
9
star
22

queue

PHP
8
star
23

demo

A simple demo for using Utopia + Swoole on a Docker container 🐳
PHP
8
star
24

pay

Lite & fast micro PHP payments abstraction library that is **easy to use**.
PHP
7
star
25

fetch

Lite & fast micro PHP Fetch library that is **easy to use**.
PHP
6
star
26

balancer

PHP
6
star
27

pools

Lite & fast micro PHP pools library that is **easy to use**.
PHP
5
star
28

vcs

Lite & fast micro PHP vcs abstraction library that is **easy to use**.
PHP
5
star
29

mongo

PHP
5
star
30

dsn

Lite & fast micro PHP library for handling Data Source Names (DSNs) that is **easy to use**.
PHP
4
star
31

migration

PHP
3
star
32

database-proxy

PHP
3
star
33

di

Lite & fast micro PHP dependency injections library that is **easy to use**.
PHP
3
star
34

servers

A base library for building Utopia style servers. 🧑‍💻
PHP
2
star
35

.github

1
star