diff --git a/app/controllers/api/account.php b/app/controllers/api/account.php index 19e63fde11..c028409dcd 100644 --- a/app/controllers/api/account.php +++ b/app/controllers/api/account.php @@ -669,26 +669,24 @@ App::post('/v1/account/sessions/magic-url') $userId = $userId == 'unique()' ? $dbForInternal->getId() : $userId; - $user = Authorization::skip(function () use ($dbForInternal, $userId, $email) { - return $dbForInternal->createDocument('users', new Document([ - '$id' => $userId, - '$read' => ['role:all'], - '$write' => ['user:' . $userId], - 'email' => $email, - 'emailVerification' => false, - 'status' => true, - 'password' => null, - 'passwordUpdate' => \time(), - 'registration' => \time(), - 'reset' => false, - 'prefs' => [], - 'sessions' => [], - 'tokens' => [], - 'memberships' => [], - 'search' => implode(' ', [$userId, $email]), - 'deleted' => false - ])); - }); + $user = Authorization::skip(fn () => $dbForInternal->createDocument('users', new Document([ + '$id' => $userId, + '$read' => ['role:all'], + '$write' => ['user:' . $userId], + 'email' => $email, + 'emailVerification' => false, + 'status' => true, + 'password' => null, + 'passwordUpdate' => \time(), + 'registration' => \time(), + 'reset' => false, + 'prefs' => [], + 'sessions' => [], + 'tokens' => [], + 'memberships' => [], + 'search' => implode(' ', [$userId, $email]), + 'deleted' => false + ]))); $mails->setParam('event', 'users.create'); $audits->setParam('event', 'users.create'); diff --git a/app/controllers/api/avatars.php b/app/controllers/api/avatars.php index f5f40cd3cd..161e87b130 100644 --- a/app/controllers/api/avatars.php +++ b/app/controllers/api/avatars.php @@ -95,9 +95,7 @@ App::get('/v1/avatars/credit-cards/:code') ->param('height', 100, new Range(0, 2000), 'Image height. Pass an integer between 0 to 2000. Defaults to 100.', true) ->param('quality', 100, new Range(0, 100), 'Image quality. Pass an integer between 0 to 100. Defaults to 100.', true) ->inject('response') - ->action(function ($code, $width, $height, $quality, $response) use ($avatarCallback) { - return $avatarCallback('credit-cards', $code, $width, $height, $quality, $response); - }); + ->action(fn($code, $width, $height, $quality, $response) => $avatarCallback('credit-cards', $code, $width, $height, $quality, $response)); App::get('/v1/avatars/browsers/:code') ->desc('Get Browser Icon') @@ -115,9 +113,7 @@ App::get('/v1/avatars/browsers/:code') ->param('height', 100, new Range(0, 2000), 'Image height. Pass an integer between 0 to 2000. Defaults to 100.', true) ->param('quality', 100, new Range(0, 100), 'Image quality. Pass an integer between 0 to 100. Defaults to 100.', true) ->inject('response') - ->action(function ($code, $width, $height, $quality, $response) use ($avatarCallback) { - return $avatarCallback('browsers', $code, $width, $height, $quality, $response); - }); + ->action(fn($code, $width, $height, $quality, $response) => $avatarCallback('browsers', $code, $width, $height, $quality, $response)); App::get('/v1/avatars/flags/:code') ->desc('Get Country Flag') @@ -135,9 +131,7 @@ App::get('/v1/avatars/flags/:code') ->param('height', 100, new Range(0, 2000), 'Image height. Pass an integer between 0 to 2000. Defaults to 100.', true) ->param('quality', 100, new Range(0, 100), 'Image quality. Pass an integer between 0 to 100. Defaults to 100.', true) ->inject('response') - ->action(function ($code, $width, $height, $quality, $response) use ($avatarCallback) { - return $avatarCallback('flags', $code, $width, $height, $quality, $response); - }); + ->action(fn($code, $width, $height, $quality, $response) => $avatarCallback('flags', $code, $width, $height, $quality, $response)); App::get('/v1/avatars/image') ->desc('Get Image from URL') diff --git a/app/controllers/api/database.php b/app/controllers/api/database.php index dca931afe2..8781f6ab0d 100644 --- a/app/controllers/api/database.php +++ b/app/controllers/api/database.php @@ -1650,9 +1650,7 @@ App::post('/v1/database/collections/:collectionId/documents') try { if ($collection->getAttribute('permission') === 'collection') { /** @var Document $document */ - $document = Authorization::skip(function() use ($dbForExternal, $collectionId, $data) { - return $dbForExternal->createDocument($collectionId, new Document($data)); - }); + $document = Authorization::skip(fn() => $dbForExternal->createDocument($collectionId, new Document($data))); } else { $document = $dbForExternal->createDocument($collectionId, new Document($data)); } @@ -1808,9 +1806,7 @@ App::get('/v1/database/collections/:collectionId/documents/:documentId') if ($collection->getAttribute('permission') === 'collection') { /** @var Document $document */ - $document = Authorization::skip(function() use ($dbForExternal, $collectionId, $documentId) { - return $dbForExternal->getDocument($collectionId, $documentId); - }); + $document = Authorization::skip(fn() => $dbForExternal->getDocument($collectionId, $documentId)); } else { $document = $dbForExternal->getDocument($collectionId, $documentId); } @@ -2014,9 +2010,7 @@ App::patch('/v1/database/collections/:collectionId/documents/:documentId') try { if ($collection->getAttribute('permission') === 'collection') { /** @var Document $document */ - $document = Authorization::skip(function() use ($dbForExternal, $collection, $document, $data) { - return $dbForExternal->updateDocument($collection->getId(), $document->getId(), new Document($data)); - }); + $document = Authorization::skip(fn() => $dbForExternal->updateDocument($collection->getId(), $document->getId(), new Document($data))); } else { $document = $dbForExternal->updateDocument($collection->getId(), $document->getId(), new Document($data)); } @@ -2092,9 +2086,7 @@ App::delete('/v1/database/collections/:collectionId/documents/:documentId') if ($collection->getAttribute('permission') === 'collection') { /** @var Document $document */ - $document = Authorization::skip(function() use ($dbForExternal, $collectionId, $documentId) { - return $dbForExternal->getDocument($collectionId, $documentId); - }); + $document = Authorization::skip(fn() => $dbForExternal->getDocument($collectionId, $documentId)); } else { $document = $dbForExternal->getDocument($collectionId, $documentId); } diff --git a/app/controllers/api/functions.php b/app/controllers/api/functions.php index b6a67191f3..869efadeb7 100644 --- a/app/controllers/api/functions.php +++ b/app/controllers/api/functions.php @@ -807,9 +807,7 @@ App::get('/v1/functions/:functionId/executions') /** @var Appwrite\Utopia\Response $response */ /** @var Utopia\Database\Database $dbForInternal */ - $function = Authorization::skip(function() use ($dbForInternal, $functionId) { - return $dbForInternal->getDocument('functions', $functionId); - }); + $function = Authorization::skip(fn() => $dbForInternal->getDocument('functions', $functionId)); if ($function->isEmpty()) { throw new Exception('Function not found', 404); diff --git a/app/http.php b/app/http.php index 28b070d3a4..78152126be 100644 --- a/app/http.php +++ b/app/http.php @@ -73,17 +73,8 @@ $http->on('start', function (Server $http) use ($payloadSize, $register) { } } while ($attempts < $max); - App::setResource('db', function () use (&$db) { - return $db; - }); - - App::setResource('cache', function () use (&$redis) { - return $redis; - }); - - App::setResource('app', function() use (&$app) { - return $app; - }); + App::setResource('db', fn() => $db); + App::setResource('cache', fn() => $redis); $dbForConsole = $app->getResource('dbForConsole'); /** @var Utopia\Database\Database $dbForConsole */ @@ -170,14 +161,9 @@ $http->on('request', function (SwooleRequest $swooleRequest, SwooleResponse $swo $db = $register->get('dbPool')->get(); $redis = $register->get('redisPool')->get(); - App::setResource('db', function () use (&$db) { - return $db; - }); + App::setResource('db', fn() => $db); + App::setResource('cache', fn() => $redis); - App::setResource('cache', function () use (&$redis) { - return $redis; - }); - try { Authorization::cleanRoles(); Authorization::setRole('role:all'); diff --git a/app/init.php b/app/init.php index 45cdf438b6..e97e51ae1f 100644 --- a/app/init.php +++ b/app/init.php @@ -543,9 +543,7 @@ Locale::setLanguageFromJSON('zh-tw', __DIR__.'/config/locale/translations/zh-tw. // Runtime Execution -App::setResource('register', function() use ($register) { - return $register; -}); +App::setResource('register', fn() => $register); App::setResource('layout', function($locale) { $layout = new View(__DIR__.'/views/layouts/default.phtml'); diff --git a/app/realtime.php b/app/realtime.php index ec4feefa21..5215cd2477 100644 --- a/app/realtime.php +++ b/app/realtime.php @@ -87,9 +87,7 @@ $server->onStart(function () use ($stats, $register, $containerId, &$statsDocume 'timestamp' => time(), 'value' => '{}' ]); - $statsDocument = Authorization::skip(function () use ($database, $document) { - return $database->createDocument('realtime', $document); - }); + $statsDocument = Authorization::skip(fn() => $database->createDocument('realtime', $document)); } catch (\Throwable $th) { Console::error('[Error] Type: ' . get_class($th)); Console::error('[Error] Message: ' . $th->getMessage()); @@ -141,9 +139,7 @@ $server->onStart(function () use ($stats, $register, $containerId, &$statsDocume ->setAttribute('timestamp', time()) ->setAttribute('value', json_encode($payload)); - Authorization::skip(function () use ($database, $statsDocument) { - $database->updateDocument('realtime', $statsDocument->getId(), $statsDocument); - }); + Authorization::skip(fn() => $database->updateDocument('realtime', $statsDocument->getId(), $statsDocument)); } catch (\Throwable $th) { Console::error('[Error] Type: ' . get_class($th)); Console::error('[Error] Message: ' . $th->getMessage()); @@ -171,11 +167,9 @@ $server->onWorkerStart(function (int $workerId) use ($server, $register, $stats, $payload = []; - $list = Authorization::skip(function () use ($database) { - return $database->find('realtime', [ + $list = Authorization::skip(fn() => $database->find('realtime', [ new Query('timestamp', Query::TYPE_GREATER, [(time() - 15)]) - ]); - }); + ])); /** * Aggregate stats across containers. @@ -329,21 +323,10 @@ $server->onOpen(function (int $connection, SwooleRequest $request) use ($server, Console::info("Connection open (user: {$connection})"); - App::setResource('db', function () use (&$db) { - return $db; - }); - - App::setResource('cache', function () use (&$redis) { - return $redis; - }); - - App::setResource('request', function () use ($request) { - return $request; - }); - - App::setResource('response', function () use ($response) { - return $response; - }); + App::setResource('db', fn() => $db); + App::setResource('cache', fn() => $redis); + App::setResource('request', fn() => $request); + App::setResource('response', fn() => $response); try { /** @var \Utopia\Database\Document $user */ diff --git a/app/workers/functions.php b/app/workers/functions.php index b4bc89f370..67c59ff679 100644 --- a/app/workers/functions.php +++ b/app/workers/functions.php @@ -481,16 +481,14 @@ class FunctionsV1 extends Worker Console::info('Function executed in ' . ($executionEnd - $executionStart) . ' seconds, status: ' . $functionStatus); - $execution = Authorization::skip(function() use ($database, $execution, $tag, $functionStatus, $exitCode, $stdout, $stderr, $executionTime) { - return $database->updateDocument('executions', $execution->getId(), new Document(array_merge($execution->getArrayCopy(), [ + $execution = Authorization::skip(fn() => $database->updateDocument('executions', $execution->getId(), new Document(array_merge($execution->getArrayCopy(), [ 'tagId' => $tag->getId(), 'status' => $functionStatus, 'exitCode' => $exitCode, 'stdout' => \utf8_encode(\mb_substr($stdout, -8000)), // log last 8000 chars output 'stderr' => \utf8_encode(\mb_substr($stderr, -8000)), // log last 8000 chars output 'time' => (float)$executionTime, - ]))); - }); + ])))); $executionModel = new Execution(); $executionUpdate = new Event('v1-webhooks', 'WebhooksV1'); diff --git a/tests/e2e/Services/Realtime/RealtimeCustomClientTest.php b/tests/e2e/Services/Realtime/RealtimeCustomClientTest.php index 6b815c9043..0c5b7b61e7 100644 --- a/tests/e2e/Services/Realtime/RealtimeCustomClientTest.php +++ b/tests/e2e/Services/Realtime/RealtimeCustomClientTest.php @@ -569,7 +569,7 @@ class RealtimeCustomClientTest extends Scope 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-key' => $this->getProject()['apiKey'] ]), [ - 'attributeId' => 'name', + 'key' => 'name', 'size' => 256, 'required' => true, ]);