diff --git a/app/controllers/api/account.php b/app/controllers/api/account.php index 309277981..16e7541d0 100644 --- a/app/controllers/api/account.php +++ b/app/controllers/api/account.php @@ -660,7 +660,7 @@ App::get('/v1/account/logs') ->label('sdk.namespace', 'account') ->label('sdk.method', 'getLogs') ->label('sdk.description', '/docs/references/account/get-logs.md') - ->action(function ($response, $register, $project, $user) { + ->action(function ($response, $register, $project, $user, $locale) { /** @var Utopia\Response $response */ /** @var Appwrite\Database\Document $project */ /** @var Appwrite\Database\Document $user */ @@ -726,7 +726,7 @@ App::get('/v1/account/logs') } $response->json($output); - }, ['response', 'register', 'project', 'user']); + }, ['response', 'register', 'project', 'user', 'locale']); App::patch('/v1/account/name') ->desc('Update Account Name') diff --git a/app/controllers/api/storage.php b/app/controllers/api/storage.php index 656bed297..3b7f9af96 100644 --- a/app/controllers/api/storage.php +++ b/app/controllers/api/storage.php @@ -577,7 +577,7 @@ App::delete('/v1/storage/files/:fileId') ; $response->noContent(); - }, ['fileId', 'response', 'projectDB', 'webhook', 'audit', 'usage']); + }, ['response', 'projectDB', 'webhook', 'audit', 'usage']); // App::get('/v1/storage/files/:fileId/scan') // ->desc('Scan Storage') diff --git a/app/controllers/mock.php b/app/controllers/mock.php index 9adfce55b..1676d3f8e 100644 --- a/app/controllers/mock.php +++ b/app/controllers/mock.php @@ -19,10 +19,8 @@ App::get('/v1/mock/tests/foo') ->param('x', '', function () { return new Text(100); }, 'Sample string param') ->param('y', '', function () { return new Numeric(); }, 'Sample numeric param') ->param('z', null, function () { return new ArrayList(new Text(256)); }, 'Sample array param') - ->action( - function ($x, $y, $z) { - } - ); + ->action(function ($x, $y, $z) { + }); App::post('/v1/mock/tests/foo') ->desc('Mock a post request for SDK tests') @@ -33,10 +31,8 @@ App::post('/v1/mock/tests/foo') ->param('x', '', function () { return new Text(100); }, 'Sample string param') ->param('y', '', function () { return new Numeric(); }, 'Sample numeric param') ->param('z', null, function () { return new ArrayList(new Text(256)); }, 'Sample array param') - ->action( - function ($x, $y, $z) { - } - ); + ->action(function ($x, $y, $z) { + }); App::patch('/v1/mock/tests/foo') ->desc('Mock a patch request for SDK tests') @@ -47,10 +43,8 @@ App::patch('/v1/mock/tests/foo') ->param('x', '', function () { return new Text(100); }, 'Sample string param') ->param('y', '', function () { return new Numeric(); }, 'Sample numeric param') ->param('z', null, function () { return new ArrayList(new Text(256)); }, 'Sample array param') - ->action( - function ($x, $y, $z) { - } - ); + ->action(function ($x, $y, $z) { + }); App::put('/v1/mock/tests/foo') ->desc('Mock a put request for SDK tests') @@ -61,10 +55,8 @@ App::put('/v1/mock/tests/foo') ->param('x', '', function () { return new Text(100); }, 'Sample string param') ->param('y', '', function () { return new Numeric(); }, 'Sample numeric param') ->param('z', null, function () { return new ArrayList(new Text(256)); }, 'Sample array param') - ->action( - function ($x, $y, $z) { - } - ); + ->action(function ($x, $y, $z) { + }); App::delete('/v1/mock/tests/foo') ->desc('Mock a delete request for SDK tests') @@ -75,10 +67,8 @@ App::delete('/v1/mock/tests/foo') ->param('x', '', function () { return new Text(100); }, 'Sample string param') ->param('y', '', function () { return new Numeric(); }, 'Sample numeric param') ->param('z', null, function () { return new ArrayList(new Text(256)); }, 'Sample array param') - ->action( - function ($x, $y, $z) { - } - ); + ->action(function ($x, $y, $z) { + }); App::get('/v1/mock/tests/bar') ->desc('Mock a get request for SDK tests') @@ -89,10 +79,8 @@ App::get('/v1/mock/tests/bar') ->param('x', '', function () { return new Text(100); }, 'Sample string param') ->param('y', '', function () { return new Numeric(); }, 'Sample numeric param') ->param('z', null, function () { return new ArrayList(new Text(256)); }, 'Sample array param') - ->action( - function ($x, $y, $z) { - } - ); + ->action(function ($x, $y, $z) { + }); App::post('/v1/mock/tests/bar') ->desc('Mock a post request for SDK tests') @@ -103,10 +91,8 @@ App::post('/v1/mock/tests/bar') ->param('x', '', function () { return new Text(100); }, 'Sample string param') ->param('y', '', function () { return new Numeric(); }, 'Sample numeric param') ->param('z', null, function () { return new ArrayList(new Text(256)); }, 'Sample array param') - ->action( - function ($x, $y, $z) { - } - ); + ->action(function ($x, $y, $z) { + }); App::patch('/v1/mock/tests/bar') ->desc('Mock a patch request for SDK tests') @@ -117,10 +103,8 @@ App::patch('/v1/mock/tests/bar') ->param('x', '', function () { return new Text(100); }, 'Sample string param') ->param('y', '', function () { return new Numeric(); }, 'Sample numeric param') ->param('z', null, function () { return new ArrayList(new Text(256)); }, 'Sample array param') - ->action( - function ($x, $y, $z) { - } - ); + ->action(function ($x, $y, $z) { + }); App::put('/v1/mock/tests/bar') ->desc('Mock a put request for SDK tests') @@ -131,10 +115,8 @@ App::put('/v1/mock/tests/bar') ->param('x', '', function () { return new Text(100); }, 'Sample string param') ->param('y', '', function () { return new Numeric(); }, 'Sample numeric param') ->param('z', null, function () { return new ArrayList(new Text(256)); }, 'Sample array param') - ->action( - function ($x, $y, $z) { - } - ); + ->action(function ($x, $y, $z) { + }); App::delete('/v1/mock/tests/bar') ->desc('Mock a delete request for SDK tests') @@ -145,10 +127,8 @@ App::delete('/v1/mock/tests/bar') ->param('x', '', function () { return new Text(100); }, 'Sample string param') ->param('y', '', function () { return new Numeric(); }, 'Sample numeric param') ->param('z', null, function () { return new ArrayList(new Text(256)); }, 'Sample array param') - ->action( - function ($x, $y, $z) { - } - ); + ->action(function ($x, $y, $z) { + }); App::post('/v1/mock/tests/general/upload') ->desc('Mock a post request for SDK tests') @@ -161,32 +141,32 @@ App::post('/v1/mock/tests/general/upload') ->param('y', '', function () { return new Numeric(); }, 'Sample numeric param') ->param('z', null, function () { return new ArrayList(new Text(256)); }, 'Sample array param') ->param('file', [], function () { return new File(); }, 'Sample file param', false) - ->action( - function ($x, $y, $z, $file) use ($request) { - $file = $request->getFiles('file'); - $file['tmp_name'] = (\is_array($file['tmp_name'])) ? $file['tmp_name'] : [$file['tmp_name']]; - $file['name'] = (\is_array($file['name'])) ? $file['name'] : [$file['name']]; - $file['size'] = (\is_array($file['size'])) ? $file['size'] : [$file['size']]; + ->action(function ($x, $y, $z, $file, $request) { + /** @var Utopia\Request $request */ + + $file = $request->getFiles('file'); + $file['tmp_name'] = (\is_array($file['tmp_name'])) ? $file['tmp_name'] : [$file['tmp_name']]; + $file['name'] = (\is_array($file['name'])) ? $file['name'] : [$file['name']]; + $file['size'] = (\is_array($file['size'])) ? $file['size'] : [$file['size']]; - foreach ($file['name'] as $i => $name) { - if ($name !== 'file.png') { - throw new Exception('Wrong file name', 400); - } - } - - foreach ($file['size'] as $i => $size) { - if ($size !== 38756) { - throw new Exception('Wrong file size', 400); - } - } - - foreach ($file['tmp_name'] as $i => $tmpName) { - if (\md5(\file_get_contents($tmpName)) !== 'd80e7e6999a3eb2ae0d631a96fe135a4') { - throw new Exception('Wrong file uploaded', 400); - } + foreach ($file['name'] as $i => $name) { + if ($name !== 'file.png') { + throw new Exception('Wrong file name', 400); } } - ); + + foreach ($file['size'] as $i => $size) { + if ($size !== 38756) { + throw new Exception('Wrong file size', 400); + } + } + + foreach ($file['tmp_name'] as $i => $tmpName) { + if (\md5(\file_get_contents($tmpName)) !== 'd80e7e6999a3eb2ae0d631a96fe135a4') { + throw new Exception('Wrong file uploaded', 400); + } + } + }, ['request']); App::get('/v1/mock/tests/general/redirect') ->desc('Mock a post request for SDK tests') @@ -194,11 +174,11 @@ App::get('/v1/mock/tests/general/redirect') ->label('sdk.namespace', 'general') ->label('sdk.method', 'redirect') ->label('sdk.description', 'Mock a redirect request for SDK tests') - ->action( - function () use ($response) { - $response->redirect('/v1/mock/tests/general/redirected'); - } - ); + ->action(function ($response) { + /** @var Utopia\Response $response */ + + $response->redirect('/v1/mock/tests/general/redirected'); + }, ['response']); App::get('/v1/mock/tests/general/redirected') ->desc('Mock a post request for SDK tests') @@ -206,10 +186,8 @@ App::get('/v1/mock/tests/general/redirected') ->label('sdk.namespace', 'general') ->label('sdk.method', 'redirected') ->label('sdk.description', 'Mock a redirected request for SDK tests') - ->action( - function () { - } - ); + ->action(function () { + }); App::get('/v1/mock/tests/general/set-cookie') ->desc('Mock a cookie request for SDK tests') @@ -217,11 +195,11 @@ App::get('/v1/mock/tests/general/set-cookie') ->label('sdk.namespace', 'general') ->label('sdk.method', 'setCookie') ->label('sdk.description', 'Mock a set cookie request for SDK tests') - ->action( - function () use ($response) { - $response->addCookie('cookieName', 'cookieValue', \time() + 31536000, '/', 'localhost', true, true); - } - ); + ->action(function ($response) { + /** @var Utopia\Response $response */ + + $response->addCookie('cookieName', 'cookieValue', \time() + 31536000, '/', 'localhost', true, true); + }, ['response']); App::get('/v1/mock/tests/general/get-cookie') ->desc('Mock a cookie request for SDK tests') @@ -229,13 +207,13 @@ App::get('/v1/mock/tests/general/get-cookie') ->label('sdk.namespace', 'general') ->label('sdk.method', 'getCookie') ->label('sdk.description', 'Mock a get cookie request for SDK tests') - ->action( - function () use ($request) { - if ($request->getCookie('cookieName', '') !== 'cookieValue') { - throw new Exception('Missing cookie value', 400); - } + ->action(function ($request) { + /** @var Utopia\Request $request */ + + if ($request->getCookie('cookieName', '') !== 'cookieValue') { + throw new Exception('Missing cookie value', 400); } - ); + }, ['request']); App::get('/v1/mock/tests/general/empty') ->desc('Mock a post request for SDK tests') @@ -243,12 +221,12 @@ App::get('/v1/mock/tests/general/empty') ->label('sdk.namespace', 'general') ->label('sdk.method', 'empty') ->label('sdk.description', 'Mock a redirected request for SDK tests') - ->action( - function () use ($response) { - $response->noContent(); - exit(); - } - ); + ->action(function ($response) { + /** @var Utopia\Response $response */ + + $response->noContent(); + exit(); + }, ['response']); App::get('/v1/mock/tests/general/oauth2') ->desc('Mock an OAuth2 login route') @@ -258,11 +236,11 @@ App::get('/v1/mock/tests/general/oauth2') ->param('redirect_uri', '', function () { return new Host(['localhost']); }, 'OAuth2 Redirect URI.') // Important to deny an open redirect attack ->param('scope', '', function () { return new Text(100); }, 'OAuth2 scope list.') ->param('state', '', function () { return new Text(1024); }, 'OAuth2 state.') - ->action( - function ($clientId, $redirectURI, $scope, $state) use ($response) { - $response->redirect($redirectURI.'?'.\http_build_query(['code' => 'abcdef', 'state' => $state])); - } - ); + ->action(function ($clientId, $redirectURI, $scope, $state, $response) { + /** @var Utopia\Response $response */ + + $response->redirect($redirectURI.'?'.\http_build_query(['code' => 'abcdef', 'state' => $state])); + }, ['response']); App::get('/v1/mock/tests/general/oauth2/token') ->desc('Mock an OAuth2 login route') @@ -272,68 +250,72 @@ App::get('/v1/mock/tests/general/oauth2/token') ->param('redirect_uri', '', function () { return new Host(['localhost']); }, 'OAuth2 Redirect URI.') ->param('client_secret', '', function () { return new Text(100); }, 'OAuth2 scope list.') ->param('code', '', function () { return new Text(100); }, 'OAuth2 state.') - ->action( - function ($clientId, $redirectURI, $clientSecret, $code) use ($response) { - if ($clientId != '1') { - throw new Exception('Invalid client ID'); - } + ->action(function ($clientId, $redirectURI, $clientSecret, $code, $response) { + /** @var Utopia\Response $response */ - if ($clientSecret != '123456') { - throw new Exception('Invalid client secret'); - } - - if ($code != 'abcdef') { - throw new Exception('Invalid token'); - } - - $response->json(['access_token' => '123456']); + if ($clientId != '1') { + throw new Exception('Invalid client ID'); } - ); + + if ($clientSecret != '123456') { + throw new Exception('Invalid client secret'); + } + + if ($code != 'abcdef') { + throw new Exception('Invalid token'); + } + + $response->json(['access_token' => '123456']); + }, ['response']); App::get('/v1/mock/tests/general/oauth2/user') ->desc('Mock an OAuth2 user route') ->label('scope', 'public') ->label('docs', false) ->param('token', '', function () { return new Text(100); }, 'OAuth2 Access Token.') - ->action( - function ($token) use ($response) { - if ($token != '123456') { - throw new Exception('Invalid token'); - } + ->action(function ($token, $response) { + /** @var Utopia\Response $response */ - $response->json([ - 'id' => 1, - 'name' => 'User Name', - 'email' => 'user@localhost.test', - ]); + if ($token != '123456') { + throw new Exception('Invalid token'); } - ); + + $response->json([ + 'id' => 1, + 'name' => 'User Name', + 'email' => 'user@localhost.test', + ]); + }, ['response']); App::get('/v1/mock/tests/general/oauth2/success') ->label('scope', 'public') ->label('docs', false) - ->action( - function () use ($response) { - $response->json([ - 'result' => 'success', - ]); - } - ); + ->action(function ($response) { + /** @var Utopia\Response $response */ + + $response->json([ + 'result' => 'success', + ]); + }, ['response']); App::get('/v1/mock/tests/general/oauth2/failure') ->label('scope', 'public') ->label('docs', false) - ->action( - function () use ($response) { - $response - ->setStatusCode(Response::STATUS_CODE_BAD_REQUEST) - ->json([ - 'result' => 'failure', - ]); - } - ); + ->action(function ($response) { + /** @var Utopia\Response $response */ + + $response + ->setStatusCode(Response::STATUS_CODE_BAD_REQUEST) + ->json([ + 'result' => 'failure', + ]); + }, ['response']); + +App::shutdown(function($utopia, $response, $request) { + /** @var Utopia\App $utopia */ + /** @var Utopia\Request $request */ + /** @var Utopia\Response $response */ -App::shutdown(function($response, $request, $utopia) { $result = []; $route = $utopia->match($request); $path = APP_STORAGE_CACHE.'/tests.json'; @@ -352,4 +334,4 @@ App::shutdown(function($response, $request, $utopia) { } $response->json(['result' => $route->getMethod() . ':' . $route->getURL() . ':passed']); -}, ['response', 'request', 'utopia'], 'mock'); \ No newline at end of file +}, ['utopia', 'response', 'request'], 'mock'); \ No newline at end of file