Skip to content
Merged
Show file tree
Hide file tree
Changes from 13 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
20 changes: 0 additions & 20 deletions .github/ISSUE_TEMPLATE/.github/workflows/linter.yml

This file was deleted.

100 changes: 100 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
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

refactor:
name: Refactor
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 tools/rector/composer.json
run: composer validate --strict --working-dir=tools/rector

- name: Install Rector dependencies
run: composer install --prefer-dist --no-progress --working-dir=tools/rector

- name: Run Refactor Check
run: composer refactor:check

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", "8.4"]

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.

3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/vendor/
/.idea/
*.cache
*.cache
/tools/rector/vendor/
68 changes: 59 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
<img height="45" src="docs/logo.png" alt="Logo">
</p>

[![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)
[![CI](https://github.com/utopia-php/di/actions/workflows/ci.yml/badge.svg)](https://github.com/utopia-php/di/actions/workflows/ci.yml)
![Total Downloads](https://img.shields.io/packagist/dt/utopia-php/di.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 PSR-11 compatible dependency injection container with parent-child scopes. It is designed to stay simple while still covering the dependency 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,75 @@ 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 Psr\Container\ContainerInterface;
use Utopia\DI\Container;
use Utopia\DI\Dependency;

$di = new Container();

$di->set(
key: 'age',
factory: new Dependency(
injections: [],
callback: fn () => 25
)
);

$di->set(
key: 'john',
factory: new Dependency(
injections: ['age'],
callback: fn (int $age) => 'John Doe is '.$age.' years old.'
)
);

$john = $di->get('john');
```

You can still register plain factories directly when you want access to the container instance.

```php
$di->set(
key: 'config',
factory: fn (ContainerInterface $container) => [
'dsn' => 'mysql:host=localhost;dbname=app',
'username' => 'root',
'password' => 'secret',
]
);

$request = $di->scope();

$request->set(
key: 'db',
factory: fn (ContainerInterface $container) => new PDO(
$container->get('config')['dsn'],
$container->get('config')['username'],
$container->get('config')['password']
)
);
```

TBD
Factories are resolved once per container instance. Child scopes fall back to the parent container until they override a definition locally.

```php
$child = $di->scope();
$child->get('john');
Comment thread
ChiragAgg5k marked this conversation as resolved.
Outdated
```

## 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 +95,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
45 changes: 30 additions & 15 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,31 +4,46 @@
"type": "library",
"keywords": [
"php",
"framework",
"http",
"upf"
"di",
"dependency-injection",
"container",
"psr-11",
"utopia"
],
"license": "MIT",
"require": {
"php": ">=8.2",
"psr/container": "^2.0"
},
"require-dev": {
"laravel/pint": "^1.27",
"phpbench/phpbench": "^1.2",
"phpstan/phpstan": "^2.1",
"phpunit/phpunit": "^9.5.25",
"swoole/ide-helper": "4.8.3"
},
"autoload": {
"psr-4": {
"Utopia\\": "src/",
"Tests\\E2E\\": "tests/e2e"
}
},
"config": {
"platform": {
"php": "8.2"
}
},
"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 --memory-limit=512M",
"refactor": "tools/rector/vendor/bin/rector process --config=rector.php",
"refactor:check": "tools/rector/vendor/bin/rector process --dry-run --config=rector.php",
"fix": [
"@refactor",
"@analyze",
"@format"
],
"test": "vendor/bin/phpunit --configuration phpunit.xml"
},
"require": {
"php": ">=8.2"
},
"require-dev": {
"phpunit/phpunit": "^9.5.25",
"laravel/pint": "^1.2",
"swoole/ide-helper": "4.8.3",
"phpstan/phpstan": "^1.10",
"phpbench/phpbench": "^1.2"
}
}
Loading
Loading