From 19e0eb1742467c6dcd5d52e97fb7b2c3801af8ac Mon Sep 17 00:00:00 2001 From: Torsten Dittmann Date: Fri, 5 Jan 2024 11:44:20 +0100 Subject: [PATCH 1/2] chore: rename library to utopia-php/http --- .github/workflows/test.yml | 5 +++- README.md | 14 ++++----- composer.json | 2 +- composer.lock | 14 ++++----- docs/Getting-Starting-Guide.md | 54 +++++++++++++++++----------------- example/composer.json | 2 +- tests/Validator/DomainTest.php | 2 +- tests/Validator/HostTest.php | 2 +- tests/Validator/IPTest.php | 2 +- tests/Validator/URLTest.php | 2 +- 10 files changed, 51 insertions(+), 48 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index ce9d61c5..e17e5507 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -15,6 +15,9 @@ jobs: with: php-version: '8.1' + - name: Validate composer.json and composer.lock + run: composer validate --strict + - name: Setup Docker run: docker-compose up -d --build @@ -23,6 +26,6 @@ jobs: - name: Run FPM Tests run: docker compose exec fpm vendor/bin/phpunit --configuration phpunit.xml - + - name: Run Swoole Tests run: docker compose exec swoole vendor/bin/phpunit --configuration phpunit.xml \ No newline at end of file diff --git a/README.md b/README.md index fe37a60e..3fb0a525 100644 --- a/README.md +++ b/README.md @@ -2,8 +2,8 @@ Logo

