Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 77 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
name: "CI"

on:
pull_request:

jobs:
analyze:
name: Analyze
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Setup PHP 8.3
uses: shivammathur/setup-php@v2
with:
php-version: "8.3"
coverage: none

- name: Validate composer.json and composer.lock
run: composer validate --strict

- name: Install dependencies
run: composer install --prefer-dist --no-progress

- name: Run Analyze
run: composer analyze

format:
name: Format
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Setup PHP 8.3
uses: shivammathur/setup-php@v2
with:
php-version: "8.3"
coverage: none

- name: Validate composer.json and composer.lock
run: composer validate --strict

- name: Install dependencies
run: composer install --prefer-dist --no-progress

- name: Run Format
run: composer format:check

tests:
name: Tests
runs-on: ubuntu-latest
strategy:
matrix:
php-versions: ["8.2", "8.3", "nightly"]

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Setup PHP ${{ matrix.php-versions }}
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-versions }}
coverage: none

- name: Validate composer.json and composer.lock
run: composer validate --strict

- name: Install dependencies
run: composer install --prefer-dist --no-progress

- name: Run Tests
run: composer test
17 changes: 0 additions & 17 deletions .github/workflows/codeql-analysis.yml

This file was deleted.

16 changes: 0 additions & 16 deletions .github/workflows/lint.yml

This file was deleted.

28 changes: 0 additions & 28 deletions .github/workflows/test.yml

This file was deleted.

28 changes: 21 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
![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 DI library is simple and lite library for managing dependency injections. This library is aiming to be as simple and easy to learn and use. This library is maintained by the [Appwrite team](https://appwrite.io).
Utopia DI is a small dependency injection container with scoped resources. It is designed to stay simple while still covering the resource lifecycle used across the Utopia libraries. This library is maintained by the [Appwrite team](https://appwrite.io).

Although this library is part of the Utopia Framework project it is dependency free, and can be used as standalone with any other PHP project or framework.

Expand All @@ -15,25 +15,39 @@ Although this library is part of the Utopia Framework project it is dependency f
Install using Composer:

```bash
composer require utopia-php/http
composer require utopia-php/di
```


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

use Utopia\DI\Container;

TBD
$di = new Container();

$di->setResource('config', fn () => ['region' => 'eu-west-1']);
$di->setResource('db', fn (array $config) => new PDO('dsn', 'username', 'password'), ['config']);
Comment thread
ChiragAgg5k marked this conversation as resolved.
Outdated

$db = $di->getResource('db', 'request-1');
```

Resources are cached per context. Definitions registered in the default `utopia` context are automatically available in other contexts, while context-specific definitions override the default for that request.

```php
$di->setResource('request-id', fn () => 'req-1', context: 'request-1');

$requestResources = $di->getResources(['db', 'request-id'], 'request-1');

$di->purge('request-1');
```

## System Requirements

Utopia HTTP requires PHP 8.1 or later. We recommend using the latest PHP version whenever possible.
Utopia DI requires PHP 8.2 or later. We recommend using the latest PHP version whenever possible.

## More from Utopia

Our ecosystem supports other thin PHP projects aiming to extend the core PHP Utopia HTTP.
Our ecosystem supports other thin PHP projects aiming to extend the core PHP Utopia libraries.

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.

Expand All @@ -45,7 +59,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/http/blob/master/CONTRIBUTING.md) for more info.
You can refer to the [Contributing Guide](https://github.com/utopia-php/di/blob/master/CONTRIBUTING.md) for more info.

For security issues, please email security@appwrite.io instead of posting a public issue in GitHub.

Expand Down
10 changes: 5 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"php",
"framework",
"http",
"upf"
"utopia"
],
"license": "MIT",
"autoload": {
Expand All @@ -16,19 +16,19 @@
}
},
"scripts": {
"lint": "vendor/bin/pint --test",
"format": "vendor/bin/pint",
"check": "vendor/bin/phpstan analyse -c phpstan.neon",
"format:check": "vendor/bin/pint --test",
"analyze": "vendor/bin/phpstan analyse -c phpstan.neon",
"test": "vendor/bin/phpunit --configuration phpunit.xml"
},
"require": {
"php": ">=8.2"
},
"require-dev": {
"phpunit/phpunit": "^9.5.25",
"laravel/pint": "^1.2",
"laravel/pint": "^1.27",
"swoole/ide-helper": "4.8.3",
"phpstan/phpstan": "^1.10",
"phpstan/phpstan": "^2.1",
"phpbench/phpbench": "^1.2"
}
}
48 changes: 22 additions & 26 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ parameters:
level: 5
paths:
- src
- tests
- tests
Loading