Skip to content

Commit

Permalink
Merge pull request #376 from utopia-php/feat-framework-v2
Browse files Browse the repository at this point in the history
Feat. HTTP Framework V2
  • Loading branch information
christyjacob4 committed Sep 5, 2024
2 parents 24b29bc + bb2a687 commit 1e97fc8
Show file tree
Hide file tree
Showing 41 changed files with 2,380 additions and 2,136 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ A list of the utopia/php concepts and their relevant equivalent using the differ
- **Document** - A simple JSON object that will be stored in one of the utopia/database collections. For SQL-based adapters, this will be equivalent to a row. For a No-SQL adapter, this will equivalent to a native document.
- **Attribute** - A simple document attribute. For SQL-based adapters, this will be equivalent to a column. For a No-SQL adapter, this will equivalent to a native document field.
- **Index** - A simple collection index used to improve the performance of your database queries.
- **Permissions** - Using permissions, you can decide which roles have read, create, update and delete access for a specific document. The special attribute `$permissions` is used to store permission metadata for each document in the collection. A permission role can be any string you want. You can use `Authorization::setRole()` to delegate new roles to your users, once obtained a new role a user would gain read, create, update or delete access to a relevant document.
- **Permissions** - Using permissions, you can decide which roles have read, create, update and delete access for a specific document. The special attribute `$permissions` is used to store permission metadata for each document in the collection. A permission role can be any string you want. You can use `$authorization->addRole()` to delegate new roles to your users, once obtained a new role a user would gain read, create, update or delete access to a relevant document.

### Filters

Expand Down
2 changes: 1 addition & 1 deletion bin/tasks/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
use Utopia\Database\Adapter\Mongo;
use Utopia\Database\Adapter\MySQL;
use Utopia\Database\Database;
use Utopia\Http\Validator\Text;
use Utopia\Mongo\Client;
use Utopia\Validator\Text;

/**
* @Example
Expand Down
19 changes: 10 additions & 9 deletions bin/tasks/load.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,11 @@
use Utopia\Database\Helpers\Permission;
use Utopia\Database\Helpers\Role;
use Utopia\Database\Validator\Authorization;
use Utopia\Http\Validator\Numeric;
use Utopia\Http\Validator\Text;
use Utopia\Mongo\Client;
use Utopia\Validator\Numeric;
use Utopia\Validator\Text;

$authorization = new Authorization();

/**
* @Example
Expand Down Expand Up @@ -61,7 +63,7 @@
$database->setNamespace($namespace);

// Outline collection schema
createSchema($database);
$createSchema($database);

// reclaim resources
$database = null;
Expand Down Expand Up @@ -121,7 +123,7 @@
$database->setNamespace($namespace);

// Outline collection schema
createSchema($database);
$createSchema($database);

// reclaim resources
$database = null;
Expand Down Expand Up @@ -183,7 +185,7 @@
$database->setNamespace($namespace);

// Outline collection schema
createSchema($database);
$createSchema($database);

// Fill DB
$faker = Factory::create();
Expand Down Expand Up @@ -226,14 +228,13 @@
});


function createSchema(Database $database): void
{
$createSchema = function (Database $database) use ($authorization): void {
if ($database->exists($database->getDatabase())) {
$database->delete($database->getDatabase());
}
$database->create();

Authorization::setRole(Role::any()->toString());
$authorization->addRole(Role::any()->toString());

$database->createCollection('articles', permissions: [
Permission::create(Role::any()),
Expand All @@ -247,7 +248,7 @@ function createSchema(Database $database): void
$database->createAttribute('articles', 'views', Database::VAR_INTEGER, 0, true);
$database->createAttribute('articles', 'tags', Database::VAR_STRING, 0, true, array: true);
$database->createIndex('articles', 'text', Database::INDEX_FULLTEXT, ['text']);
}
};

function createDocument($database, Generator $faker): void
{
Expand Down
24 changes: 11 additions & 13 deletions bin/tasks/query.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,9 @@
use Utopia\Database\Adapter\MySQL;
use Utopia\Database\Database;
use Utopia\Database\Query;
use Utopia\Database\Validator\Authorization;
use Utopia\Http\Validator\Numeric;
use Utopia\Http\Validator\Text;
use Utopia\Mongo\Client;
use Utopia\Validator\Numeric;
use Utopia\Validator\Text;

/**
* @Example
Expand Down Expand Up @@ -84,35 +83,35 @@

$report = [];

$count = setRoles($faker, 1);
$count = $setRoles($faker, 1);
Console::info("\n{$count} roles:");
$report[] = [
'roles' => $count,
'results' => runQueries($database, $limit)
];

$count = setRoles($faker, 100);
$count = $setRoles($faker, 100);
Console::info("\n{$count} roles:");
$report[] = [
'roles' => $count,
'results' => runQueries($database, $limit)
];

$count = setRoles($faker, 400);
$count = $setRoles($faker, 400);
Console::info("\n{$count} roles:");
$report[] = [
'roles' => $count,
'results' => runQueries($database, $limit)
];

$count = setRoles($faker, 500);
$count = $setRoles($faker, 500);
Console::info("\n{$count} roles:");
$report[] = [
'roles' => $count,
'results' => runQueries($database, $limit)
];

$count = setRoles($faker, 1000);
$count = $setRoles($faker, 1000);
Console::info("\n{$count} roles:");
$report[] = [
'roles' => $count,
Expand All @@ -136,13 +135,12 @@
Console::error($error->getMessage());
});

function setRoles($faker, $count): int
{
$setRoles = function ($faker, $count) use ($authorization): int {
for ($i = 0; $i < $count; $i++) {
Authorization::setRole($faker->numerify('user####'));
$authorization->addRole($faker->numerify('user####'));
}
return \count(Authorization::getRoles());
}
return \count($authorization->getRoles());
};

function runQueries(Database $database, int $limit): array
{
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"ext-pdo": "*",
"ext-mbstring": "*",
"php": ">=8.0",
"utopia-php/framework": "0.33.*",
"utopia-php/framework": "1.0.*",
"utopia-php/cache": "0.10.*",
"utopia-php/mongo": "0.3.*"
},
Expand All @@ -45,7 +45,7 @@
"phpunit/phpunit": "9.6.*",
"pcov/clobber": "2.0.*",
"swoole/ide-helper": "5.1.3",
"utopia-php/cli": "0.14.*",
"utopia-php/cli": "0.19.*",
"laravel/pint": "1.17.*",
"phpstan/phpstan": "1.11.*",
"rregeer/phpunit-coverage-check": "0.3.*"
Expand Down
Loading

0 comments on commit 1e97fc8

Please sign in to comment.