-[![Build Status](https://travis-ci.org/utopia-php/framework.svg?branch=master)](https://travis-ci.org/utopia-php/framework) -![Total Downloads](https://img.shields.io/packagist/dt/utopia-php/framework.svg) +[![Build Status](https://travis-ci.org/utopia-php/http.svg?branch=master)](https://travis-ci.org/utopia-php/http) +![Total Downloads](https://img.shields.io/packagist/dt/utopia-php/http.svg) [![Discord](https://img.shields.io/discord/564160730845151244?label=discord)](https://discord.gg/GSeTUeA) 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). @@ -14,7 +14,7 @@ Utopia Framework is dependency-free. Any extra features, such as authentication Install using composer: ```bash -composer require utopia-php/framework +composer require utopia-php/http ``` Init your first application in `src/server.php`: @@ -49,7 +49,7 @@ $http->start(); Run HTTP server: ```bash -php -S localhost:8000 src/server2.php +php -S localhost:8000 src/server2.php ``` Send HTTP request: @@ -203,7 +203,7 @@ Http::init() }); ``` -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. +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. ### Resources @@ -253,7 +253,7 @@ Utopia Framework requires PHP 8.0 or later. We recommend using the latest PHP ve Our ecosystem supports 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. +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. You can find all libraries in [GitHub Utopia organization](https://github.com/utopia-php). @@ -263,7 +263,7 @@ All code contributions - including those of people having commit access - must g Fork the project, create a feature branch, and send us a pull request. -You can refer to the [Contributing Guide](https://github.com/utopia-php/framework/blob/master/CONTRIBUTING.md) for more info. +You can refer to the [Contributing Guide](https://github.com/utopia-php/http/blob/master/CONTRIBUTING.md) for more info. For security issues, please email security@appwrite.io instead of posting a public issue in GitHub. diff --git a/composer.json b/composer.json index 043758fa..a2cf3cb2 100644 --- a/composer.json +++ b/composer.json @@ -1,5 +1,5 @@ { - "name": "utopia-php/framework", + "name": "utopia-php/http", "description": "A simple, light and advanced PHP framework", "type": "library", "keywords": [ diff --git a/composer.lock b/composer.lock index a388d0e9..a5519ed2 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "f27d5bb02390ce6b9a8268d4fffb1e87", + "content-hash": "33b8cf270cfbd8f86cbd1338d81f5140", "packages": [], "packages-dev": [ { @@ -724,16 +724,16 @@ }, { "name": "phpstan/phpstan", - "version": "1.10.50", + "version": "1.10.52", "source": { "type": "git", "url": "https://github.com/phpstan/phpstan.git", - "reference": "06a98513ac72c03e8366b5a0cb00750b487032e4" + "reference": "0cd0c330081d4f1e1d630701fe4f342c3b659685" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpstan/phpstan/zipball/06a98513ac72c03e8366b5a0cb00750b487032e4", - "reference": "06a98513ac72c03e8366b5a0cb00750b487032e4", + "url": "https://api.github.com/repos/phpstan/phpstan/zipball/0cd0c330081d4f1e1d630701fe4f342c3b659685", + "reference": "0cd0c330081d4f1e1d630701fe4f342c3b659685", "shasum": "" }, "require": { @@ -782,7 +782,7 @@ "type": "tidelift" } ], - "time": "2023-12-13T10:59:42+00:00" + "time": "2024-01-05T09:51:32+00:00" }, { "name": "phpunit/php-code-coverage", @@ -3451,5 +3451,5 @@ "ext-swoole": "*" }, "platform-dev": [], - "plugin-api-version": "2.6.0" + "plugin-api-version": "2.3.0" } diff --git a/docs/Getting-Starting-Guide.md b/docs/Getting-Starting-Guide.md index 272a6b4a..0d44f140 100644 --- a/docs/Getting-Starting-Guide.md +++ b/docs/Getting-Starting-Guide.md @@ -4,7 +4,7 @@ Utopia Framework is an easy-to-use PHP MVC based framework with minimal must-have features for professional, simple, advanced and secure web development. It follows an architecture like Express and is based on the declarative programming approach. Documenting and writing code are usually seen as two separate tasks and very often, documentation loses priority in the software development lifecycle. Utopia unifies the two with a flexible API that allows your code to be self-documenting. What’s interesting about Utopia is its ability to accept metadata along with it’s route definitions. This metadata can then be used for various purposes like generating documentation, swagger specifications and more. # Defining Routes -If you’re new to Utopia, let’s get started by looking at an example of a basic GET route for an application that you can create using Utopia. We'll be using a [Swoole server](https://github.com/swoole/swoole-src) in this example, but you should be able to extend it to any HTTP server. +If you’re new to Utopia, let’s get started by looking at an example of a basic GET route for an application that you can create using Utopia. We'll be using a [Swoole server](https://github.com/swoole/swoole-src) in this example, but you should be able to extend it to any HTTP server. ## Basic GET Route @@ -17,7 +17,7 @@ use Swoole\Http\Request as SwooleRequest; use Swoole\Http\Response as SwooleResponse; $http = new Server("0.0.0.0", 8080); - + Http::get('/') ->inject('request') ->inject('response') @@ -27,7 +27,7 @@ Http::get('/') $response->send("
Hello World!
"); } /* - Configure your HTTP server to respond with the Utopia http. + Configure your HTTP server to respond with the Utopia http. */ $http->on('request', function (SwooleRequest $swooleRequest, SwooleResponse $swooleResponse) { @@ -39,12 +39,12 @@ $http->on('request', function (SwooleRequest $swooleRequest, SwooleResponse $swo $http->start(); ``` - + Any route in Utopia would require you to `inject` the dependencies ( `$request` and `$response` in this case ) and define the controller by passing a callback to the `action` function. As you might have already guessed, `$request` and `$response` refer to the objects of the HTTP server library you’re using, for example, Swoole in this case. `action` defines the callback function that would be called when the GET request is executed. In this case, raw HTML is returned as a `$response`. ## More Endpoints -You can perform basic CRUD operations like GET, POST, PUT and DELETE using Utopia. Let’s assume there's a file `todos.json` that stores a list of todo objects with the following structure. In a real-world scenario, you would be fetching this information from a database. +You can perform basic CRUD operations like GET, POST, PUT and DELETE using Utopia. Let’s assume there's a file `todos.json` that stores a list of todo objects with the following structure. In a real-world scenario, you would be fetching this information from a database. ```json [ @@ -88,9 +88,9 @@ You might have noticed an additional property in the above example, i.e. `param` All the parameters need to be defined using the `param` property which accepts the following - `$key`, `$default`, `$validator`, `$description`, `$optional` and `$injections`. There are typically 3 types of parameters: -1. Path params ( eg: `/api/users/` ) +1. Path params ( eg: `/api/users/` ) 2. Query Params ( eg: `/api/users?userId=`) -3. Body Params ( These are passed in the request body in POST and PUT requests. ) +3. Body Params ( These are passed in the request body in POST and PUT requests. ) Let's take a look at how these three types of params are taken care of by Utopia: @@ -100,7 +100,7 @@ Let's take a look at how these three types of params are taken care of by Utopia 3. Body Parameters are specified using the `->param()` function as well. -Each of these params then become available to the `->action()` callback function in the same order that they were declared in. +Each of these params then become available to the `->action()` callback function in the same order that they were declared in. ### Returning a Response Based on the type of the response you wish to return, multiple options can be used: @@ -120,7 +120,7 @@ $response->json(['Goodbye' => 'World']); JSON objects can be returned by passing the JSON object inside `$response->json()`. -### Setting Response Status +### Setting Response Status You can set a status code for your response using the `setStatusCode()` function of utopia's response object. @@ -130,7 +130,7 @@ $response ->send('') ``` -You can find the details of other status codes by visiting our [GitHub repository](https://github.com/utopia-php/framework/blob/master/src/Response.php). +You can find the details of other status codes by visiting our [GitHub repository](https://github.com/utopia-php/http/blob/master/src/Response.php). # Advanced Utopia @@ -149,28 +149,28 @@ use Utopia\Http\Validator\Wildcard; $http = new Server("0.0.0.0", 8080); Http::init(function($response) { - /* - Example of global init method. Do stuff that is common to all your endpoints in all groups. + /* + Example of global init method. Do stuff that is common to all your endpoints in all groups. This can include things like authentication and authorisation checks, implementing rate limits and so on.. */ }, ['response']); Http::init(function($response) { - /* + /* Example of init method for group1. Do stuff that is common to all your endpoints in group1. This can include things like authentication and authorisation checks, implementing rate limits and so on.. */ }, ['response'], 'group1'); Http::init(function($response) { - /* - Example of init method for group2. Do stuff that is common to all your endpoints in group2. + /* + Example of init method for group2. Do stuff that is common to all your endpoints in group2. This can include things like authentication and authorisation checks, implementing rate limits and so on.. */ }, ['response'], 'group2'); Http::shutdown(function($request) { - /* + /* Example of global shutdown method. Do stuff that needs to be performed at the end of each request for all groups. '*' (Wildcard validator) is optional. This can include cleanups, logging information, recording usage stats, closing database connections and so on.. @@ -179,7 +179,7 @@ Http::shutdown(function($request) { }, ['request'], '*'); Http::shutdown(function($request) { - /* + /* Example of shutdown method of group1. Do stuff that needs to be performed at the end of each request for all groups. This can include cleanups, logging information, recording usage stats, closing database connections and so on.. */ @@ -211,7 +211,7 @@ Http::put('/todos/:id') $response->json($data); } ); - + $http->start(); ``` @@ -224,7 +224,7 @@ For each endpoint, you can add the following properties described below. Let’s `groups` are used to define common functions that need to be executed. When you add a callback function to a group, the init hooks of the respective group are executed before the individual actions are executed. * #### Labels -`label` can be used to store metadata that is related to your endpoint. It’s a key-value store. Some use-cases can be using label to generate the documentation or the swagger specifications. +`label` can be used to store metadata that is related to your endpoint. It’s a key-value store. Some use-cases can be using label to generate the documentation or the swagger specifications. * #### Injections Since each action in Utopia depends on certain resources, `inject` is used to add the dependencies. `$response` and `$request` can be injected into the service. Utopia provides the http static functions to make global resources available to all utopia endpoints. @@ -238,7 +238,7 @@ Since each action in Utopia depends on certain resources, `inject` is used to ad Now that you’re familiar with routing in Utopia, let’s dive into the lifecycle of a utopia request in detail and learn about some of the lifecycle methods. ## Init and Shutdown Methods - + The Utopia http goes through the following lifecycle whenever it receives any request: ![untitled@2x](https://user-images.githubusercontent.com/43381712/146966398-0f4af03b-213e-47d7-9002-01983053c5aa.png) @@ -248,7 +248,7 @@ In case an error occurs anywhere during the execution, the workflow executes the The init and shutdown methods take three params: 1. Callback function - 2. Array of resources required by the callback + 2. Array of resources required by the callback 3. The endpoint group for which the callback is intended to run * ### Init @@ -256,9 +256,9 @@ The init and shutdown methods take three params: 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 `'*'`. ```php Http::init(function($response) { - /* - Do stuff that is common to all your endpoints. - This can include things like authentication and authorisation checks, implementing rate limits and so on.. + /* + Do stuff that is common to all your endpoints. + This can include things like authentication and authorisation checks, implementing rate limits and so on.. */ }, ['response'], '*'); ``` @@ -269,8 +269,8 @@ Utopia's shutdown callback is used to perform cleanup tasks after a request. Thi ```php Http::shutdown(function($request) { - /* - Do stuff that needs to be performed at the end of each request. + /* + Do stuff that needs to be performed at the end of each request. This can include cleanups, logging information, recording usage stats, closing database connections and so on.. */ @@ -279,7 +279,7 @@ Http::shutdown(function($request) { # Running Locally -If you have PHP and Composer installed on your device, you can run Utopia apps locally by downloading the Utopia-PHP/framework dependency using `composer require utopia-php/framework` command. +If you have PHP and Composer installed on your device, you can run Utopia apps locally by downloading the utopia-php/http dependency using `composer require utopia-php/http` command. > Utopia Framework requires PHP 7.3 or later. We recommend using the latest PHP version whenever possible. diff --git a/example/composer.json b/example/composer.json index 999df3c0..8e35bc2e 100644 --- a/example/composer.json +++ b/example/composer.json @@ -1,6 +1,6 @@ { "name": "utopia-php/http-app", "require": { - "utopia-php/framework": "0.33.*" + "utopia-php/http": "0.33.*" } } \ No newline at end of file diff --git a/tests/Validator/DomainTest.php b/tests/Validator/DomainTest.php index d8fa4de4..5e9e544f 100644 --- a/tests/Validator/DomainTest.php +++ b/tests/Validator/DomainTest.php @@ -5,7 +5,7 @@ * @package Framework * @subpackage Tests * - * @link https://github.com/utopia-php/framework + * @link https://github.com/utopia-php/http * @author Appwrite Team * @version 1.0 RC4 * @license The MIT License (MIT) diff --git a/tests/Validator/HostTest.php b/tests/Validator/HostTest.php index 7d845f33..fc75907d 100644 --- a/tests/Validator/HostTest.php +++ b/tests/Validator/HostTest.php @@ -5,7 +5,7 @@ * @package Framework * @subpackage Tests * - * @link https://github.com/utopia-php/framework + * @link https://github.com/utopia-php/http * @author Appwrite Team * @version 1.0 RC4 * @license The MIT License (MIT) diff --git a/tests/Validator/IPTest.php b/tests/Validator/IPTest.php index 88c71994..ea699feb 100644 --- a/tests/Validator/IPTest.php +++ b/tests/Validator/IPTest.php @@ -5,7 +5,7 @@ * @package Framework * @subpackage Tests * - * @link https://github.com/utopia-php/framework + * @link https://github.com/utopia-php/http * @author Appwrite Team * @version 1.0 RC4 * @license The MIT License (MIT) diff --git a/tests/Validator/URLTest.php b/tests/Validator/URLTest.php index f092890f..5e8c94f6 100644 --- a/tests/Validator/URLTest.php +++ b/tests/Validator/URLTest.php @@ -5,7 +5,7 @@ * @package Framework * @subpackage Tests * - * @link https://github.com/utopia-php/framework + * @link https://github.com/utopia-php/http * @author Appwrite Team * @version 1.0 RC4 * @license The MIT License (MIT) From 43f884715e03b8aa4e87d8e77478ff032391c969 Mon Sep 17 00:00:00 2001 From: Torsten Dittmann Date: Fri, 5 Jan 2024 11:49:09 +0100 Subject: [PATCH 2/2] fix: example version to latest --- example/composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/example/composer.json b/example/composer.json index 8e35bc2e..383d90aa 100644 --- a/example/composer.json +++ b/example/composer.json @@ -1,6 +1,6 @@ { "name": "utopia-php/http-app", "require": { - "utopia-php/http": "0.33.*" + "utopia-php/http": "latest" } } \ No newline at end of file