Merge pull request #436 from appwrite/functions-performance
Functions performance
This commit is contained in:
commit
0abfa5e5fc
|
@ -161,6 +161,16 @@ To run tests manually, run phpunit from your command line:
|
|||
docker exec appwrite test
|
||||
```
|
||||
|
||||
## Code Maintenance
|
||||
|
||||
We use some automation tools to help us keep a healthy code base.
|
||||
|
||||
Improve PHP exeution time by using [fully-qualified function calls](https://veewee.github.io/blog/optimizing-php-performance-by-fq-function-calls/):
|
||||
|
||||
```bash
|
||||
php-cs-fixer fix src/ --rules=native_function_invocation --allow-risky=yes
|
||||
```
|
||||
|
||||
## Tutorials
|
||||
|
||||
From time to time, our team will add tutorials that will help contributors find their way in the Appwrite source code. Below is a list of currently available tutorials:
|
||||
|
|
46
app/app.php
46
app/app.php
|
@ -34,9 +34,9 @@ $deletes = new Event('v1-deletes', 'DeletesV1');
|
|||
* Get All verified client URLs for both console and current projects
|
||||
* + Filter for duplicated entries
|
||||
*/
|
||||
$clientsConsole = array_map(function ($node) {
|
||||
$clientsConsole = \array_map(function ($node) {
|
||||
return $node['hostname'];
|
||||
}, array_filter($console->getAttribute('platforms', []), function ($node) {
|
||||
}, \array_filter($console->getAttribute('platforms', []), function ($node) {
|
||||
if (isset($node['type']) && $node['type'] === 'web' && isset($node['hostname']) && !empty($node['hostname'])) {
|
||||
return true;
|
||||
}
|
||||
|
@ -44,9 +44,9 @@ $clientsConsole = array_map(function ($node) {
|
|||
return false;
|
||||
}));
|
||||
|
||||
$clients = array_unique(array_merge($clientsConsole, array_map(function ($node) {
|
||||
$clients = \array_unique(\array_merge($clientsConsole, \array_map(function ($node) {
|
||||
return $node['hostname'];
|
||||
}, array_filter($project->getAttribute('platforms', []), function ($node) {
|
||||
}, \array_filter($project->getAttribute('platforms', []), function ($node) {
|
||||
if (isset($node['type']) && $node['type'] === 'web' && isset($node['hostname']) && !empty($node['hostname'])) {
|
||||
return true;
|
||||
}
|
||||
|
@ -63,11 +63,11 @@ $utopia->init(function () use ($utopia, $request, $response, &$user, $project, $
|
|||
}
|
||||
|
||||
$referrer = $request->getServer('HTTP_REFERER', '');
|
||||
$origin = parse_url($request->getServer('HTTP_ORIGIN', $referrer), PHP_URL_HOST);
|
||||
$protocol = parse_url($request->getServer('HTTP_ORIGIN', $referrer), PHP_URL_SCHEME);
|
||||
$port = parse_url($request->getServer('HTTP_ORIGIN', $referrer), PHP_URL_PORT);
|
||||
$origin = \parse_url($request->getServer('HTTP_ORIGIN', $referrer), PHP_URL_HOST);
|
||||
$protocol = \parse_url($request->getServer('HTTP_ORIGIN', $referrer), PHP_URL_SCHEME);
|
||||
$port = \parse_url($request->getServer('HTTP_ORIGIN', $referrer), PHP_URL_PORT);
|
||||
|
||||
$refDomain = $protocol.'://'.((in_array($origin, $clients))
|
||||
$refDomain = $protocol.'://'.((\in_array($origin, $clients))
|
||||
? $origin : 'localhost') . (!empty($port) ? ':'.$port : '');
|
||||
|
||||
$selfDomain = new Domain(Config::getParam('hostname'));
|
||||
|
@ -93,7 +93,7 @@ $utopia->init(function () use ($utopia, $request, $response, &$user, $project, $
|
|||
|
||||
$response
|
||||
->addHeader('Server', 'Appwrite')
|
||||
->addHeader('X-XSS-Protection', '1; mode=block; report=/v1/xss?url='.urlencode($request->getServer('REQUEST_URI')))
|
||||
->addHeader('X-XSS-Protection', '1; mode=block; report=/v1/xss?url='.\urlencode($request->getServer('REQUEST_URI')))
|
||||
//->addHeader('X-Frame-Options', ($refDomain == 'http://localhost') ? 'SAMEORIGIN' : 'ALLOW-FROM ' . $refDomain)
|
||||
->addHeader('X-Content-Type-Options', 'nosniff')
|
||||
->addHeader('Access-Control-Allow-Methods', 'GET, POST, PUT, PATCH, DELETE')
|
||||
|
@ -109,10 +109,10 @@ $utopia->init(function () use ($utopia, $request, $response, &$user, $project, $
|
|||
* Skip this check for non-web platforms which are not requiredto send an origin header
|
||||
*/
|
||||
$origin = $request->getServer('HTTP_ORIGIN', $request->getServer('HTTP_REFERER', ''));
|
||||
$originValidator = new Origin(array_merge($project->getAttribute('platforms', []), $console->getAttribute('platforms', [])));
|
||||
$originValidator = new Origin(\array_merge($project->getAttribute('platforms', []), $console->getAttribute('platforms', [])));
|
||||
|
||||
if(!$originValidator->isValid($origin)
|
||||
&& in_array($request->getMethod(), [Request::METHOD_POST, Request::METHOD_PUT, Request::METHOD_PATCH, Request::METHOD_DELETE])
|
||||
&& \in_array($request->getMethod(), [Request::METHOD_POST, Request::METHOD_PUT, Request::METHOD_PATCH, Request::METHOD_DELETE])
|
||||
&& $route->getLabel('origin', false) !== '*'
|
||||
&& empty($request->getHeader('X-Appwrite-Key', ''))) {
|
||||
throw new Exception($originValidator->getDescription(), 403);
|
||||
|
@ -162,7 +162,7 @@ $utopia->init(function () use ($utopia, $request, $response, &$user, $project, $
|
|||
]);
|
||||
|
||||
$role = Auth::USER_ROLE_APP;
|
||||
$scopes = array_merge($roles[$role]['scopes'], $key->getAttribute('scopes', []));
|
||||
$scopes = \array_merge($roles[$role]['scopes'], $key->getAttribute('scopes', []));
|
||||
|
||||
Authorization::setDefaultStatus(false); // Cancel security segmentation for API keys.
|
||||
}
|
||||
|
@ -170,7 +170,7 @@ $utopia->init(function () use ($utopia, $request, $response, &$user, $project, $
|
|||
Authorization::setRole('user:'.$user->getId());
|
||||
Authorization::setRole('role:'.$role);
|
||||
|
||||
array_map(function ($node) {
|
||||
\array_map(function ($node) {
|
||||
if (isset($node['teamId']) && isset($node['roles'])) {
|
||||
Authorization::setRole('team:'.$node['teamId']);
|
||||
|
||||
|
@ -182,12 +182,12 @@ $utopia->init(function () use ($utopia, $request, $response, &$user, $project, $
|
|||
|
||||
// TDOO Check if user is god
|
||||
|
||||
if (!in_array($scope, $scopes)) {
|
||||
if (!\in_array($scope, $scopes)) {
|
||||
if (empty($project->getId()) || Database::SYSTEM_COLLECTION_PROJECTS !== $project->getCollection()) { // Check if permission is denied because project is missing
|
||||
throw new Exception('Project not found', 404);
|
||||
}
|
||||
|
||||
throw new Exception($user->getAttribute('email', 'User').' (role: '.strtolower($roles[$role]['label']).') missing scope ('.$scope.')', 401);
|
||||
throw new Exception($user->getAttribute('email', 'User').' (role: '.\strtolower($roles[$role]['label']).') missing scope ('.$scope.')', 401);
|
||||
}
|
||||
|
||||
if (Auth::USER_STATUS_BLOCKED == $user->getAttribute('status')) { // Account has not been activated
|
||||
|
@ -396,9 +396,9 @@ $utopia->get('/.well-known/acme-challenge')
|
|||
->label('docs', false)
|
||||
->action(
|
||||
function () use ($request, $response) {
|
||||
$base = realpath(APP_STORAGE_CERTIFICATES);
|
||||
$path = str_replace('/.well-known/acme-challenge/', '', $request->getParam('q'));
|
||||
$absolute = realpath($base.'/.well-known/acme-challenge/'.$path);
|
||||
$base = \realpath(APP_STORAGE_CERTIFICATES);
|
||||
$path = \str_replace('/.well-known/acme-challenge/', '', $request->getParam('q'));
|
||||
$absolute = \realpath($base.'/.well-known/acme-challenge/'.$path);
|
||||
|
||||
if(!$base) {
|
||||
throw new Exception('Storage error', 500);
|
||||
|
@ -408,15 +408,15 @@ $utopia->get('/.well-known/acme-challenge')
|
|||
throw new Exception('Unknown path', 404);
|
||||
}
|
||||
|
||||
if(!substr($absolute, 0, strlen($base)) === $base) {
|
||||
if(!\substr($absolute, 0, \strlen($base)) === $base) {
|
||||
throw new Exception('Invalid path', 401);
|
||||
}
|
||||
|
||||
if(!file_exists($absolute)) {
|
||||
if(!\file_exists($absolute)) {
|
||||
throw new Exception('Unknown path', 404);
|
||||
}
|
||||
|
||||
$content = @file_get_contents($absolute);
|
||||
$content = @\file_get_contents($absolute);
|
||||
|
||||
if(!$content) {
|
||||
throw new Exception('Failed to get contents', 500);
|
||||
|
@ -428,9 +428,9 @@ $utopia->get('/.well-known/acme-challenge')
|
|||
|
||||
$name = APP_NAME;
|
||||
|
||||
if (array_key_exists($service, $services)) { /** @noinspection PhpIncludeInspection */
|
||||
if (\array_key_exists($service, $services)) { /** @noinspection PhpIncludeInspection */
|
||||
include_once $services[$service]['controller'];
|
||||
$name = APP_NAME.' '.ucfirst($services[$service]['name']);
|
||||
$name = APP_NAME.' '.\ucfirst($services[$service]['name']);
|
||||
} else {
|
||||
/** @noinspection PhpIncludeInspection */
|
||||
include_once $services['/']['controller'];
|
||||
|
|
|
@ -41,7 +41,7 @@ $collections = [
|
|||
'$collection' => Database::SYSTEM_COLLECTION_PLATFORMS,
|
||||
'name' => 'Current Host',
|
||||
'type' => 'web',
|
||||
'hostname' => parse_url('https://'.$request->getServer('HTTP_HOST'), PHP_URL_HOST),
|
||||
'hostname' => \parse_url('https://'.$request->getServer('HTTP_HOST'), PHP_URL_HOST),
|
||||
],
|
||||
],
|
||||
'legalName' => '',
|
||||
|
@ -50,9 +50,9 @@ $collections = [
|
|||
'legalCity' => '',
|
||||
'legalAddress' => '',
|
||||
'legalTaxId' => '',
|
||||
'authWhitelistEmails' => (!empty($request->getServer('_APP_CONSOLE_WHITELIST_EMAILS', null))) ? explode(',', $request->getServer('_APP_CONSOLE_WHITELIST_EMAILS', null)) : [],
|
||||
'authWhitelistIPs' => (!empty($request->getServer('_APP_CONSOLE_WHITELIST_IPS', null))) ? explode(',', $request->getServer('_APP_CONSOLE_WHITELIST_IPS', null)) : [],
|
||||
'authWhitelistDomains' => (!empty($request->getServer('_APP_CONSOLE_WHITELIST_DOMAINS', null))) ? explode(',', $request->getServer('_APP_CONSOLE_WHITELIST_DOMAINS', null)) : [],
|
||||
'authWhitelistEmails' => (!empty($request->getServer('_APP_CONSOLE_WHITELIST_EMAILS', null))) ? \explode(',', $request->getServer('_APP_CONSOLE_WHITELIST_EMAILS', null)) : [],
|
||||
'authWhitelistIPs' => (!empty($request->getServer('_APP_CONSOLE_WHITELIST_IPS', null))) ? \explode(',', $request->getServer('_APP_CONSOLE_WHITELIST_IPS', null)) : [],
|
||||
'authWhitelistDomains' => (!empty($request->getServer('_APP_CONSOLE_WHITELIST_DOMAINS', null))) ? \explode(',', $request->getServer('_APP_CONSOLE_WHITELIST_DOMAINS', null)) : [],
|
||||
],
|
||||
Database::SYSTEM_COLLECTION_COLLECTIONS => [
|
||||
'$collection' => Database::SYSTEM_COLLECTION_COLLECTIONS,
|
||||
|
@ -1199,8 +1199,8 @@ foreach ($providers as $index => $provider) {
|
|||
|
||||
$collections[Database::SYSTEM_COLLECTION_PROJECTS]['rules'][] = [
|
||||
'$collection' => Database::SYSTEM_COLLECTION_RULES,
|
||||
'label' => 'OAuth2 '.ucfirst($index).' ID',
|
||||
'key' => 'usersOauth2'.ucfirst($index).'Appid',
|
||||
'label' => 'OAuth2 '.\ucfirst($index).' ID',
|
||||
'key' => 'usersOauth2'.\ucfirst($index).'Appid',
|
||||
'type' => 'text',
|
||||
'default' => '',
|
||||
'required' => false,
|
||||
|
@ -1209,8 +1209,8 @@ foreach ($providers as $index => $provider) {
|
|||
|
||||
$collections[Database::SYSTEM_COLLECTION_PROJECTS]['rules'][] = [
|
||||
'$collection' => Database::SYSTEM_COLLECTION_RULES,
|
||||
'label' => 'OAuth2 '.ucfirst($index).' Secret',
|
||||
'key' => 'usersOauth2'.ucfirst($index).'Secret',
|
||||
'label' => 'OAuth2 '.\ucfirst($index).' Secret',
|
||||
'key' => 'usersOauth2'.\ucfirst($index).'Secret',
|
||||
'type' => 'text',
|
||||
'default' => '',
|
||||
'required' => false,
|
||||
|
@ -1219,8 +1219,8 @@ foreach ($providers as $index => $provider) {
|
|||
|
||||
$collections[Database::SYSTEM_COLLECTION_USERS]['rules'][] = [
|
||||
'$collection' => Database::SYSTEM_COLLECTION_RULES,
|
||||
'label' => 'OAuth2 '.ucfirst($index).' ID',
|
||||
'key' => 'oauth2'.ucfirst($index),
|
||||
'label' => 'OAuth2 '.\ucfirst($index).' ID',
|
||||
'key' => 'oauth2'.\ucfirst($index),
|
||||
'type' => 'text',
|
||||
'default' => '',
|
||||
'required' => false,
|
||||
|
@ -1229,8 +1229,8 @@ foreach ($providers as $index => $provider) {
|
|||
|
||||
$collections[Database::SYSTEM_COLLECTION_USERS]['rules'][] = [
|
||||
'$collection' => Database::SYSTEM_COLLECTION_RULES,
|
||||
'label' => 'OAuth2 '.ucfirst($index).' Access Token',
|
||||
'key' => 'oauth2'.ucfirst($index).'AccessToken',
|
||||
'label' => 'OAuth2 '.\ucfirst($index).' Access Token',
|
||||
'key' => 'oauth2'.\ucfirst($index).'AccessToken',
|
||||
'type' => 'text',
|
||||
'default' => '',
|
||||
'required' => false,
|
||||
|
|
|
@ -30,7 +30,7 @@ $list = [
|
|||
'SE', // Sweden
|
||||
];
|
||||
|
||||
if (time() < strtotime('2020-01-31')) { // @see https://en.wikipedia.org/wiki/Brexit
|
||||
if (\time() < \strtotime('2020-01-31')) { // @see https://en.wikipedia.org/wiki/Brexit
|
||||
$list[] = 'GB'; // // United Kingdom
|
||||
}
|
||||
|
||||
|
|
|
@ -21,7 +21,7 @@ return [
|
|||
'beta' => false,
|
||||
'family' => APP_PLATFORM_CLIENT,
|
||||
'prism' => 'javascript',
|
||||
'source' => realpath(__DIR__ . '/../sdks/client-web'),
|
||||
'source' => \realpath(__DIR__ . '/../sdks/client-web'),
|
||||
'gitUrl' => 'git@github.com:appwrite/sdk-for-js.git',
|
||||
'gitRepoName' => 'sdk-for-js',
|
||||
'gitUserName' => 'appwrite',
|
||||
|
@ -35,7 +35,7 @@ return [
|
|||
'beta' => true,
|
||||
'family' => APP_PLATFORM_CLIENT,
|
||||
'prism' => 'dart',
|
||||
'source' => realpath(__DIR__ . '/../sdks/client-flutter'),
|
||||
'source' => \realpath(__DIR__ . '/../sdks/client-flutter'),
|
||||
'gitUrl' => 'git@github.com:appwrite/sdk-for-flutter.git',
|
||||
'gitRepoName' => 'sdk-for-flutter',
|
||||
'gitUserName' => 'appwrite',
|
||||
|
@ -110,7 +110,7 @@ return [
|
|||
'beta' => false,
|
||||
'family' => APP_PLATFORM_CONSOLE,
|
||||
'prism' => 'console',
|
||||
'source' => realpath(__DIR__ . '/../sdks/console-web'),
|
||||
'source' => \realpath(__DIR__ . '/../sdks/console-web'),
|
||||
'gitUrl' => null,
|
||||
'gitRepoName' => 'sdk-for-console',
|
||||
'gitUserName' => 'appwrite',
|
||||
|
@ -134,7 +134,7 @@ return [
|
|||
'beta' => false,
|
||||
'family' => APP_PLATFORM_SERVER,
|
||||
'prism' => 'javascript',
|
||||
'source' => realpath(__DIR__ . '/../sdks/server-nodejs'),
|
||||
'source' => \realpath(__DIR__ . '/../sdks/server-nodejs'),
|
||||
'gitUrl' => 'git@github.com:appwrite/sdk-for-node.git',
|
||||
'gitRepoName' => 'sdk-for-node',
|
||||
'gitUserName' => 'appwrite',
|
||||
|
@ -148,7 +148,7 @@ return [
|
|||
'beta' => true,
|
||||
'family' => APP_PLATFORM_SERVER,
|
||||
'prism' => 'typescript',
|
||||
'source' => realpath(__DIR__ . '/../sdks/server-deno'),
|
||||
'source' => \realpath(__DIR__ . '/../sdks/server-deno'),
|
||||
'gitUrl' => 'git@github.com:appwrite/sdk-for-deno.git',
|
||||
'gitRepoName' => 'sdk-for-deno',
|
||||
'gitUserName' => 'appwrite',
|
||||
|
@ -162,7 +162,7 @@ return [
|
|||
'beta' => false,
|
||||
'family' => APP_PLATFORM_SERVER,
|
||||
'prism' => 'php',
|
||||
'source' => realpath(__DIR__ . '/../sdks/server-php'),
|
||||
'source' => \realpath(__DIR__ . '/../sdks/server-php'),
|
||||
'gitUrl' => 'git@github.com:appwrite/sdk-for-php.git',
|
||||
'gitRepoName' => 'sdk-for-php',
|
||||
'gitUserName' => 'appwrite',
|
||||
|
@ -176,7 +176,7 @@ return [
|
|||
'beta' => true,
|
||||
'family' => APP_PLATFORM_SERVER,
|
||||
'prism' => 'python',
|
||||
'source' => realpath(__DIR__ . '/../sdks/server-python'),
|
||||
'source' => \realpath(__DIR__ . '/../sdks/server-python'),
|
||||
'gitUrl' => 'git@github.com:appwrite/sdk-for-python.git',
|
||||
'gitRepoName' => 'sdk-for-python',
|
||||
'gitUserName' => 'appwrite',
|
||||
|
@ -190,7 +190,7 @@ return [
|
|||
'beta' => true,
|
||||
'family' => APP_PLATFORM_SERVER,
|
||||
'prism' => 'ruby',
|
||||
'source' => realpath(__DIR__ . '/../sdks/server-ruby'),
|
||||
'source' => \realpath(__DIR__ . '/../sdks/server-ruby'),
|
||||
'gitUrl' => 'git@github.com:appwrite/sdk-for-ruby.git',
|
||||
'gitRepoName' => 'sdk-for-ruby',
|
||||
'gitUserName' => 'appwrite',
|
||||
|
@ -204,7 +204,7 @@ return [
|
|||
'beta' => true,
|
||||
'family' => APP_PLATFORM_SERVER,
|
||||
'prism' => 'go',
|
||||
'source' => realpath(__DIR__ . '/../sdks/server-go'),
|
||||
'source' => \realpath(__DIR__ . '/../sdks/server-go'),
|
||||
'gitUrl' => 'git@github.com:appwrite/sdk-for-go.git',
|
||||
'gitRepoName' => 'sdk-for-go',
|
||||
'gitUserName' => 'appwrite',
|
||||
|
@ -218,7 +218,7 @@ return [
|
|||
'beta' => true,
|
||||
'family' => APP_PLATFORM_SERVER,
|
||||
'prism' => 'java',
|
||||
'source' => realpath(__DIR__ . '/../sdks/server-java'),
|
||||
'source' => \realpath(__DIR__ . '/../sdks/server-java'),
|
||||
'gitUrl' => 'git@github.com:appwrite/sdk-for-java.git',
|
||||
'gitRepoName' => 'sdk-for-java',
|
||||
'gitUserName' => 'appwrite',
|
||||
|
@ -232,7 +232,7 @@ return [
|
|||
'beta' => true,
|
||||
'family' => APP_PLATFORM_SERVER,
|
||||
'prism' => 'java',
|
||||
'source' => realpath(__DIR__ . '/../sdks/server-dart'),
|
||||
'source' => \realpath(__DIR__ . '/../sdks/server-dart'),
|
||||
'gitUrl' => 'git@github.com:appwrite/sdk-for-dart.git',
|
||||
'gitRepoName' => 'sdk-for-dart',
|
||||
'gitUserName' => 'appwrite',
|
||||
|
|
|
@ -65,19 +65,19 @@ return [
|
|||
],
|
||||
ROLE_MEMBER => [
|
||||
'label' => 'Member',
|
||||
'scopes' => array_merge($logged, []),
|
||||
'scopes' => \array_merge($logged, []),
|
||||
],
|
||||
ROLE_ADMIN => [
|
||||
'label' => 'Admin',
|
||||
'scopes' => array_merge($admins, []),
|
||||
'scopes' => \array_merge($admins, []),
|
||||
],
|
||||
ROLE_DEVELOPER => [
|
||||
'label' => 'Developer',
|
||||
'scopes' => array_merge($admins, []),
|
||||
'scopes' => \array_merge($admins, []),
|
||||
],
|
||||
ROLE_OWNER => [
|
||||
'label' => 'Owner',
|
||||
'scopes' => array_merge($logged, $admins, []),
|
||||
'scopes' => \array_merge($logged, $admins, []),
|
||||
],
|
||||
ROLE_APP => [
|
||||
'label' => 'Application',
|
||||
|
|
|
@ -42,8 +42,8 @@ $utopia->init(function() use (&$oauth2Keys) {
|
|||
continue;
|
||||
}
|
||||
|
||||
$oauth2Keys[] = 'oauth2'.ucfirst($key);
|
||||
$oauth2Keys[] = 'oauth2'.ucfirst($key).'AccessToken';
|
||||
$oauth2Keys[] = 'oauth2'.\ucfirst($key);
|
||||
$oauth2Keys[] = 'oauth2'.\ucfirst($key).'AccessToken';
|
||||
}
|
||||
|
||||
});
|
||||
|
@ -67,15 +67,15 @@ $utopia->post('/v1/account')
|
|||
$whitlistIPs = $project->getAttribute('authWhitelistIPs');
|
||||
$whitlistDomains = $project->getAttribute('authWhitelistDomains');
|
||||
|
||||
if (!empty($whitlistEmails) && !in_array($email, $whitlistEmails)) {
|
||||
if (!empty($whitlistEmails) && !\in_array($email, $whitlistEmails)) {
|
||||
throw new Exception('Console registration is restricted to specific emails. Contact your administrator for more information.', 401);
|
||||
}
|
||||
|
||||
if (!empty($whitlistIPs) && !in_array($request->getIP(), $whitlistIPs)) {
|
||||
if (!empty($whitlistIPs) && !\in_array($request->getIP(), $whitlistIPs)) {
|
||||
throw new Exception('Console registration is restricted to specific IPs. Contact your administrator for more information.', 401);
|
||||
}
|
||||
|
||||
if (!empty($whitlistDomains) && !in_array(substr(strrchr($email, '@'), 1), $whitlistDomains)) {
|
||||
if (!empty($whitlistDomains) && !\in_array(\substr(\strrchr($email, '@'), 1), $whitlistDomains)) {
|
||||
throw new Exception('Console registration is restricted to specific domains. Contact your administrator for more information.', 401);
|
||||
}
|
||||
}
|
||||
|
@ -106,8 +106,8 @@ $utopia->post('/v1/account')
|
|||
'emailVerification' => false,
|
||||
'status' => Auth::USER_STATUS_UNACTIVATED,
|
||||
'password' => Auth::passwordHash($password),
|
||||
'password-update' => time(),
|
||||
'registration' => time(),
|
||||
'password-update' => \time(),
|
||||
'registration' => \time(),
|
||||
'reset' => false,
|
||||
'name' => $name,
|
||||
], ['email' => $email]);
|
||||
|
@ -136,7 +136,7 @@ $utopia->post('/v1/account')
|
|||
|
||||
$response
|
||||
->setStatusCode(Response::STATUS_CODE_CREATED)
|
||||
->json(array_merge($user->getArrayCopy(array_merge(
|
||||
->json(\array_merge($user->getArrayCopy(\array_merge(
|
||||
[
|
||||
'$id',
|
||||
'email',
|
||||
|
@ -182,7 +182,7 @@ $utopia->post('/v1/account/sessions')
|
|||
throw new Exception('Invalid credentials', 401); // Wrong password or username
|
||||
}
|
||||
|
||||
$expiry = time() + Auth::TOKEN_EXPIRATION_LOGIN_LONG;
|
||||
$expiry = \time() + Auth::TOKEN_EXPIRATION_LOGIN_LONG;
|
||||
$secret = Auth::tokenGenerator();
|
||||
$session = new Document([
|
||||
'$collection' => Database::SYSTEM_COLLECTION_TOKENS,
|
||||
|
@ -225,7 +225,7 @@ $utopia->post('/v1/account/sessions')
|
|||
|
||||
if(!Config::getParam('domainVerification')) {
|
||||
$response
|
||||
->addHeader('X-Fallback-Cookies', json_encode([Auth::$cookieName => Auth::encodeSession($profile->getId(), $secret)]))
|
||||
->addHeader('X-Fallback-Cookies', \json_encode([Auth::$cookieName => Auth::encodeSession($profile->getId(), $secret)]))
|
||||
;
|
||||
}
|
||||
|
||||
|
@ -251,7 +251,7 @@ $utopia->get('/v1/account/sessions/oauth2/:provider')
|
|||
->label('sdk.methodType', 'webAuth')
|
||||
->label('abuse-limit', 50)
|
||||
->label('abuse-key', 'ip:{ip}')
|
||||
->param('provider', '', function () { return new WhiteList(array_keys(Config::getParam('providers'))); }, 'OAuth2 Provider. Currently, supported providers are: ' . implode(', ', array_keys(array_filter(Config::getParam('providers'), function($node) {return (!$node['mock']);}))).'.')
|
||||
->param('provider', '', function () { return new WhiteList(\array_keys(Config::getParam('providers'))); }, 'OAuth2 Provider. Currently, supported providers are: ' . \implode(', ', \array_keys(\array_filter(Config::getParam('providers'), function($node) {return (!$node['mock']);}))).'.')
|
||||
->param('success', $oauthDefaultSuccess, function () use ($clients) { return new Host($clients); }, 'URL to redirect back to your app after a successful login attempt. Only URLs from hostnames in your project platform list are allowed. This requirement helps to prevent an [open redirect](https://cheatsheetseries.owasp.org/cheatsheets/Unvalidated_Redirects_and_Forwards_Cheat_Sheet.html) attack against your project API.', true)
|
||||
->param('failure', $oauthDefaultFailure, function () use ($clients) { return new Host($clients); }, 'URL to redirect back to your app after a failed login attempt. Only URLs from hostnames in your project platform list are allowed. This requirement helps to prevent an [open redirect](https://cheatsheetseries.owasp.org/cheatsheets/Unvalidated_Redirects_and_Forwards_Cheat_Sheet.html) attack against your project API.', true)
|
||||
->param('scopes', [], function () { return new ArrayList(new Text(128)); }, 'A list of custom OAuth2 scopes. Check each provider internal docs for a list of supported scopes.', true)
|
||||
|
@ -259,23 +259,23 @@ $utopia->get('/v1/account/sessions/oauth2/:provider')
|
|||
function ($provider, $success, $failure, $scopes) use ($response, $request, $project) {
|
||||
$protocol = Config::getParam('protocol');
|
||||
$callback = $protocol.'://'.$request->getServer('HTTP_HOST').'/v1/account/sessions/oauth2/callback/'.$provider.'/'.$project->getId();
|
||||
$appId = $project->getAttribute('usersOauth2'.ucfirst($provider).'Appid', '');
|
||||
$appSecret = $project->getAttribute('usersOauth2'.ucfirst($provider).'Secret', '{}');
|
||||
$appId = $project->getAttribute('usersOauth2'.\ucfirst($provider).'Appid', '');
|
||||
$appSecret = $project->getAttribute('usersOauth2'.\ucfirst($provider).'Secret', '{}');
|
||||
|
||||
$appSecret = json_decode($appSecret, true);
|
||||
$appSecret = \json_decode($appSecret, true);
|
||||
|
||||
if (!empty($appSecret) && isset($appSecret['version'])) {
|
||||
$key = $request->getServer('_APP_OPENSSL_KEY_V'.$appSecret['version']);
|
||||
$appSecret = OpenSSL::decrypt($appSecret['data'], $appSecret['method'], $key, 0, hex2bin($appSecret['iv']), hex2bin($appSecret['tag']));
|
||||
$appSecret = OpenSSL::decrypt($appSecret['data'], $appSecret['method'], $key, 0, \hex2bin($appSecret['iv']), \hex2bin($appSecret['tag']));
|
||||
}
|
||||
|
||||
if (empty($appId) || empty($appSecret)) {
|
||||
throw new Exception('This provider is disabled. Please configure the provider app ID and app secret key from your '.APP_NAME.' console to continue.', 412);
|
||||
}
|
||||
|
||||
$classname = 'Appwrite\\Auth\\OAuth2\\'.ucfirst($provider);
|
||||
$classname = 'Appwrite\\Auth\\OAuth2\\'.\ucfirst($provider);
|
||||
|
||||
if (!class_exists($classname)) {
|
||||
if (!\class_exists($classname)) {
|
||||
throw new Exception('Provider is not supported', 501);
|
||||
}
|
||||
|
||||
|
@ -294,7 +294,7 @@ $utopia->get('/v1/account/sessions/oauth2/callback/:provider/:projectId')
|
|||
->label('scope', 'public')
|
||||
->label('docs', false)
|
||||
->param('projectId', '', function () { return new Text(1024); }, 'Project unique ID.')
|
||||
->param('provider', '', function () { return new WhiteList(array_keys(Config::getParam('providers'))); }, 'OAuth2 provider.')
|
||||
->param('provider', '', function () { return new WhiteList(\array_keys(Config::getParam('providers'))); }, 'OAuth2 provider.')
|
||||
->param('code', '', function () { return new Text(1024); }, 'OAuth2 code.')
|
||||
->param('state', '', function () { return new Text(2048); }, 'Login state params.', true)
|
||||
->action(
|
||||
|
@ -306,7 +306,7 @@ $utopia->get('/v1/account/sessions/oauth2/callback/:provider/:projectId')
|
|||
->addHeader('Cache-Control', 'no-store, no-cache, must-revalidate, max-age=0')
|
||||
->addHeader('Pragma', 'no-cache')
|
||||
->redirect($protocol.'://'.$domain.'/v1/account/sessions/oauth2/'.$provider.'/redirect?'
|
||||
.http_build_query(['project' => $projectId, 'code' => $code, 'state' => $state]));
|
||||
.\http_build_query(['project' => $projectId, 'code' => $code, 'state' => $state]));
|
||||
}
|
||||
);
|
||||
|
||||
|
@ -317,7 +317,7 @@ $utopia->post('/v1/account/sessions/oauth2/callback/:provider/:projectId')
|
|||
->label('origin', '*')
|
||||
->label('docs', false)
|
||||
->param('projectId', '', function () { return new Text(1024); }, 'Project unique ID.')
|
||||
->param('provider', '', function () { return new WhiteList(array_keys(Config::getParam('providers'))); }, 'OAuth2 provider.')
|
||||
->param('provider', '', function () { return new WhiteList(\array_keys(Config::getParam('providers'))); }, 'OAuth2 provider.')
|
||||
->param('code', '', function () { return new Text(1024); }, 'OAuth2 code.')
|
||||
->param('state', '', function () { return new Text(2048); }, 'Login state params.', true)
|
||||
->action(
|
||||
|
@ -329,7 +329,7 @@ $utopia->post('/v1/account/sessions/oauth2/callback/:provider/:projectId')
|
|||
->addHeader('Cache-Control', 'no-store, no-cache, must-revalidate, max-age=0')
|
||||
->addHeader('Pragma', 'no-cache')
|
||||
->redirect($protocol.'://'.$domain.'/v1/account/sessions/oauth2/'.$provider.'/redirect?'
|
||||
.http_build_query(['project' => $projectId, 'code' => $code, 'state' => $state]));
|
||||
.\http_build_query(['project' => $projectId, 'code' => $code, 'state' => $state]));
|
||||
}
|
||||
);
|
||||
|
||||
|
@ -341,7 +341,7 @@ $utopia->get('/v1/account/sessions/oauth2/:provider/redirect')
|
|||
->label('abuse-limit', 50)
|
||||
->label('abuse-key', 'ip:{ip}')
|
||||
->label('docs', false)
|
||||
->param('provider', '', function () { return new WhiteList(array_keys(Config::getParam('providers'))); }, 'OAuth2 provider.')
|
||||
->param('provider', '', function () { return new WhiteList(\array_keys(Config::getParam('providers'))); }, 'OAuth2 provider.')
|
||||
->param('code', '', function () { return new Text(1024); }, 'OAuth2 code.')
|
||||
->param('state', '', function () { return new Text(2048); }, 'OAuth2 state params.', true)
|
||||
->action(
|
||||
|
@ -351,19 +351,19 @@ $utopia->get('/v1/account/sessions/oauth2/:provider/redirect')
|
|||
$defaultState = ['success' => $project->getAttribute('url', ''), 'failure' => ''];
|
||||
$validateURL = new URL();
|
||||
|
||||
$appId = $project->getAttribute('usersOauth2'.ucfirst($provider).'Appid', '');
|
||||
$appSecret = $project->getAttribute('usersOauth2'.ucfirst($provider).'Secret', '{}');
|
||||
$appId = $project->getAttribute('usersOauth2'.\ucfirst($provider).'Appid', '');
|
||||
$appSecret = $project->getAttribute('usersOauth2'.\ucfirst($provider).'Secret', '{}');
|
||||
|
||||
$appSecret = json_decode($appSecret, true);
|
||||
$appSecret = \json_decode($appSecret, true);
|
||||
|
||||
if (!empty($appSecret) && isset($appSecret['version'])) {
|
||||
$key = $request->getServer('_APP_OPENSSL_KEY_V'.$appSecret['version']);
|
||||
$appSecret = OpenSSL::decrypt($appSecret['data'], $appSecret['method'], $key, 0, hex2bin($appSecret['iv']), hex2bin($appSecret['tag']));
|
||||
$appSecret = OpenSSL::decrypt($appSecret['data'], $appSecret['method'], $key, 0, \hex2bin($appSecret['iv']), \hex2bin($appSecret['tag']));
|
||||
}
|
||||
|
||||
$classname = 'Appwrite\\Auth\\OAuth2\\'.ucfirst($provider);
|
||||
$classname = 'Appwrite\\Auth\\OAuth2\\'.\ucfirst($provider);
|
||||
|
||||
if (!class_exists($classname)) {
|
||||
if (!\class_exists($classname)) {
|
||||
throw new Exception('Provider is not supported', 501);
|
||||
}
|
||||
|
||||
|
@ -371,7 +371,7 @@ $utopia->get('/v1/account/sessions/oauth2/:provider/redirect')
|
|||
|
||||
if (!empty($state)) {
|
||||
try {
|
||||
$state = array_merge($defaultState, $oauth2->parseState($state));
|
||||
$state = \array_merge($defaultState, $oauth2->parseState($state));
|
||||
} catch (\Exception $exception) {
|
||||
throw new Exception('Failed to parse login state params as passed from OAuth2 provider');
|
||||
}
|
||||
|
@ -419,7 +419,7 @@ $utopia->get('/v1/account/sessions/oauth2/:provider/redirect')
|
|||
'first' => true,
|
||||
'filters' => [
|
||||
'$collection='.Database::SYSTEM_COLLECTION_USERS,
|
||||
'oauth2'.ucfirst($provider).'='.$oauth2ID,
|
||||
'oauth2'.\ucfirst($provider).'='.$oauth2ID,
|
||||
],
|
||||
]) : $user;
|
||||
|
||||
|
@ -447,8 +447,8 @@ $utopia->get('/v1/account/sessions/oauth2/:provider/redirect')
|
|||
'emailVerification' => true,
|
||||
'status' => Auth::USER_STATUS_ACTIVATED, // Email should already be authenticated by OAuth2 provider
|
||||
'password' => Auth::passwordHash(Auth::passwordGenerator()),
|
||||
'password-update' => time(),
|
||||
'registration' => time(),
|
||||
'password-update' => \time(),
|
||||
'registration' => \time(),
|
||||
'reset' => false,
|
||||
'name' => $name,
|
||||
], ['email' => $email]);
|
||||
|
@ -467,7 +467,7 @@ $utopia->get('/v1/account/sessions/oauth2/:provider/redirect')
|
|||
// Create session token, verify user account and update OAuth2 ID and Access Token
|
||||
|
||||
$secret = Auth::tokenGenerator();
|
||||
$expiry = time() + Auth::TOKEN_EXPIRATION_LOGIN_LONG;
|
||||
$expiry = \time() + Auth::TOKEN_EXPIRATION_LOGIN_LONG;
|
||||
$session = new Document([
|
||||
'$collection' => Database::SYSTEM_COLLECTION_TOKENS,
|
||||
'$permissions' => ['read' => ['user:'.$user['$id']], 'write' => ['user:'.$user['$id']]],
|
||||
|
@ -479,8 +479,8 @@ $utopia->get('/v1/account/sessions/oauth2/:provider/redirect')
|
|||
]);
|
||||
|
||||
$user
|
||||
->setAttribute('oauth2'.ucfirst($provider), $oauth2ID)
|
||||
->setAttribute('oauth2'.ucfirst($provider).'AccessToken', $accessToken)
|
||||
->setAttribute('oauth2'.\ucfirst($provider), $oauth2ID)
|
||||
->setAttribute('oauth2'.\ucfirst($provider).'AccessToken', $accessToken)
|
||||
->setAttribute('status', Auth::USER_STATUS_ACTIVATED)
|
||||
->setAttribute('tokens', $session, Document::SET_TYPE_APPEND)
|
||||
;
|
||||
|
@ -502,7 +502,7 @@ $utopia->get('/v1/account/sessions/oauth2/:provider/redirect')
|
|||
|
||||
if(!Config::getParam('domainVerification')) {
|
||||
$response
|
||||
->addHeader('X-Fallback-Cookies', json_encode([Auth::$cookieName => Auth::encodeSession($user->getId(), $secret)]))
|
||||
->addHeader('X-Fallback-Cookies', \json_encode([Auth::$cookieName => Auth::encodeSession($user->getId(), $secret)]))
|
||||
;
|
||||
}
|
||||
|
||||
|
@ -537,7 +537,7 @@ $utopia->get('/v1/account')
|
|||
->label('sdk.response', ['200' => 'user'])
|
||||
->action(
|
||||
function () use ($response, &$user, $oauth2Keys) {
|
||||
$response->json(array_merge($user->getArrayCopy(array_merge(
|
||||
$response->json(\array_merge($user->getArrayCopy(\array_merge(
|
||||
[
|
||||
'$id',
|
||||
'email',
|
||||
|
@ -562,7 +562,7 @@ $utopia->get('/v1/account/prefs')
|
|||
$prefs = $user->getAttribute('prefs', '{}');
|
||||
|
||||
try {
|
||||
$prefs = json_decode($prefs, true);
|
||||
$prefs = \json_decode($prefs, true);
|
||||
$prefs = ($prefs) ? $prefs : [];
|
||||
} catch (\Exception $error) {
|
||||
throw new Exception('Failed to parse prefs', 500);
|
||||
|
@ -616,7 +616,7 @@ $utopia->get('/v1/account/sessions')
|
|||
|
||||
try {
|
||||
$record = $reader->country($token->getAttribute('ip', ''));
|
||||
$sessions[$index]['geo']['isoCode'] = strtolower($record->country->isoCode);
|
||||
$sessions[$index]['geo']['isoCode'] = \strtolower($record->country->isoCode);
|
||||
$sessions[$index]['geo']['country'] = (isset($countries[$record->country->isoCode])) ? $countries[$record->country->isoCode] : Locale::getText('locale.country.unknown');
|
||||
} catch (\Exception $e) {
|
||||
$sessions[$index]['geo']['isoCode'] = '--';
|
||||
|
@ -678,7 +678,7 @@ $utopia->get('/v1/account/logs')
|
|||
$output[$i] = [
|
||||
'event' => $log['event'],
|
||||
'ip' => $log['ip'],
|
||||
'time' => strtotime($log['time']),
|
||||
'time' => \strtotime($log['time']),
|
||||
'OS' => $dd->getOs(),
|
||||
'client' => $dd->getClient(),
|
||||
'device' => $dd->getDevice(),
|
||||
|
@ -689,7 +689,7 @@ $utopia->get('/v1/account/logs')
|
|||
|
||||
try {
|
||||
$record = $reader->country($log['ip']);
|
||||
$output[$i]['geo']['isoCode'] = strtolower($record->country->isoCode);
|
||||
$output[$i]['geo']['isoCode'] = \strtolower($record->country->isoCode);
|
||||
$output[$i]['geo']['country'] = $record->country->name;
|
||||
$output[$i]['geo']['country'] = (isset($countries[$record->country->isoCode])) ? $countries[$record->country->isoCode] : Locale::getText('locale.country.unknown');
|
||||
} catch (\Exception $e) {
|
||||
|
@ -713,7 +713,7 @@ $utopia->patch('/v1/account/name')
|
|||
->param('name', '', function () { return new Text(100); }, 'User name.')
|
||||
->action(
|
||||
function ($name) use ($response, $user, $projectDB, $audit, $oauth2Keys) {
|
||||
$user = $projectDB->updateDocument(array_merge($user->getArrayCopy(), [
|
||||
$user = $projectDB->updateDocument(\array_merge($user->getArrayCopy(), [
|
||||
'name' => $name,
|
||||
]));
|
||||
|
||||
|
@ -727,7 +727,7 @@ $utopia->patch('/v1/account/name')
|
|||
->setParam('resource', 'users/'.$user->getId())
|
||||
;
|
||||
|
||||
$response->json(array_merge($user->getArrayCopy(array_merge(
|
||||
$response->json(\array_merge($user->getArrayCopy(\array_merge(
|
||||
[
|
||||
'$id',
|
||||
'email',
|
||||
|
@ -755,7 +755,7 @@ $utopia->patch('/v1/account/password')
|
|||
throw new Exception('Invalid credentials', 401);
|
||||
}
|
||||
|
||||
$user = $projectDB->updateDocument(array_merge($user->getArrayCopy(), [
|
||||
$user = $projectDB->updateDocument(\array_merge($user->getArrayCopy(), [
|
||||
'password' => Auth::passwordHash($password),
|
||||
]));
|
||||
|
||||
|
@ -769,7 +769,7 @@ $utopia->patch('/v1/account/password')
|
|||
->setParam('resource', 'users/'.$user->getId())
|
||||
;
|
||||
|
||||
$response->json(array_merge($user->getArrayCopy(array_merge(
|
||||
$response->json(\array_merge($user->getArrayCopy(\array_merge(
|
||||
[
|
||||
'$id',
|
||||
'email',
|
||||
|
@ -812,7 +812,7 @@ $utopia->patch('/v1/account/email')
|
|||
|
||||
// TODO after this user needs to confirm mail again
|
||||
|
||||
$user = $projectDB->updateDocument(array_merge($user->getArrayCopy(), [
|
||||
$user = $projectDB->updateDocument(\array_merge($user->getArrayCopy(), [
|
||||
'email' => $email,
|
||||
'emailVerification' => false,
|
||||
]));
|
||||
|
@ -827,7 +827,7 @@ $utopia->patch('/v1/account/email')
|
|||
->setParam('resource', 'users/'.$user->getId())
|
||||
;
|
||||
|
||||
$response->json(array_merge($user->getArrayCopy(array_merge(
|
||||
$response->json(\array_merge($user->getArrayCopy(\array_merge(
|
||||
[
|
||||
'$id',
|
||||
'email',
|
||||
|
@ -850,11 +850,11 @@ $utopia->patch('/v1/account/prefs')
|
|||
->label('sdk.description', '/docs/references/account/update-prefs.md')
|
||||
->action(
|
||||
function ($prefs) use ($response, $user, $projectDB, $audit) {
|
||||
$old = json_decode($user->getAttribute('prefs', '{}'), true);
|
||||
$old = \json_decode($user->getAttribute('prefs', '{}'), true);
|
||||
$old = ($old) ? $old : [];
|
||||
|
||||
$user = $projectDB->updateDocument(array_merge($user->getArrayCopy(), [
|
||||
'prefs' => json_encode(array_merge($old, $prefs)),
|
||||
$user = $projectDB->updateDocument(\array_merge($user->getArrayCopy(), [
|
||||
'prefs' => \json_encode(\array_merge($old, $prefs)),
|
||||
]));
|
||||
|
||||
if (false === $user) {
|
||||
|
@ -869,7 +869,7 @@ $utopia->patch('/v1/account/prefs')
|
|||
$prefs = $user->getAttribute('prefs', '{}');
|
||||
|
||||
try {
|
||||
$prefs = json_decode($prefs, true);
|
||||
$prefs = \json_decode($prefs, true);
|
||||
$prefs = ($prefs) ? $prefs : [];
|
||||
} catch (\Exception $error) {
|
||||
throw new Exception('Failed to parse prefs', 500);
|
||||
|
@ -890,7 +890,7 @@ $utopia->delete('/v1/account')
|
|||
->action(
|
||||
function () use ($response, $user, $projectDB, $audit, $webhook) {
|
||||
$protocol = Config::getParam('protocol');
|
||||
$user = $projectDB->updateDocument(array_merge($user->getArrayCopy(), [
|
||||
$user = $projectDB->updateDocument(\array_merge($user->getArrayCopy(), [
|
||||
'status' => Auth::USER_STATUS_BLOCKED,
|
||||
]));
|
||||
|
||||
|
@ -922,13 +922,13 @@ $utopia->delete('/v1/account')
|
|||
|
||||
if(!Config::getParam('domainVerification')) {
|
||||
$response
|
||||
->addHeader('X-Fallback-Cookies', json_encode([]))
|
||||
->addHeader('X-Fallback-Cookies', \json_encode([]))
|
||||
;
|
||||
}
|
||||
|
||||
$response
|
||||
->addCookie(Auth::$cookieName.'_legacy', '', time() - 3600, '/', COOKIE_DOMAIN, ('https' == $protocol), true, null)
|
||||
->addCookie(Auth::$cookieName, '', time() - 3600, '/', COOKIE_DOMAIN, ('https' == $protocol), true, COOKIE_SAMESITE)
|
||||
->addCookie(Auth::$cookieName.'_legacy', '', \time() - 3600, '/', COOKIE_DOMAIN, ('https' == $protocol), true, null)
|
||||
->addCookie(Auth::$cookieName, '', \time() - 3600, '/', COOKIE_DOMAIN, ('https' == $protocol), true, COOKIE_SAMESITE)
|
||||
->noContent()
|
||||
;
|
||||
}
|
||||
|
@ -974,14 +974,14 @@ $utopia->delete('/v1/account/sessions/:sessionId')
|
|||
|
||||
if(!Config::getParam('domainVerification')) {
|
||||
$response
|
||||
->addHeader('X-Fallback-Cookies', json_encode([]))
|
||||
->addHeader('X-Fallback-Cookies', \json_encode([]))
|
||||
;
|
||||
}
|
||||
|
||||
if ($token->getAttribute('secret') == Auth::hash(Auth::$secret)) { // If current session delete the cookies too
|
||||
$response
|
||||
->addCookie(Auth::$cookieName.'_legacy', '', time() - 3600, '/', COOKIE_DOMAIN, ('https' == $protocol), true, null)
|
||||
->addCookie(Auth::$cookieName, '', time() - 3600, '/', COOKIE_DOMAIN, ('https' == $protocol), true, COOKIE_SAMESITE)
|
||||
->addCookie(Auth::$cookieName.'_legacy', '', \time() - 3600, '/', COOKIE_DOMAIN, ('https' == $protocol), true, null)
|
||||
->addCookie(Auth::$cookieName, '', \time() - 3600, '/', COOKIE_DOMAIN, ('https' == $protocol), true, COOKIE_SAMESITE)
|
||||
;
|
||||
}
|
||||
|
||||
|
@ -1027,14 +1027,14 @@ $utopia->delete('/v1/account/sessions')
|
|||
|
||||
if(!Config::getParam('domainVerification')) {
|
||||
$response
|
||||
->addHeader('X-Fallback-Cookies', json_encode([]))
|
||||
->addHeader('X-Fallback-Cookies', \json_encode([]))
|
||||
;
|
||||
}
|
||||
|
||||
if ($token->getAttribute('secret') == Auth::hash(Auth::$secret)) { // If current session delete the cookies too
|
||||
$response
|
||||
->addCookie(Auth::$cookieName.'_legacy', '', time() - 3600, '/', COOKIE_DOMAIN, ('https' == $protocol), true, null)
|
||||
->addCookie(Auth::$cookieName, '', time() - 3600, '/', COOKIE_DOMAIN, ('https' == $protocol), true, COOKIE_SAMESITE)
|
||||
->addCookie(Auth::$cookieName.'_legacy', '', \time() - 3600, '/', COOKIE_DOMAIN, ('https' == $protocol), true, null)
|
||||
->addCookie(Auth::$cookieName, '', \time() - 3600, '/', COOKIE_DOMAIN, ('https' == $protocol), true, COOKIE_SAMESITE)
|
||||
;
|
||||
}
|
||||
}
|
||||
|
@ -1075,7 +1075,7 @@ $utopia->post('/v1/account/recovery')
|
|||
'$permissions' => ['read' => ['user:'.$profile->getId()], 'write' => ['user:'.$profile->getId()]],
|
||||
'type' => Auth::TOKEN_TYPE_RECOVERY,
|
||||
'secret' => Auth::hash($secret), // On way hash encryption to protect DB leak
|
||||
'expire' => time() + Auth::TOKEN_EXPIRATION_RECOVERY,
|
||||
'expire' => \time() + Auth::TOKEN_EXPIRATION_RECOVERY,
|
||||
'userAgent' => $request->getServer('HTTP_USER_AGENT', 'UNKNOWN'),
|
||||
'ip' => $request->getIP(),
|
||||
]);
|
||||
|
@ -1182,9 +1182,9 @@ $utopia->put('/v1/account/recovery')
|
|||
|
||||
Authorization::setRole('user:'.$profile->getId());
|
||||
|
||||
$profile = $projectDB->updateDocument(array_merge($profile->getArrayCopy(), [
|
||||
$profile = $projectDB->updateDocument(\array_merge($profile->getArrayCopy(), [
|
||||
'password' => Auth::passwordHash($password),
|
||||
'password-update' => time(),
|
||||
'password-update' => \time(),
|
||||
'emailVerification' => true,
|
||||
]));
|
||||
|
||||
|
@ -1231,7 +1231,7 @@ $utopia->post('/v1/account/verification')
|
|||
'$permissions' => ['read' => ['user:'.$user->getId()], 'write' => ['user:'.$user->getId()]],
|
||||
'type' => Auth::TOKEN_TYPE_VERIFICATION,
|
||||
'secret' => Auth::hash($verificationSecret), // On way hash encryption to protect DB leak
|
||||
'expire' => time() + Auth::TOKEN_EXPIRATION_CONFIRM,
|
||||
'expire' => \time() + Auth::TOKEN_EXPIRATION_CONFIRM,
|
||||
'userAgent' => $request->getServer('HTTP_USER_AGENT', 'UNKNOWN'),
|
||||
'ip' => $request->getIP(),
|
||||
]);
|
||||
|
@ -1332,7 +1332,7 @@ $utopia->put('/v1/account/verification')
|
|||
|
||||
Authorization::setRole('user:'.$profile->getId());
|
||||
|
||||
$profile = $projectDB->updateDocument(array_merge($profile->getArrayCopy(), [
|
||||
$profile = $projectDB->updateDocument(\array_merge($profile->getArrayCopy(), [
|
||||
'emailVerification' => true,
|
||||
]));
|
||||
|
||||
|
|
|
@ -27,28 +27,28 @@ $types = [
|
|||
];
|
||||
|
||||
$avatarCallback = function ($type, $code, $width, $height, $quality) use ($types, $response, $request) {
|
||||
$code = strtolower($code);
|
||||
$type = strtolower($type);
|
||||
$code = \strtolower($code);
|
||||
$type = \strtolower($type);
|
||||
|
||||
if (!array_key_exists($type, $types)) {
|
||||
if (!\array_key_exists($type, $types)) {
|
||||
throw new Exception('Avatar set not found', 404);
|
||||
}
|
||||
|
||||
if (!array_key_exists($code, $types[$type])) {
|
||||
if (!\array_key_exists($code, $types[$type])) {
|
||||
throw new Exception('Avatar not found', 404);
|
||||
}
|
||||
|
||||
if (!extension_loaded('imagick')) {
|
||||
if (!\extension_loaded('imagick')) {
|
||||
throw new Exception('Imagick extension is missing', 500);
|
||||
}
|
||||
|
||||
$output = 'png';
|
||||
$date = date('D, d M Y H:i:s', time() + (60 * 60 * 24 * 45)).' GMT'; // 45 days cache
|
||||
$key = md5('/v1/avatars/:type/:code-'.$code.$width.$height.$quality.$output);
|
||||
$date = \date('D, d M Y H:i:s', \time() + (60 * 60 * 24 * 45)).' GMT'; // 45 days cache
|
||||
$key = \md5('/v1/avatars/:type/:code-'.$code.$width.$height.$quality.$output);
|
||||
$path = $types[$type][$code];
|
||||
$type = 'png';
|
||||
|
||||
if (!is_readable($path)) {
|
||||
if (!\is_readable($path)) {
|
||||
throw new Exception('File not readable in '.$path, 500);
|
||||
}
|
||||
|
||||
|
@ -66,7 +66,7 @@ $avatarCallback = function ($type, $code, $width, $height, $quality) use ($types
|
|||
;
|
||||
}
|
||||
|
||||
$resize = new Resize(file_get_contents($path));
|
||||
$resize = new Resize(\file_get_contents($path));
|
||||
|
||||
$resize->crop((int) $width, (int) $height);
|
||||
|
||||
|
@ -92,7 +92,7 @@ $avatarCallback = function ($type, $code, $width, $height, $quality) use ($types
|
|||
|
||||
$utopia->get('/v1/avatars/credit-cards/:code')
|
||||
->desc('Get Credit Card Icon')
|
||||
->param('code', '', function () use ($types) { return new WhiteList(array_keys($types['credit-cards'])); }, 'Credit Card Code. Possible values: '.implode(', ', array_keys($types['credit-cards'])).'.')
|
||||
->param('code', '', function () use ($types) { return new WhiteList(\array_keys($types['credit-cards'])); }, 'Credit Card Code. Possible values: '.\implode(', ', \array_keys($types['credit-cards'])).'.')
|
||||
->param('width', 100, function () { return new Range(0, 2000); }, 'Image width. Pass an integer between 0 to 2000. Defaults to 100.', true)
|
||||
->param('height', 100, function () { return new Range(0, 2000); }, 'Image height. Pass an integer between 0 to 2000. Defaults to 100.', true)
|
||||
->param('quality', 100, function () { return new Range(0, 100); }, 'Image quality. Pass an integer between 0 to 100. Defaults to 100.', true)
|
||||
|
@ -107,7 +107,7 @@ $utopia->get('/v1/avatars/credit-cards/:code')
|
|||
|
||||
$utopia->get('/v1/avatars/browsers/:code')
|
||||
->desc('Get Browser Icon')
|
||||
->param('code', '', function () use ($types) { return new WhiteList(array_keys($types['browsers'])); }, 'Browser Code.')
|
||||
->param('code', '', function () use ($types) { return new WhiteList(\array_keys($types['browsers'])); }, 'Browser Code.')
|
||||
->param('width', 100, function () { return new Range(0, 2000); }, 'Image width. Pass an integer between 0 to 2000. Defaults to 100.', true)
|
||||
->param('height', 100, function () { return new Range(0, 2000); }, 'Image height. Pass an integer between 0 to 2000. Defaults to 100.', true)
|
||||
->param('quality', 100, function () { return new Range(0, 100); }, 'Image quality. Pass an integer between 0 to 100. Defaults to 100.', true)
|
||||
|
@ -122,7 +122,7 @@ $utopia->get('/v1/avatars/browsers/:code')
|
|||
|
||||
$utopia->get('/v1/avatars/flags/:code')
|
||||
->desc('Get Country Flag')
|
||||
->param('code', '', function () use ($types) { return new WhiteList(array_keys($types['flags'])); }, 'Country Code. ISO Alpha-2 country code format.')
|
||||
->param('code', '', function () use ($types) { return new WhiteList(\array_keys($types['flags'])); }, 'Country Code. ISO Alpha-2 country code format.')
|
||||
->param('width', 100, function () { return new Range(0, 2000); }, 'Image width. Pass an integer between 0 to 2000. Defaults to 100.', true)
|
||||
->param('height', 100, function () { return new Range(0, 2000); }, 'Image height. Pass an integer between 0 to 2000. Defaults to 100.', true)
|
||||
->param('quality', 100, function () { return new Range(0, 100); }, 'Image quality. Pass an integer between 0 to 100. Defaults to 100.', true)
|
||||
|
@ -150,8 +150,8 @@ $utopia->get('/v1/avatars/image')
|
|||
function ($url, $width, $height) use ($response) {
|
||||
$quality = 80;
|
||||
$output = 'png';
|
||||
$date = date('D, d M Y H:i:s', time() + (60 * 60 * 24 * 45)).' GMT'; // 45 days cache
|
||||
$key = md5('/v2/avatars/images-'.$url.'-'.$width.'/'.$height.'/'.$quality);
|
||||
$date = \date('D, d M Y H:i:s', \time() + (60 * 60 * 24 * 45)).' GMT'; // 45 days cache
|
||||
$key = \md5('/v2/avatars/images-'.$url.'-'.$width.'/'.$height.'/'.$quality);
|
||||
$type = 'png';
|
||||
$cache = new Cache(new Filesystem(APP_STORAGE_CACHE.'/app-0')); // Limit file number or size
|
||||
$data = $cache->load($key, 60 * 60 * 24 * 7 /* 1 week */);
|
||||
|
@ -165,11 +165,11 @@ $utopia->get('/v1/avatars/image')
|
|||
;
|
||||
}
|
||||
|
||||
if (!extension_loaded('imagick')) {
|
||||
if (!\extension_loaded('imagick')) {
|
||||
throw new Exception('Imagick extension is missing', 500);
|
||||
}
|
||||
|
||||
$fetch = @file_get_contents($url, false);
|
||||
$fetch = @\file_get_contents($url, false);
|
||||
|
||||
if (!$fetch) {
|
||||
throw new Exception('Image not found', 404);
|
||||
|
@ -219,8 +219,8 @@ $utopia->get('/v1/avatars/favicon')
|
|||
$height = 56;
|
||||
$quality = 80;
|
||||
$output = 'png';
|
||||
$date = date('D, d M Y H:i:s', time() + (60 * 60 * 24 * 45)).' GMT'; // 45 days cache
|
||||
$key = md5('/v2/avatars/favicon-'.$url);
|
||||
$date = \date('D, d M Y H:i:s', \time() + (60 * 60 * 24 * 45)).' GMT'; // 45 days cache
|
||||
$key = \md5('/v2/avatars/favicon-'.$url);
|
||||
$type = 'png';
|
||||
$cache = new Cache(new Filesystem(APP_STORAGE_CACHE.'/app-0')); // Limit file number or size
|
||||
$data = $cache->load($key, 60 * 60 * 24 * 30 * 3 /* 3 months */);
|
||||
|
@ -234,26 +234,26 @@ $utopia->get('/v1/avatars/favicon')
|
|||
;
|
||||
}
|
||||
|
||||
if (!extension_loaded('imagick')) {
|
||||
if (!\extension_loaded('imagick')) {
|
||||
throw new Exception('Imagick extension is missing', 500);
|
||||
}
|
||||
|
||||
$curl = curl_init();
|
||||
$curl = \curl_init();
|
||||
|
||||
curl_setopt_array($curl, [
|
||||
\curl_setopt_array($curl, [
|
||||
CURLOPT_RETURNTRANSFER => 1,
|
||||
CURLOPT_FOLLOWLOCATION => true,
|
||||
CURLOPT_MAXREDIRS => 3,
|
||||
CURLOPT_URL => $url,
|
||||
CURLOPT_USERAGENT => sprintf(APP_USERAGENT,
|
||||
CURLOPT_USERAGENT => \sprintf(APP_USERAGENT,
|
||||
Config::getParam('version'),
|
||||
$request->getServer('_APP_SYSTEM_SECURITY_EMAIL_ADDRESS', APP_EMAIL_SECURITY)
|
||||
),
|
||||
]);
|
||||
|
||||
$html = curl_exec($curl);
|
||||
$html = \curl_exec($curl);
|
||||
|
||||
curl_close($curl);
|
||||
\curl_close($curl);
|
||||
|
||||
if (!$html) {
|
||||
throw new Exception('Failed to fetch remote URL', 404);
|
||||
|
@ -272,20 +272,20 @@ $utopia->get('/v1/avatars/favicon')
|
|||
$href = $link->getAttribute('href');
|
||||
$rel = $link->getAttribute('rel');
|
||||
$sizes = $link->getAttribute('sizes');
|
||||
$absolute = URLParse::unparse(array_merge(parse_url($url), parse_url($href)));
|
||||
$absolute = URLParse::unparse(\array_merge(\parse_url($url), \parse_url($href)));
|
||||
|
||||
switch (strtolower($rel)) {
|
||||
switch (\strtolower($rel)) {
|
||||
case 'icon':
|
||||
case 'shortcut icon':
|
||||
//case 'apple-touch-icon':
|
||||
$ext = pathinfo(parse_url($absolute, PHP_URL_PATH), PATHINFO_EXTENSION);
|
||||
$ext = \pathinfo(\parse_url($absolute, PHP_URL_PATH), PATHINFO_EXTENSION);
|
||||
|
||||
switch ($ext) {
|
||||
case 'ico':
|
||||
case 'png':
|
||||
case 'jpg':
|
||||
case 'jpeg':
|
||||
$size = explode('x', strtolower($sizes));
|
||||
$size = \explode('x', \strtolower($sizes));
|
||||
|
||||
$sizeWidth = (isset($size[0])) ? (int) $size[0] : 0;
|
||||
$sizeHeight = (isset($size[1])) ? (int) $size[1] : 0;
|
||||
|
@ -304,16 +304,16 @@ $utopia->get('/v1/avatars/favicon')
|
|||
}
|
||||
|
||||
if (empty($outputHref) || empty($outputExt)) {
|
||||
$default = parse_url($url);
|
||||
$default = \parse_url($url);
|
||||
|
||||
$outputHref = $default['scheme'].'://'.$default['host'].'/favicon.ico';
|
||||
$outputExt = 'ico';
|
||||
}
|
||||
|
||||
if ('ico' == $outputExt) { // Skip crop, Imagick isn\'t supporting icon files
|
||||
$data = @file_get_contents($outputHref, false);
|
||||
$data = @\file_get_contents($outputHref, false);
|
||||
|
||||
if (empty($data) || (mb_substr($data, 0, 5) === '<html') || mb_substr($data, 0, 5) === '<!doc') {
|
||||
if (empty($data) || (\mb_substr($data, 0, 5) === '<html') || \mb_substr($data, 0, 5) === '<!doc') {
|
||||
throw new Exception('Favicon not found', 404);
|
||||
}
|
||||
|
||||
|
@ -327,7 +327,7 @@ $utopia->get('/v1/avatars/favicon')
|
|||
;
|
||||
}
|
||||
|
||||
$fetch = @file_get_contents($outputHref, false);
|
||||
$fetch = @\file_get_contents($outputHref, false);
|
||||
|
||||
if (!$fetch) {
|
||||
throw new Exception('Icon not found', 404);
|
||||
|
@ -384,7 +384,7 @@ $utopia->get('/v1/avatars/qr')
|
|||
}
|
||||
|
||||
$response
|
||||
->addHeader('Expires', date('D, d M Y H:i:s', time() + (60 * 60 * 24 * 45)).' GMT') // 45 days cache
|
||||
->addHeader('Expires', \date('D, d M Y H:i:s', \time() + (60 * 60 * 24 * 45)).' GMT') // 45 days cache
|
||||
->setContentType('image/png')
|
||||
->send($writer->writeString($text))
|
||||
;
|
||||
|
@ -419,30 +419,30 @@ $utopia->get('/v1/avatars/initials')
|
|||
['color' => '#610008', 'background' => '#f6d2d5'] // RED
|
||||
];
|
||||
|
||||
$rand = rand(0, count($themes)-1);
|
||||
$rand = \rand(0, \count($themes)-1);
|
||||
|
||||
$name = (!empty($name)) ? $name : $user->getAttribute('name', $user->getAttribute('email', ''));
|
||||
$words = explode(' ', strtoupper($name));
|
||||
$words = \explode(' ', \strtoupper($name));
|
||||
$initials = null;
|
||||
$code = 0;
|
||||
|
||||
foreach ($words as $key => $w) {
|
||||
$initials .= (isset($w[0])) ? $w[0] : '';
|
||||
$code += (isset($w[0])) ? ord($w[0]) : 0;
|
||||
$code += (isset($w[0])) ? \ord($w[0]) : 0;
|
||||
|
||||
if($key == 1) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$length = count($words);
|
||||
$rand = substr($code,-1);
|
||||
$length = \count($words);
|
||||
$rand = \substr($code,-1);
|
||||
$background = (!empty($background)) ? '#'.$background : $themes[$rand]['background'];
|
||||
$color = (!empty($color)) ? '#'.$color : $themes[$rand]['color'];
|
||||
|
||||
$image = new \Imagick();
|
||||
$draw = new \ImagickDraw();
|
||||
$fontSize = min($width, $height) / 2;
|
||||
$fontSize = \min($width, $height) / 2;
|
||||
|
||||
$draw->setFont(__DIR__."/../../../public/fonts/poppins-v9-latin-500.ttf");
|
||||
$image->setFont(__DIR__."/../../../public/fonts/poppins-v9-latin-500.ttf");
|
||||
|
@ -460,7 +460,7 @@ $utopia->get('/v1/avatars/initials')
|
|||
//$image->setImageCompressionQuality(9 - round(($quality / 100) * 9));
|
||||
|
||||
$response
|
||||
->addHeader('Expires', date('D, d M Y H:i:s', time() + (60 * 60 * 24 * 45)).' GMT') // 45 days cache
|
||||
->addHeader('Expires', \date('D, d M Y H:i:s', \time() + (60 * 60 * 24 * 45)).' GMT') // 45 days cache
|
||||
->setContentType('image/png')
|
||||
->send($image->getImageBlob())
|
||||
;
|
||||
|
|
|
@ -46,7 +46,7 @@ $utopia->post('/v1/database/collections')
|
|||
$parsedRules = [];
|
||||
|
||||
foreach ($rules as &$rule) {
|
||||
$parsedRules[] = array_merge([
|
||||
$parsedRules[] = \array_merge([
|
||||
'$collection' => Database::SYSTEM_COLLECTION_RULES,
|
||||
'$permissions' => [
|
||||
'read' => $read,
|
||||
|
@ -59,8 +59,8 @@ $utopia->post('/v1/database/collections')
|
|||
$data = $projectDB->createDocument([
|
||||
'$collection' => Database::SYSTEM_COLLECTION_COLLECTIONS,
|
||||
'name' => $name,
|
||||
'dateCreated' => time(),
|
||||
'dateUpdated' => time(),
|
||||
'dateCreated' => \time(),
|
||||
'dateUpdated' => \time(),
|
||||
'structure' => true,
|
||||
'$permissions' => [
|
||||
'read' => $read,
|
||||
|
@ -258,7 +258,7 @@ $utopia->put('/v1/database/collections/:collectionId')
|
|||
$parsedRules = [];
|
||||
|
||||
foreach ($rules as &$rule) {
|
||||
$parsedRules[] = array_merge([
|
||||
$parsedRules[] = \array_merge([
|
||||
'$collection' => Database::SYSTEM_COLLECTION_RULES,
|
||||
'$permissions' => [
|
||||
'read' => $read,
|
||||
|
@ -268,10 +268,10 @@ $utopia->put('/v1/database/collections/:collectionId')
|
|||
}
|
||||
|
||||
try {
|
||||
$collection = $projectDB->updateDocument(array_merge($collection->getArrayCopy(), [
|
||||
$collection = $projectDB->updateDocument(\array_merge($collection->getArrayCopy(), [
|
||||
'name' => $name,
|
||||
'structure' => true,
|
||||
'dateUpdated' => time(),
|
||||
'dateUpdated' => \time(),
|
||||
'$permissions' => [
|
||||
'read' => $read,
|
||||
'write' => $write,
|
||||
|
@ -360,7 +360,7 @@ $utopia->post('/v1/database/collections/:collectionId/documents')
|
|||
->param('parentPropertyType', Document::SET_TYPE_ASSIGN, function () { return new WhiteList([Document::SET_TYPE_ASSIGN, Document::SET_TYPE_APPEND, Document::SET_TYPE_PREPEND]); }, 'Parent document property connection type. You can set this value to **assign**, **append** or **prepend**, default value is assign. Use when you want your new document to be a child of a parent document.', true)
|
||||
->action(
|
||||
function ($collectionId, $data, $read, $write, $parentDocument, $parentProperty, $parentPropertyType) use ($response, $projectDB, $webhook, $audit) {
|
||||
$data = (is_string($data)) ? json_decode($data, true) : $data; // Cast to JSON array
|
||||
$data = (\is_string($data)) ? \json_decode($data, true) : $data; // Cast to JSON array
|
||||
|
||||
if (empty($data)) {
|
||||
throw new Exception('Missing payload', 400);
|
||||
|
@ -372,7 +372,7 @@ $utopia->post('/v1/database/collections/:collectionId/documents')
|
|||
|
||||
$collection = $projectDB->getDocument($collectionId/*, $isDev*/);
|
||||
|
||||
if (is_null($collection->getId()) || Database::SYSTEM_COLLECTION_COLLECTIONS != $collection->getCollection()) {
|
||||
if (\is_null($collection->getId()) || Database::SYSTEM_COLLECTION_COLLECTIONS != $collection->getCollection()) {
|
||||
throw new Exception('Collection not found', 404);
|
||||
}
|
||||
|
||||
|
@ -483,7 +483,7 @@ $utopia->get('/v1/database/collections/:collectionId/documents')
|
|||
function ($collectionId, $filters, $offset, $limit, $orderField, $orderType, $orderCast, $search, $first, $last) use ($response, $projectDB, $isDev) {
|
||||
$collection = $projectDB->getDocument($collectionId, $isDev);
|
||||
|
||||
if (is_null($collection->getId()) || Database::SYSTEM_COLLECTION_COLLECTIONS != $collection->getCollection()) {
|
||||
if (\is_null($collection->getId()) || Database::SYSTEM_COLLECTION_COLLECTIONS != $collection->getCollection()) {
|
||||
throw new Exception('Collection not found', 404);
|
||||
}
|
||||
|
||||
|
@ -496,7 +496,7 @@ $utopia->get('/v1/database/collections/:collectionId/documents')
|
|||
'search' => $search,
|
||||
'first' => (bool) $first,
|
||||
'last' => (bool) $last,
|
||||
'filters' => array_merge($filters, [
|
||||
'filters' => \array_merge($filters, [
|
||||
'$collection='.$collectionId,
|
||||
]),
|
||||
]);
|
||||
|
@ -549,20 +549,20 @@ $utopia->get('/v1/database/collections/:collectionId/documents/:documentId')
|
|||
|
||||
$output = $document->getArrayCopy();
|
||||
|
||||
$paths = explode('/', $request->getParam('q', ''));
|
||||
$paths = array_slice($paths, 7, count($paths));
|
||||
$paths = \explode('/', $request->getParam('q', ''));
|
||||
$paths = \array_slice($paths, 7, \count($paths));
|
||||
|
||||
if (count($paths) > 0) {
|
||||
if (count($paths) % 2 == 1) {
|
||||
$output = $document->getAttribute(implode('.', $paths));
|
||||
if (\count($paths) > 0) {
|
||||
if (\count($paths) % 2 == 1) {
|
||||
$output = $document->getAttribute(\implode('.', $paths));
|
||||
} else {
|
||||
$id = (int) array_pop($paths);
|
||||
$output = $document->search('$id', $id, $document->getAttribute(implode('.', $paths)));
|
||||
$id = (int) \array_pop($paths);
|
||||
$output = $document->search('$id', $id, $document->getAttribute(\implode('.', $paths)));
|
||||
}
|
||||
|
||||
$output = ($output instanceof Document) ? $output->getArrayCopy() : $output;
|
||||
|
||||
if (!is_array($output)) {
|
||||
if (!\is_array($output)) {
|
||||
throw new Exception('No document found', 404);
|
||||
}
|
||||
}
|
||||
|
@ -592,13 +592,13 @@ $utopia->patch('/v1/database/collections/:collectionId/documents/:documentId')
|
|||
$collection = $projectDB->getDocument($collectionId/*, $isDev*/);
|
||||
$document = $projectDB->getDocument($documentId, $isDev);
|
||||
|
||||
$data = (is_string($data)) ? json_decode($data, true) : $data; // Cast to JSON array
|
||||
$data = (\is_string($data)) ? \json_decode($data, true) : $data; // Cast to JSON array
|
||||
|
||||
if (!is_array($data)) {
|
||||
if (!\is_array($data)) {
|
||||
throw new Exception('Data param should be a valid JSON', 400);
|
||||
}
|
||||
|
||||
if (is_null($collection->getId()) || Database::SYSTEM_COLLECTION_COLLECTIONS != $collection->getCollection()) {
|
||||
if (\is_null($collection->getId()) || Database::SYSTEM_COLLECTION_COLLECTIONS != $collection->getCollection()) {
|
||||
throw new Exception('Collection not found', 404);
|
||||
}
|
||||
|
||||
|
@ -616,7 +616,7 @@ $utopia->patch('/v1/database/collections/:collectionId/documents/:documentId')
|
|||
$data['$permissions']['write'] = $read;
|
||||
}
|
||||
|
||||
$data = array_merge($document->getArrayCopy(), $data);
|
||||
$data = \array_merge($document->getArrayCopy(), $data);
|
||||
|
||||
$data['$collection'] = $collection->getId(); // Make sure user don't switch collectionID
|
||||
$data['$id'] = $document->getId(); // Make sure user don't switch document unique ID
|
||||
|
@ -672,7 +672,7 @@ $utopia->delete('/v1/database/collections/:collectionId/documents/:documentId')
|
|||
throw new Exception('No document found', 404);
|
||||
}
|
||||
|
||||
if (is_null($collection->getId()) || Database::SYSTEM_COLLECTION_COLLECTIONS != $collection->getCollection()) {
|
||||
if (\is_null($collection->getId()) || Database::SYSTEM_COLLECTION_COLLECTIONS != $collection->getCollection()) {
|
||||
throw new Exception('Collection not found', 404);
|
||||
}
|
||||
|
||||
|
|
|
@ -75,34 +75,34 @@ $utopia->get('/v1/health/time')
|
|||
$gap = 60; // Allow [X] seconds gap
|
||||
|
||||
/* Create a socket and connect to NTP server */
|
||||
$sock = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP);
|
||||
$sock = \socket_create(AF_INET, SOCK_DGRAM, SOL_UDP);
|
||||
|
||||
socket_connect($sock, $host, 123);
|
||||
\socket_connect($sock, $host, 123);
|
||||
|
||||
/* Send request */
|
||||
$msg = "\010".str_repeat("\0", 47);
|
||||
$msg = "\010".\str_repeat("\0", 47);
|
||||
|
||||
socket_send($sock, $msg, strlen($msg), 0);
|
||||
\socket_send($sock, $msg, \strlen($msg), 0);
|
||||
|
||||
/* Receive response and close socket */
|
||||
socket_recv($sock, $recv, 48, MSG_WAITALL);
|
||||
socket_close($sock);
|
||||
\socket_recv($sock, $recv, 48, MSG_WAITALL);
|
||||
\socket_close($sock);
|
||||
|
||||
/* Interpret response */
|
||||
$data = unpack('N12', $recv);
|
||||
$timestamp = sprintf('%u', $data[9]);
|
||||
$data = \unpack('N12', $recv);
|
||||
$timestamp = \sprintf('%u', $data[9]);
|
||||
|
||||
/* NTP is number of seconds since 0000 UT on 1 January 1900
|
||||
Unix time is seconds since 0000 UT on 1 January 1970 */
|
||||
$timestamp -= 2208988800;
|
||||
|
||||
$diff = ($timestamp - time());
|
||||
$diff = ($timestamp - \time());
|
||||
|
||||
if ($diff > $gap || $diff < ($gap * -1)) {
|
||||
throw new Exception('Server time gaps detected');
|
||||
}
|
||||
|
||||
$response->json(['remote' => $timestamp, 'local' => time(), 'diff' => $diff]);
|
||||
$response->json(['remote' => $timestamp, 'local' => \time(), 'diff' => $diff]);
|
||||
}
|
||||
);
|
||||
|
||||
|
@ -202,11 +202,11 @@ $utopia->get('/v1/health/storage/local')
|
|||
] as $key => $volume) {
|
||||
$device = new Local($volume);
|
||||
|
||||
if (!is_readable($device->getRoot())) {
|
||||
if (!\is_readable($device->getRoot())) {
|
||||
throw new Exception('Device '.$key.' dir is not readable');
|
||||
}
|
||||
|
||||
if (!is_writable($device->getRoot())) {
|
||||
if (!\is_writable($device->getRoot())) {
|
||||
throw new Exception('Device '.$key.' dir is not writable');
|
||||
}
|
||||
}
|
||||
|
@ -255,7 +255,7 @@ $utopia->get('/v1/health/stats') // Currently only used internally
|
|||
->json([
|
||||
'server' => [
|
||||
'name' => 'nginx',
|
||||
'version' => shell_exec('nginx -v 2>&1'),
|
||||
'version' => \shell_exec('nginx -v 2>&1'),
|
||||
],
|
||||
'storage' => [
|
||||
'used' => Storage::human($device->getDirectorySize($device->getRoot().'/')),
|
||||
|
|
|
@ -41,10 +41,10 @@ $utopia->get('/v1/locale')
|
|||
//$output['countryTimeZone'] = DateTimeZone::listIdentifiers(DateTimeZone::PER_COUNTRY, $record->country->isoCode);
|
||||
$output['continent'] = (isset($continents[$record->continent->code])) ? $continents[$record->continent->code] : Locale::getText('locale.country.unknown');
|
||||
$output['continentCode'] = $record->continent->code;
|
||||
$output['eu'] = (in_array($record->country->isoCode, $eu)) ? true : false;
|
||||
$output['eu'] = (\in_array($record->country->isoCode, $eu)) ? true : false;
|
||||
|
||||
foreach ($currencies as $code => $element) {
|
||||
if (isset($element['locations']) && isset($element['code']) && in_array($record->country->isoCode, $element['locations'])) {
|
||||
if (isset($element['locations']) && isset($element['code']) && \in_array($record->country->isoCode, $element['locations'])) {
|
||||
$currency = $element['code'];
|
||||
}
|
||||
}
|
||||
|
@ -61,7 +61,7 @@ $utopia->get('/v1/locale')
|
|||
|
||||
$response
|
||||
->addHeader('Cache-Control', 'public, max-age='.$time)
|
||||
->addHeader('Expires', date('D, d M Y H:i:s', time() + $time).' GMT') // 45 days cache
|
||||
->addHeader('Expires', \date('D, d M Y H:i:s', \time() + $time).' GMT') // 45 days cache
|
||||
->json($output);
|
||||
}
|
||||
);
|
||||
|
@ -77,7 +77,7 @@ $utopia->get('/v1/locale/countries')
|
|||
function () use ($response) {
|
||||
$list = Locale::getText('countries'); /* @var $list array */
|
||||
|
||||
asort($list);
|
||||
\asort($list);
|
||||
|
||||
$response->json($list);
|
||||
}
|
||||
|
@ -97,12 +97,12 @@ $utopia->get('/v1/locale/countries/eu')
|
|||
$list = [];
|
||||
|
||||
foreach ($eu as $code) {
|
||||
if (array_key_exists($code, $countries)) {
|
||||
if (\array_key_exists($code, $countries)) {
|
||||
$list[$code] = $countries[$code];
|
||||
}
|
||||
}
|
||||
|
||||
asort($list);
|
||||
\asort($list);
|
||||
|
||||
$response->json($list);
|
||||
}
|
||||
|
@ -122,12 +122,12 @@ $utopia->get('/v1/locale/countries/phones')
|
|||
$countries = Locale::getText('countries'); /* @var $countries array */
|
||||
|
||||
foreach ($list as $code => $name) {
|
||||
if (array_key_exists($code, $countries)) {
|
||||
if (\array_key_exists($code, $countries)) {
|
||||
$list[$code] = '+'.$list[$code];
|
||||
}
|
||||
}
|
||||
|
||||
asort($list);
|
||||
\asort($list);
|
||||
|
||||
$response->json($list);
|
||||
}
|
||||
|
@ -144,7 +144,7 @@ $utopia->get('/v1/locale/continents')
|
|||
function () use ($response) {
|
||||
$list = Locale::getText('continents'); /* @var $list array */
|
||||
|
||||
asort($list);
|
||||
\asort($list);
|
||||
|
||||
$response->json($list);
|
||||
}
|
||||
|
|
|
@ -107,11 +107,11 @@ $utopia->get('/v1/projects')
|
|||
|
||||
foreach ($results as $project) {
|
||||
foreach (Config::getParam('providers') as $provider => $node) {
|
||||
$secret = json_decode($project->getAttribute('usersOauth2'.ucfirst($provider).'Secret', '{}'), true);
|
||||
$secret = \json_decode($project->getAttribute('usersOauth2'.\ucfirst($provider).'Secret', '{}'), true);
|
||||
|
||||
if (!empty($secret) && isset($secret['version'])) {
|
||||
$key = $request->getServer('_APP_OPENSSL_KEY_V'.$secret['version']);
|
||||
$project->setAttribute('usersOauth2'.ucfirst($provider).'Secret', OpenSSL::decrypt($secret['data'], $secret['method'], $key, 0, hex2bin($secret['iv']), hex2bin($secret['tag'])));
|
||||
$project->setAttribute('usersOauth2'.\ucfirst($provider).'Secret', OpenSSL::decrypt($secret['data'], $secret['method'], $key, 0, \hex2bin($secret['iv']), \hex2bin($secret['tag'])));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -135,11 +135,11 @@ $utopia->get('/v1/projects/:projectId')
|
|||
}
|
||||
|
||||
foreach (Config::getParam('providers') as $provider => $node) {
|
||||
$secret = json_decode($project->getAttribute('usersOauth2'.ucfirst($provider).'Secret', '{}'), true);
|
||||
$secret = \json_decode($project->getAttribute('usersOauth2'.\ucfirst($provider).'Secret', '{}'), true);
|
||||
|
||||
if (!empty($secret) && isset($secret['version'])) {
|
||||
$key = $request->getServer('_APP_OPENSSL_KEY_V'.$secret['version']);
|
||||
$project->setAttribute('usersOauth2'.ucfirst($provider).'Secret', OpenSSL::decrypt($secret['data'], $secret['method'], $key, 0, hex2bin($secret['iv']), hex2bin($secret['tag'])));
|
||||
$project->setAttribute('usersOauth2'.\ucfirst($provider).'Secret', OpenSSL::decrypt($secret['data'], $secret['method'], $key, 0, \hex2bin($secret['iv']), \hex2bin($secret['tag'])));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -164,23 +164,23 @@ $utopia->get('/v1/projects/:projectId/usage')
|
|||
|
||||
$period = [
|
||||
'daily' => [
|
||||
'start' => DateTime::createFromFormat('U', strtotime('today')),
|
||||
'end' => DateTime::createFromFormat('U', strtotime('tomorrow')),
|
||||
'start' => DateTime::createFromFormat('U', \strtotime('today')),
|
||||
'end' => DateTime::createFromFormat('U', \strtotime('tomorrow')),
|
||||
'group' => '1m',
|
||||
],
|
||||
'monthly' => [
|
||||
'start' => DateTime::createFromFormat('U', strtotime('midnight first day of this month')),
|
||||
'end' => DateTime::createFromFormat('U', strtotime('midnight last day of this month')),
|
||||
'start' => DateTime::createFromFormat('U', \strtotime('midnight first day of this month')),
|
||||
'end' => DateTime::createFromFormat('U', \strtotime('midnight last day of this month')),
|
||||
'group' => '1d',
|
||||
],
|
||||
'last30' => [
|
||||
'start' => DateTime::createFromFormat('U', strtotime('-30 days')),
|
||||
'end' => DateTime::createFromFormat('U', strtotime('tomorrow')),
|
||||
'start' => DateTime::createFromFormat('U', \strtotime('-30 days')),
|
||||
'end' => DateTime::createFromFormat('U', \strtotime('tomorrow')),
|
||||
'group' => '1d',
|
||||
],
|
||||
'last90' => [
|
||||
'start' => DateTime::createFromFormat('U', strtotime('-90 days')),
|
||||
'end' => DateTime::createFromFormat('U', strtotime('today')),
|
||||
'start' => DateTime::createFromFormat('U', \strtotime('-90 days')),
|
||||
'end' => DateTime::createFromFormat('U', \strtotime('today')),
|
||||
'group' => '1d',
|
||||
],
|
||||
// 'yearly' => [
|
||||
|
@ -207,7 +207,7 @@ $utopia->get('/v1/projects/:projectId/usage')
|
|||
foreach ($points as $point) {
|
||||
$requests[] = [
|
||||
'value' => (!empty($point['value'])) ? $point['value'] : 0,
|
||||
'date' => strtotime($point['time']),
|
||||
'date' => \strtotime($point['time']),
|
||||
];
|
||||
}
|
||||
|
||||
|
@ -218,7 +218,7 @@ $utopia->get('/v1/projects/:projectId/usage')
|
|||
foreach ($points as $point) {
|
||||
$network[] = [
|
||||
'value' => (!empty($point['value'])) ? $point['value'] : 0,
|
||||
'date' => strtotime($point['time']),
|
||||
'date' => \strtotime($point['time']),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
@ -262,18 +262,18 @@ $utopia->get('/v1/projects/:projectId/usage')
|
|||
}
|
||||
|
||||
// Tasks
|
||||
$tasksTotal = count($project->getAttribute('tasks', []));
|
||||
$tasksTotal = \count($project->getAttribute('tasks', []));
|
||||
|
||||
$response->json([
|
||||
'requests' => [
|
||||
'data' => $requests,
|
||||
'total' => array_sum(array_map(function ($item) {
|
||||
'total' => \array_sum(\array_map(function ($item) {
|
||||
return $item['value'];
|
||||
}, $requests)),
|
||||
],
|
||||
'network' => [
|
||||
'data' => $network,
|
||||
'total' => array_sum(array_map(function ($item) {
|
||||
'total' => \array_sum(\array_map(function ($item) {
|
||||
return $item['value'];
|
||||
}, $network)),
|
||||
],
|
||||
|
@ -283,7 +283,7 @@ $utopia->get('/v1/projects/:projectId/usage')
|
|||
],
|
||||
'documents' => [
|
||||
'data' => $documents,
|
||||
'total' => array_sum(array_map(function ($item) {
|
||||
'total' => \array_sum(\array_map(function ($item) {
|
||||
return $item['total'];
|
||||
}, $documents)),
|
||||
],
|
||||
|
@ -332,7 +332,7 @@ $utopia->patch('/v1/projects/:projectId')
|
|||
throw new Exception('Project not found', 404);
|
||||
}
|
||||
|
||||
$project = $consoleDB->updateDocument(array_merge($project->getArrayCopy(), [
|
||||
$project = $consoleDB->updateDocument(\array_merge($project->getArrayCopy(), [
|
||||
'name' => $name,
|
||||
'description' => $description,
|
||||
'logo' => $logo,
|
||||
|
@ -359,7 +359,7 @@ $utopia->patch('/v1/projects/:projectId/oauth2')
|
|||
->label('sdk.namespace', 'projects')
|
||||
->label('sdk.method', 'updateOAuth2')
|
||||
->param('projectId', '', function () { return new UID(); }, 'Project unique ID.')
|
||||
->param('provider', '', function () { return new WhiteList(array_keys(Config::getParam('providers'))); }, 'Provider Name', false)
|
||||
->param('provider', '', function () { return new WhiteList(\array_keys(Config::getParam('providers'))); }, 'Provider Name', false)
|
||||
->param('appId', '', function () { return new Text(256); }, 'Provider app ID.', true)
|
||||
->param('secret', '', function () { return new text(512); }, 'Provider secret key.', true)
|
||||
->action(
|
||||
|
@ -373,17 +373,17 @@ $utopia->patch('/v1/projects/:projectId/oauth2')
|
|||
$key = $request->getServer('_APP_OPENSSL_KEY_V1');
|
||||
$iv = OpenSSL::randomPseudoBytes(OpenSSL::cipherIVLength(OpenSSL::CIPHER_AES_128_GCM));
|
||||
$tag = null;
|
||||
$secret = json_encode([
|
||||
$secret = \json_encode([
|
||||
'data' => OpenSSL::encrypt($secret, OpenSSL::CIPHER_AES_128_GCM, $key, 0, $iv, $tag),
|
||||
'method' => OpenSSL::CIPHER_AES_128_GCM,
|
||||
'iv' => bin2hex($iv),
|
||||
'tag' => bin2hex($tag),
|
||||
'iv' => \bin2hex($iv),
|
||||
'tag' => \bin2hex($tag),
|
||||
'version' => '1',
|
||||
]);
|
||||
|
||||
$project = $consoleDB->updateDocument(array_merge($project->getArrayCopy(), [
|
||||
'usersOauth2'.ucfirst($provider).'Appid' => $appId,
|
||||
'usersOauth2'.ucfirst($provider).'Secret' => $secret,
|
||||
$project = $consoleDB->updateDocument(\array_merge($project->getArrayCopy(), [
|
||||
'usersOauth2'.\ucfirst($provider).'Appid' => $appId,
|
||||
'usersOauth2'.\ucfirst($provider).'Secret' => $secret,
|
||||
]));
|
||||
|
||||
if (false === $project) {
|
||||
|
@ -462,11 +462,11 @@ $utopia->post('/v1/projects/:projectId/webhooks')
|
|||
$key = $request->getServer('_APP_OPENSSL_KEY_V1');
|
||||
$iv = OpenSSL::randomPseudoBytes(OpenSSL::cipherIVLength(OpenSSL::CIPHER_AES_128_GCM));
|
||||
$tag = null;
|
||||
$httpPass = json_encode([
|
||||
$httpPass = \json_encode([
|
||||
'data' => OpenSSL::encrypt($httpPass, OpenSSL::CIPHER_AES_128_GCM, $key, 0, $iv, $tag),
|
||||
'method' => OpenSSL::CIPHER_AES_128_GCM,
|
||||
'iv' => bin2hex($iv),
|
||||
'tag' => bin2hex($tag),
|
||||
'iv' => \bin2hex($iv),
|
||||
'tag' => \bin2hex($tag),
|
||||
'version' => '1',
|
||||
]);
|
||||
|
||||
|
@ -520,7 +520,7 @@ $utopia->get('/v1/projects/:projectId/webhooks')
|
|||
$webhooks = $project->getAttribute('webhooks', []);
|
||||
|
||||
foreach ($webhooks as $webhook) { /* @var $webhook Document */
|
||||
$httpPass = json_decode($webhook->getAttribute('httpPass', '{}'), true);
|
||||
$httpPass = \json_decode($webhook->getAttribute('httpPass', '{}'), true);
|
||||
|
||||
if (empty($httpPass) || !isset($httpPass['version'])) {
|
||||
continue;
|
||||
|
@ -528,7 +528,7 @@ $utopia->get('/v1/projects/:projectId/webhooks')
|
|||
|
||||
$key = $request->getServer('_APP_OPENSSL_KEY_V'.$httpPass['version']);
|
||||
|
||||
$webhook->setAttribute('httpPass', OpenSSL::decrypt($httpPass['data'], $httpPass['method'], $key, 0, hex2bin($httpPass['iv']), hex2bin($httpPass['tag'])));
|
||||
$webhook->setAttribute('httpPass', OpenSSL::decrypt($httpPass['data'], $httpPass['method'], $key, 0, \hex2bin($httpPass['iv']), \hex2bin($httpPass['tag'])));
|
||||
}
|
||||
|
||||
$response->json($webhooks);
|
||||
|
@ -556,11 +556,11 @@ $utopia->get('/v1/projects/:projectId/webhooks/:webhookId')
|
|||
throw new Exception('Webhook not found', 404);
|
||||
}
|
||||
|
||||
$httpPass = json_decode($webhook->getAttribute('httpPass', '{}'), true);
|
||||
$httpPass = \json_decode($webhook->getAttribute('httpPass', '{}'), true);
|
||||
|
||||
if (!empty($httpPass) && isset($httpPass['version'])) {
|
||||
$key = $request->getServer('_APP_OPENSSL_KEY_V'.$httpPass['version']);
|
||||
$webhook->setAttribute('httpPass', OpenSSL::decrypt($httpPass['data'], $httpPass['method'], $key, 0, hex2bin($httpPass['iv']), hex2bin($httpPass['tag'])));
|
||||
$webhook->setAttribute('httpPass', OpenSSL::decrypt($httpPass['data'], $httpPass['method'], $key, 0, \hex2bin($httpPass['iv']), \hex2bin($httpPass['tag'])));
|
||||
}
|
||||
|
||||
$response->json($webhook->getArrayCopy());
|
||||
|
@ -592,11 +592,11 @@ $utopia->put('/v1/projects/:projectId/webhooks/:webhookId')
|
|||
$key = $request->getServer('_APP_OPENSSL_KEY_V1');
|
||||
$iv = OpenSSL::randomPseudoBytes(OpenSSL::cipherIVLength(OpenSSL::CIPHER_AES_128_GCM));
|
||||
$tag = null;
|
||||
$httpPass = json_encode([
|
||||
$httpPass = \json_encode([
|
||||
'data' => OpenSSL::encrypt($httpPass, OpenSSL::CIPHER_AES_128_GCM, $key, 0, $iv, $tag),
|
||||
'method' => OpenSSL::CIPHER_AES_128_GCM,
|
||||
'iv' => bin2hex($iv),
|
||||
'tag' => bin2hex($tag),
|
||||
'iv' => \bin2hex($iv),
|
||||
'tag' => \bin2hex($tag),
|
||||
'version' => '1',
|
||||
]);
|
||||
|
||||
|
@ -678,7 +678,7 @@ $utopia->post('/v1/projects/:projectId/keys')
|
|||
],
|
||||
'name' => $name,
|
||||
'scopes' => $scopes,
|
||||
'secret' => bin2hex(random_bytes(128)),
|
||||
'secret' => \bin2hex(\random_bytes(128)),
|
||||
]);
|
||||
|
||||
if (false === $key) {
|
||||
|
@ -839,11 +839,11 @@ $utopia->post('/v1/projects/:projectId/tasks')
|
|||
$key = $request->getServer('_APP_OPENSSL_KEY_V1');
|
||||
$iv = OpenSSL::randomPseudoBytes(OpenSSL::cipherIVLength(OpenSSL::CIPHER_AES_128_GCM));
|
||||
$tag = null;
|
||||
$httpPass = json_encode([
|
||||
$httpPass = \json_encode([
|
||||
'data' => OpenSSL::encrypt($httpPass, OpenSSL::CIPHER_AES_128_GCM, $key, 0, $iv, $tag),
|
||||
'method' => OpenSSL::CIPHER_AES_128_GCM,
|
||||
'iv' => bin2hex($iv),
|
||||
'tag' => bin2hex($tag),
|
||||
'iv' => \bin2hex($iv),
|
||||
'tag' => \bin2hex($tag),
|
||||
'version' => '1',
|
||||
]);
|
||||
|
||||
|
@ -856,7 +856,7 @@ $utopia->post('/v1/projects/:projectId/tasks')
|
|||
'name' => $name,
|
||||
'status' => $status,
|
||||
'schedule' => $schedule,
|
||||
'updated' => time(),
|
||||
'updated' => \time(),
|
||||
'previous' => null,
|
||||
'next' => $next,
|
||||
'security' => (int) $security,
|
||||
|
@ -909,7 +909,7 @@ $utopia->get('/v1/projects/:projectId/tasks')
|
|||
$tasks = $project->getAttribute('tasks', []);
|
||||
|
||||
foreach ($tasks as $task) { /* @var $task Document */
|
||||
$httpPass = json_decode($task->getAttribute('httpPass', '{}'), true);
|
||||
$httpPass = \json_decode($task->getAttribute('httpPass', '{}'), true);
|
||||
|
||||
if (empty($httpPass) || !isset($httpPass['version'])) {
|
||||
continue;
|
||||
|
@ -917,7 +917,7 @@ $utopia->get('/v1/projects/:projectId/tasks')
|
|||
|
||||
$key = $request->getServer('_APP_OPENSSL_KEY_V'.$httpPass['version']);
|
||||
|
||||
$task->setAttribute('httpPass', OpenSSL::decrypt($httpPass['data'], $httpPass['method'], $key, 0, hex2bin($httpPass['iv']), hex2bin($httpPass['tag'])));
|
||||
$task->setAttribute('httpPass', OpenSSL::decrypt($httpPass['data'], $httpPass['method'], $key, 0, \hex2bin($httpPass['iv']), \hex2bin($httpPass['tag'])));
|
||||
}
|
||||
|
||||
$response->json($tasks);
|
||||
|
@ -945,11 +945,11 @@ $utopia->get('/v1/projects/:projectId/tasks/:taskId')
|
|||
throw new Exception('Task not found', 404);
|
||||
}
|
||||
|
||||
$httpPass = json_decode($task->getAttribute('httpPass', '{}'), true);
|
||||
$httpPass = \json_decode($task->getAttribute('httpPass', '{}'), true);
|
||||
|
||||
if (!empty($httpPass) && isset($httpPass['version'])) {
|
||||
$key = $request->getServer('_APP_OPENSSL_KEY_V'.$httpPass['version']);
|
||||
$task->setAttribute('httpPass', OpenSSL::decrypt($httpPass['data'], $httpPass['method'], $key, 0, hex2bin($httpPass['iv']), hex2bin($httpPass['tag'])));
|
||||
$task->setAttribute('httpPass', OpenSSL::decrypt($httpPass['data'], $httpPass['method'], $key, 0, \hex2bin($httpPass['iv']), \hex2bin($httpPass['tag'])));
|
||||
}
|
||||
|
||||
$response->json($task->getArrayCopy());
|
||||
|
@ -992,11 +992,11 @@ $utopia->put('/v1/projects/:projectId/tasks/:taskId')
|
|||
$key = $request->getServer('_APP_OPENSSL_KEY_V1');
|
||||
$iv = OpenSSL::randomPseudoBytes(OpenSSL::cipherIVLength(OpenSSL::CIPHER_AES_128_GCM));
|
||||
$tag = null;
|
||||
$httpPass = json_encode([
|
||||
$httpPass = \json_encode([
|
||||
'data' => OpenSSL::encrypt($httpPass, OpenSSL::CIPHER_AES_128_GCM, $key, 0, $iv, $tag),
|
||||
'method' => OpenSSL::CIPHER_AES_128_GCM,
|
||||
'iv' => bin2hex($iv),
|
||||
'tag' => bin2hex($tag),
|
||||
'iv' => \bin2hex($iv),
|
||||
'tag' => \bin2hex($tag),
|
||||
'version' => '1',
|
||||
]);
|
||||
|
||||
|
@ -1004,7 +1004,7 @@ $utopia->put('/v1/projects/:projectId/tasks/:taskId')
|
|||
->setAttribute('name', $name)
|
||||
->setAttribute('status', $status)
|
||||
->setAttribute('schedule', $schedule)
|
||||
->setAttribute('updated', time())
|
||||
->setAttribute('updated', \time())
|
||||
->setAttribute('next', $next)
|
||||
->setAttribute('security', (int) $security)
|
||||
->setAttribute('httpMethod', $httpMethod)
|
||||
|
@ -1087,8 +1087,8 @@ $utopia->post('/v1/projects/:projectId/platforms')
|
|||
'key' => $key,
|
||||
'store' => $store,
|
||||
'hostname' => $hostname,
|
||||
'dateCreated' => time(),
|
||||
'dateUpdated' => time(),
|
||||
'dateCreated' => \time(),
|
||||
'dateUpdated' => \time(),
|
||||
]);
|
||||
|
||||
if (false === $platform) {
|
||||
|
@ -1182,7 +1182,7 @@ $utopia->put('/v1/projects/:projectId/platforms/:platformId')
|
|||
|
||||
$platform
|
||||
->setAttribute('name', $name)
|
||||
->setAttribute('dateUpdated', time())
|
||||
->setAttribute('dateUpdated', \time())
|
||||
->setAttribute('key', $key)
|
||||
->setAttribute('store', $store)
|
||||
->setAttribute('hostname', $hostname)
|
||||
|
@ -1262,7 +1262,7 @@ $utopia->post('/v1/projects/:projectId/domains')
|
|||
'read' => ['team:'.$project->getAttribute('teamId', null)],
|
||||
'write' => ['team:'.$project->getAttribute('teamId', null).'/owner', 'team:'.$project->getAttribute('teamId', null).'/developer'],
|
||||
],
|
||||
'updated' => time(),
|
||||
'updated' => \time(),
|
||||
'domain' => $domain->get(),
|
||||
'tld' => $domain->getSuffix(),
|
||||
'registerable' => $domain->getRegisterable(),
|
||||
|
|
|
@ -165,9 +165,9 @@ $utopia->post('/v1/storage/files')
|
|||
}
|
||||
|
||||
// Make sure we handle a single file and multiple files the same way
|
||||
$file['name'] = (is_array($file['name']) && isset($file['name'][0])) ? $file['name'][0] : $file['name'];
|
||||
$file['tmp_name'] = (is_array($file['tmp_name']) && isset($file['tmp_name'][0])) ? $file['tmp_name'][0] : $file['tmp_name'];
|
||||
$file['size'] = (is_array($file['size']) && isset($file['size'][0])) ? $file['size'][0] : $file['size'];
|
||||
$file['name'] = (\is_array($file['name']) && isset($file['name'][0])) ? $file['name'][0] : $file['name'];
|
||||
$file['tmp_name'] = (\is_array($file['tmp_name']) && isset($file['tmp_name'][0])) ? $file['tmp_name'][0] : $file['tmp_name'];
|
||||
$file['size'] = (\is_array($file['size']) && isset($file['size'][0])) ? $file['size'][0] : $file['size'];
|
||||
|
||||
// Check if file type is allowed (feature for project settings?)
|
||||
//if (!$fileType->isValid($file['tmp_name'])) {
|
||||
|
@ -190,7 +190,7 @@ $utopia->post('/v1/storage/files')
|
|||
|
||||
// Save to storage
|
||||
$size = $device->getFileSize($file['tmp_name']);
|
||||
$path = $device->getPath(uniqid().'.'.pathinfo($file['name'], PATHINFO_EXTENSION));
|
||||
$path = $device->getPath(\uniqid().'.'.\pathinfo($file['name'], PATHINFO_EXTENSION));
|
||||
|
||||
if (!$device->upload($file['tmp_name'], $path)) { // TODO deprecate 'upload' and replace with 'move'
|
||||
throw new Exception('Failed moving file', 500);
|
||||
|
@ -228,7 +228,7 @@ $utopia->post('/v1/storage/files')
|
|||
'read' => $read,
|
||||
'write' => $write,
|
||||
],
|
||||
'dateCreated' => time(),
|
||||
'dateCreated' => \time(),
|
||||
'folderId' => $folderId,
|
||||
'name' => $file['name'],
|
||||
'path' => $path,
|
||||
|
@ -237,12 +237,12 @@ $utopia->post('/v1/storage/files')
|
|||
'sizeOriginal' => $size,
|
||||
'sizeActual' => $sizeActual,
|
||||
'algorithm' => $compressor->getName(),
|
||||
'token' => bin2hex(random_bytes(64)),
|
||||
'token' => \bin2hex(\random_bytes(64)),
|
||||
'comment' => '',
|
||||
'fileOpenSSLVersion' => '1',
|
||||
'fileOpenSSLCipher' => OpenSSL::CIPHER_AES_128_GCM,
|
||||
'fileOpenSSLTag' => bin2hex($tag),
|
||||
'fileOpenSSLIV' => bin2hex($iv),
|
||||
'fileOpenSSLTag' => \bin2hex($tag),
|
||||
'fileOpenSSLIV' => \bin2hex($iv),
|
||||
]);
|
||||
|
||||
if (false === $file) {
|
||||
|
@ -294,7 +294,7 @@ $utopia->get('/v1/storage/files')
|
|||
],
|
||||
]);
|
||||
|
||||
$results = array_map(function ($value) { /* @var $value \Database\Document */
|
||||
$results = \array_map(function ($value) { /* @var $value \Database\Document */
|
||||
return $value->getArrayCopy(['$id', '$permissions', 'name', 'dateCreated', 'signature', 'mimeType', 'sizeOriginal']);
|
||||
}, $results);
|
||||
|
||||
|
@ -336,14 +336,14 @@ $utopia->get('/v1/storage/files/:fileId/preview')
|
|||
->param('height', 0, function () { return new Range(0, 4000); }, 'Resize preview image height, Pass an integer between 0 to 4000.', true)
|
||||
->param('quality', 100, function () { return new Range(0, 100); }, 'Preview image quality. Pass an integer between 0 to 100. Defaults to 100.', true)
|
||||
->param('background', '', function () { return new HexColor(); }, 'Preview image background color. Only works with transparent images (png). Use a valid HEX color, no # is needed for prefix.', true)
|
||||
->param('output', null, function () use ($outputs) { return new WhiteList(array_merge(array_keys($outputs), [null])); }, 'Output format type (jpeg, jpg, png, gif and webp).', true)
|
||||
->param('output', null, function () use ($outputs) { return new WhiteList(\array_merge(\array_keys($outputs), [null])); }, 'Output format type (jpeg, jpg, png, gif and webp).', true)
|
||||
//->param('storage', 'local', function () {return new WhiteList(array('local'));}, 'Selected storage device. defaults to local')
|
||||
//->param('token', '', function () {return new Text(128);}, 'Preview token', true)
|
||||
->action(
|
||||
function ($fileId, $width, $height, $quality, $background, $output) use ($request, $response, $projectDB, $project, $inputs, $outputs, $fileLogos) {
|
||||
$storage = 'local';
|
||||
|
||||
if (!extension_loaded('imagick')) {
|
||||
if (!\extension_loaded('imagick')) {
|
||||
throw new Exception('Imagick extension is missing', 500);
|
||||
}
|
||||
|
||||
|
@ -351,12 +351,12 @@ $utopia->get('/v1/storage/files/:fileId/preview')
|
|||
throw new Exception('No such storage device', 400);
|
||||
}
|
||||
|
||||
if ((strpos($request->getServer('HTTP_ACCEPT'), 'image/webp') === false) && ('webp' == $output)) { // Fallback webp to jpeg when no browser support
|
||||
if ((\strpos($request->getServer('HTTP_ACCEPT'), 'image/webp') === false) && ('webp' == $output)) { // Fallback webp to jpeg when no browser support
|
||||
$output = 'jpg';
|
||||
}
|
||||
|
||||
$date = date('D, d M Y H:i:s', time() + (60 * 60 * 24 * 45)).' GMT'; // 45 days cache
|
||||
$key = md5($fileId.$width.$height.$quality.$background.$storage.$output);
|
||||
$date = \date('D, d M Y H:i:s', \time() + (60 * 60 * 24 * 45)).' GMT'; // 45 days cache
|
||||
$key = \md5($fileId.$width.$height.$quality.$background.$storage.$output);
|
||||
|
||||
$file = $projectDB->getDocument($fileId);
|
||||
|
||||
|
@ -365,24 +365,24 @@ $utopia->get('/v1/storage/files/:fileId/preview')
|
|||
}
|
||||
|
||||
$path = $file->getAttribute('path');
|
||||
$type = strtolower(pathinfo($path, PATHINFO_EXTENSION));
|
||||
$type = \strtolower(\pathinfo($path, PATHINFO_EXTENSION));
|
||||
$algorithm = $file->getAttribute('algorithm');
|
||||
$cipher = $file->getAttribute('fileOpenSSLCipher');
|
||||
$mime = $file->getAttribute('mimeType');
|
||||
|
||||
if(!in_array($mime, $inputs)) {
|
||||
$path = (array_key_exists($mime, $fileLogos)) ? $fileLogos[$mime] : $fileLogos['default'];
|
||||
if(!\in_array($mime, $inputs)) {
|
||||
$path = (\array_key_exists($mime, $fileLogos)) ? $fileLogos[$mime] : $fileLogos['default'];
|
||||
$algorithm = null;
|
||||
$cipher = null;
|
||||
$background = (empty($background)) ? 'eceff1' : $background;
|
||||
$type = strtolower(pathinfo($path, PATHINFO_EXTENSION));
|
||||
$key = md5($path.$width.$height.$quality.$background.$storage.$output);
|
||||
$type = \strtolower(\pathinfo($path, PATHINFO_EXTENSION));
|
||||
$key = \md5($path.$width.$height.$quality.$background.$storage.$output);
|
||||
}
|
||||
|
||||
$compressor = new GZIP();
|
||||
$device = Storage::getDevice('local');
|
||||
|
||||
if (!file_exists($path)) {
|
||||
if (!\file_exists($path)) {
|
||||
throw new Exception('File not found', 404);
|
||||
}
|
||||
|
||||
|
@ -393,7 +393,7 @@ $utopia->get('/v1/storage/files/:fileId/preview')
|
|||
$output = (empty($output)) ? $type : $output;
|
||||
|
||||
$response
|
||||
->setContentType((in_array($output, $outputs)) ? $outputs[$output] : $outputs['jpg'])
|
||||
->setContentType((\in_array($output, $outputs)) ? $outputs[$output] : $outputs['jpg'])
|
||||
->addHeader('Expires', $date)
|
||||
->addHeader('X-Appwrite-Cache', 'hit')
|
||||
->send($data)
|
||||
|
@ -410,8 +410,8 @@ $utopia->get('/v1/storage/files/:fileId/preview')
|
|||
$file->getAttribute('fileOpenSSLCipher'),
|
||||
$request->getServer('_APP_OPENSSL_KEY_V'.$file->getAttribute('fileOpenSSLVersion')),
|
||||
0,
|
||||
hex2bin($file->getAttribute('fileOpenSSLIV')),
|
||||
hex2bin($file->getAttribute('fileOpenSSLTag'))
|
||||
\hex2bin($file->getAttribute('fileOpenSSLIV')),
|
||||
\hex2bin($file->getAttribute('fileOpenSSLTag'))
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -466,7 +466,7 @@ $utopia->get('/v1/storage/files/:fileId/download')
|
|||
|
||||
$path = $file->getAttribute('path', '');
|
||||
|
||||
if (!file_exists($path)) {
|
||||
if (!\file_exists($path)) {
|
||||
throw new Exception('File not found in '.$path, 404);
|
||||
}
|
||||
|
||||
|
@ -481,8 +481,8 @@ $utopia->get('/v1/storage/files/:fileId/download')
|
|||
$file->getAttribute('fileOpenSSLCipher'),
|
||||
$request->getServer('_APP_OPENSSL_KEY_V'.$file->getAttribute('fileOpenSSLVersion')),
|
||||
0,
|
||||
hex2bin($file->getAttribute('fileOpenSSLIV')),
|
||||
hex2bin($file->getAttribute('fileOpenSSLTag'))
|
||||
\hex2bin($file->getAttribute('fileOpenSSLIV')),
|
||||
\hex2bin($file->getAttribute('fileOpenSSLTag'))
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -492,8 +492,8 @@ $utopia->get('/v1/storage/files/:fileId/download')
|
|||
$response
|
||||
->setContentType($file->getAttribute('mimeType'))
|
||||
->addHeader('Content-Disposition', 'attachment; filename="'.$file->getAttribute('name', '').'"')
|
||||
->addHeader('Expires', date('D, d M Y H:i:s', time() + (60 * 60 * 24 * 45)).' GMT') // 45 days cache
|
||||
->addHeader('X-Peak', memory_get_peak_usage())
|
||||
->addHeader('Expires', \date('D, d M Y H:i:s', \time() + (60 * 60 * 24 * 45)).' GMT') // 45 days cache
|
||||
->addHeader('X-Peak', \memory_get_peak_usage())
|
||||
->send($source)
|
||||
;
|
||||
}
|
||||
|
@ -520,7 +520,7 @@ $utopia->get('/v1/storage/files/:fileId/view')
|
|||
|
||||
$path = $file->getAttribute('path', '');
|
||||
|
||||
if (!file_exists($path)) {
|
||||
if (!\file_exists($path)) {
|
||||
throw new Exception('File not found in '.$path, 404);
|
||||
}
|
||||
|
||||
|
@ -529,7 +529,7 @@ $utopia->get('/v1/storage/files/:fileId/view')
|
|||
|
||||
$contentType = 'text/plain';
|
||||
|
||||
if (in_array($file->getAttribute('mimeType'), $mimes)) {
|
||||
if (\in_array($file->getAttribute('mimeType'), $mimes)) {
|
||||
$contentType = $file->getAttribute('mimeType');
|
||||
}
|
||||
|
||||
|
@ -541,8 +541,8 @@ $utopia->get('/v1/storage/files/:fileId/view')
|
|||
$file->getAttribute('fileOpenSSLCipher'),
|
||||
$request->getServer('_APP_OPENSSL_KEY_V'.$file->getAttribute('fileOpenSSLVersion')),
|
||||
0,
|
||||
hex2bin($file->getAttribute('fileOpenSSLIV')),
|
||||
hex2bin($file->getAttribute('fileOpenSSLTag'))
|
||||
\hex2bin($file->getAttribute('fileOpenSSLIV')),
|
||||
\hex2bin($file->getAttribute('fileOpenSSLTag'))
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -554,7 +554,7 @@ $utopia->get('/v1/storage/files/:fileId/view')
|
|||
'text' => 'text/plain',
|
||||
];
|
||||
|
||||
$contentType = (array_key_exists($as, $contentTypes)) ? $contentTypes[$as] : $contentType;
|
||||
$contentType = (\array_key_exists($as, $contentTypes)) ? $contentTypes[$as] : $contentType;
|
||||
|
||||
// Response
|
||||
$response
|
||||
|
@ -562,8 +562,8 @@ $utopia->get('/v1/storage/files/:fileId/view')
|
|||
->addHeader('Content-Security-Policy', 'script-src none;')
|
||||
->addHeader('X-Content-Type-Options', 'nosniff')
|
||||
->addHeader('Content-Disposition', 'inline; filename="'.$fileName.'"')
|
||||
->addHeader('Expires', date('D, d M Y H:i:s', time() + (60 * 60 * 24 * 45)).' GMT') // 45 days cache
|
||||
->addHeader('X-Peak', memory_get_peak_usage())
|
||||
->addHeader('Expires', \date('D, d M Y H:i:s', \time() + (60 * 60 * 24 * 45)).' GMT') // 45 days cache
|
||||
->addHeader('X-Peak', \memory_get_peak_usage())
|
||||
->send($output)
|
||||
;
|
||||
}
|
||||
|
@ -589,7 +589,7 @@ $utopia->put('/v1/storage/files/:fileId')
|
|||
throw new Exception('File not found', 404);
|
||||
}
|
||||
|
||||
$file = $projectDB->updateDocument(array_merge($file->getArrayCopy(), [
|
||||
$file = $projectDB->updateDocument(\array_merge($file->getArrayCopy(), [
|
||||
'$permissions' => [
|
||||
'read' => $read,
|
||||
'write' => $write,
|
||||
|
|
|
@ -43,7 +43,7 @@ $utopia->post('/v1/teams')
|
|||
],
|
||||
'name' => $name,
|
||||
'sum' => ($mode !== APP_MODE_ADMIN && $user->getId()) ? 1 : 0,
|
||||
'dateCreated' => time(),
|
||||
'dateCreated' => \time(),
|
||||
]);
|
||||
|
||||
Authorization::reset();
|
||||
|
@ -62,8 +62,8 @@ $utopia->post('/v1/teams')
|
|||
'userId' => $user->getId(),
|
||||
'teamId' => $team->getId(),
|
||||
'roles' => $roles,
|
||||
'invited' => time(),
|
||||
'joined' => time(),
|
||||
'invited' => \time(),
|
||||
'joined' => \time(),
|
||||
'confirm' => true,
|
||||
'secret' => '',
|
||||
]);
|
||||
|
@ -151,7 +151,7 @@ $utopia->put('/v1/teams/:teamId')
|
|||
throw new Exception('Team not found', 404);
|
||||
}
|
||||
|
||||
$team = $projectDB->updateDocument(array_merge($team->getArrayCopy(), [
|
||||
$team = $projectDB->updateDocument(\array_merge($team->getArrayCopy(), [
|
||||
'name' => $name,
|
||||
]));
|
||||
|
||||
|
@ -256,8 +256,8 @@ $utopia->post('/v1/teams/:teamId/memberships')
|
|||
'emailVerification' => false,
|
||||
'status' => Auth::USER_STATUS_UNACTIVATED,
|
||||
'password' => Auth::passwordHash(Auth::passwordGenerator()),
|
||||
'password-update' => time(),
|
||||
'registration' => time(),
|
||||
'password-update' => \time(),
|
||||
'registration' => \time(),
|
||||
'reset' => false,
|
||||
'name' => $name,
|
||||
'tokens' => [],
|
||||
|
@ -280,7 +280,7 @@ $utopia->post('/v1/teams/:teamId/memberships')
|
|||
throw new Exception('User has already been invited or is already a member of this team', 409);
|
||||
}
|
||||
|
||||
if ($member->getAttribute('userId') == $user->getId() && in_array('owner', $member->getAttribute('roles', []))) {
|
||||
if ($member->getAttribute('userId') == $user->getId() && \in_array('owner', $member->getAttribute('roles', []))) {
|
||||
$isOwner = true;
|
||||
}
|
||||
}
|
||||
|
@ -300,7 +300,7 @@ $utopia->post('/v1/teams/:teamId/memberships')
|
|||
'userId' => $invitee->getId(),
|
||||
'teamId' => $team->getId(),
|
||||
'roles' => $roles,
|
||||
'invited' => time(),
|
||||
'invited' => \time(),
|
||||
'joined' => 0,
|
||||
'confirm' => (APP_MODE_ADMIN === $mode),
|
||||
'secret' => Auth::hash($secret),
|
||||
|
@ -349,7 +349,7 @@ $utopia->post('/v1/teams/:teamId/memberships')
|
|||
->setParam('event', 'teams.membership.create')
|
||||
->setParam('recipient', $email)
|
||||
->setParam('name', $name)
|
||||
->setParam('subject', sprintf(Locale::getText('account.emails.invitation.title'), $team->getAttribute('name', '[TEAM-NAME]'), $project->getAttribute('name', ['[APP-NAME]'])))
|
||||
->setParam('subject', \sprintf(Locale::getText('account.emails.invitation.title'), $team->getAttribute('name', '[TEAM-NAME]'), $project->getAttribute('name', ['[APP-NAME]'])))
|
||||
->setParam('body', $body->render())
|
||||
->trigger();
|
||||
;
|
||||
|
@ -363,7 +363,7 @@ $utopia->post('/v1/teams/:teamId/memberships')
|
|||
|
||||
$response
|
||||
->setStatusCode(Response::STATUS_CODE_CREATED) // TODO change response of this endpoint
|
||||
->json(array_merge($membership->getArrayCopy([
|
||||
->json(\array_merge($membership->getArrayCopy([
|
||||
'$id',
|
||||
'userId',
|
||||
'teamId',
|
||||
|
@ -421,7 +421,7 @@ $utopia->get('/v1/teams/:teamId/memberships')
|
|||
|
||||
$temp = $projectDB->getDocument($membership->getAttribute('userId', null))->getArrayCopy(['email', 'name']);
|
||||
|
||||
$users[] = array_merge($temp, $membership->getArrayCopy([
|
||||
$users[] = \array_merge($temp, $membership->getArrayCopy([
|
||||
'$id',
|
||||
'userId',
|
||||
'teamId',
|
||||
|
@ -495,7 +495,7 @@ $utopia->patch('/v1/teams/:teamId/memberships/:inviteId/status')
|
|||
}
|
||||
|
||||
$membership // Attach user to team
|
||||
->setAttribute('joined', time())
|
||||
->setAttribute('joined', \time())
|
||||
->setAttribute('confirm', true)
|
||||
;
|
||||
|
||||
|
@ -505,7 +505,7 @@ $utopia->patch('/v1/teams/:teamId/memberships/:inviteId/status')
|
|||
;
|
||||
|
||||
// Log user in
|
||||
$expiry = time() + Auth::TOKEN_EXPIRATION_LOGIN_LONG;
|
||||
$expiry = \time() + Auth::TOKEN_EXPIRATION_LOGIN_LONG;
|
||||
$secret = Auth::tokenGenerator();
|
||||
|
||||
$user->setAttribute('tokens', new Document([
|
||||
|
@ -528,7 +528,7 @@ $utopia->patch('/v1/teams/:teamId/memberships/:inviteId/status')
|
|||
|
||||
Authorization::disable();
|
||||
|
||||
$team = $projectDB->updateDocument(array_merge($team->getArrayCopy(), [
|
||||
$team = $projectDB->updateDocument(\array_merge($team->getArrayCopy(), [
|
||||
'sum' => $team->getAttribute('sum', 0) + 1,
|
||||
]));
|
||||
|
||||
|
@ -546,14 +546,14 @@ $utopia->patch('/v1/teams/:teamId/memberships/:inviteId/status')
|
|||
|
||||
if(!Config::getParam('domainVerification')) {
|
||||
$response
|
||||
->addHeader('X-Fallback-Cookies', json_encode([Auth::$cookieName => Auth::encodeSession($user->getId(), $secret)]))
|
||||
->addHeader('X-Fallback-Cookies', \json_encode([Auth::$cookieName => Auth::encodeSession($user->getId(), $secret)]))
|
||||
;
|
||||
}
|
||||
|
||||
$response
|
||||
->addCookie(Auth::$cookieName.'_legacy', Auth::encodeSession($user->getId(), $secret), $expiry, '/', COOKIE_DOMAIN, ('https' == $protocol), true, null)
|
||||
->addCookie(Auth::$cookieName, Auth::encodeSession($user->getId(), $secret), $expiry, '/', COOKIE_DOMAIN, ('https' == $protocol), true, COOKIE_SAMESITE)
|
||||
->json(array_merge($membership->getArrayCopy([
|
||||
->json(\array_merge($membership->getArrayCopy([
|
||||
'$id',
|
||||
'userId',
|
||||
'teamId',
|
||||
|
@ -601,7 +601,7 @@ $utopia->delete('/v1/teams/:teamId/memberships/:inviteId')
|
|||
}
|
||||
|
||||
if ($membership->getAttribute('confirm')) { // Count only confirmed members
|
||||
$team = $projectDB->updateDocument(array_merge($team->getArrayCopy(), [
|
||||
$team = $projectDB->updateDocument(\array_merge($team->getArrayCopy(), [
|
||||
'sum' => $team->getAttribute('sum', 0) - 1,
|
||||
]));
|
||||
}
|
||||
|
|
|
@ -59,8 +59,8 @@ $utopia->post('/v1/users')
|
|||
'emailVerification' => false,
|
||||
'status' => Auth::USER_STATUS_UNACTIVATED,
|
||||
'password' => Auth::passwordHash($password),
|
||||
'password-update' => time(),
|
||||
'registration' => time(),
|
||||
'password-update' => \time(),
|
||||
'registration' => \time(),
|
||||
'reset' => false,
|
||||
'name' => $name,
|
||||
], ['email' => $email]);
|
||||
|
@ -75,13 +75,13 @@ $utopia->post('/v1/users')
|
|||
continue;
|
||||
}
|
||||
|
||||
$oauth2Keys[] = 'oauth2'.ucfirst($key);
|
||||
$oauth2Keys[] = 'oauth2'.ucfirst($key).'AccessToken';
|
||||
$oauth2Keys[] = 'oauth2'.\ucfirst($key);
|
||||
$oauth2Keys[] = 'oauth2'.\ucfirst($key).'AccessToken';
|
||||
}
|
||||
|
||||
$response
|
||||
->setStatusCode(Response::STATUS_CODE_CREATED)
|
||||
->json(array_merge($user->getArrayCopy(array_merge([
|
||||
->json(\array_merge($user->getArrayCopy(\array_merge([
|
||||
'$id',
|
||||
'status',
|
||||
'email',
|
||||
|
@ -124,12 +124,12 @@ $utopia->get('/v1/users')
|
|||
continue;
|
||||
}
|
||||
|
||||
$oauth2Keys[] = 'oauth2'.ucfirst($key);
|
||||
$oauth2Keys[] = 'oauth2'.ucfirst($key).'AccessToken';
|
||||
$oauth2Keys[] = 'oauth2'.\ucfirst($key);
|
||||
$oauth2Keys[] = 'oauth2'.\ucfirst($key).'AccessToken';
|
||||
}
|
||||
|
||||
$results = array_map(function ($value) use ($oauth2Keys) { /* @var $value \Database\Document */
|
||||
return $value->getArrayCopy(array_merge(
|
||||
$results = \array_map(function ($value) use ($oauth2Keys) { /* @var $value \Database\Document */
|
||||
return $value->getArrayCopy(\array_merge(
|
||||
[
|
||||
'$id',
|
||||
'status',
|
||||
|
@ -169,11 +169,11 @@ $utopia->get('/v1/users/:userId')
|
|||
continue;
|
||||
}
|
||||
|
||||
$oauth2Keys[] = 'oauth2'.ucfirst($key);
|
||||
$oauth2Keys[] = 'oauth2'.ucfirst($key).'AccessToken';
|
||||
$oauth2Keys[] = 'oauth2'.\ucfirst($key);
|
||||
$oauth2Keys[] = 'oauth2'.\ucfirst($key).'AccessToken';
|
||||
}
|
||||
|
||||
$response->json(array_merge($user->getArrayCopy(array_merge(
|
||||
$response->json(\array_merge($user->getArrayCopy(\array_merge(
|
||||
[
|
||||
'$id',
|
||||
'status',
|
||||
|
@ -206,7 +206,7 @@ $utopia->get('/v1/users/:userId/prefs')
|
|||
$prefs = $user->getAttribute('prefs', '');
|
||||
|
||||
try {
|
||||
$prefs = json_decode($prefs, true);
|
||||
$prefs = \json_decode($prefs, true);
|
||||
$prefs = ($prefs) ? $prefs : [];
|
||||
} catch (\Exception $error) {
|
||||
throw new Exception('Failed to parse prefs', 500);
|
||||
|
@ -265,7 +265,7 @@ $utopia->get('/v1/users/:userId/sessions')
|
|||
|
||||
try {
|
||||
$record = $reader->country($token->getAttribute('ip', ''));
|
||||
$sessions[$index]['geo']['isoCode'] = strtolower($record->country->isoCode);
|
||||
$sessions[$index]['geo']['isoCode'] = \strtolower($record->country->isoCode);
|
||||
$sessions[$index]['geo']['country'] = (isset($countries[$record->country->isoCode])) ? $countries[$record->country->isoCode] : Locale::getText('locale.country.unknown');
|
||||
} catch (\Exception $e) {
|
||||
$sessions[$index]['geo']['isoCode'] = '--';
|
||||
|
@ -335,7 +335,7 @@ $utopia->get('/v1/users/:userId/logs')
|
|||
$output[$i] = [
|
||||
'event' => $log['event'],
|
||||
'ip' => $log['ip'],
|
||||
'time' => strtotime($log['time']),
|
||||
'time' => \strtotime($log['time']),
|
||||
'OS' => $dd->getOs(),
|
||||
'client' => $dd->getClient(),
|
||||
'device' => $dd->getDevice(),
|
||||
|
@ -346,7 +346,7 @@ $utopia->get('/v1/users/:userId/logs')
|
|||
|
||||
try {
|
||||
$record = $reader->country($log['ip']);
|
||||
$output[$i]['geo']['isoCode'] = strtolower($record->country->isoCode);
|
||||
$output[$i]['geo']['isoCode'] = \strtolower($record->country->isoCode);
|
||||
$output[$i]['geo']['country'] = $record->country->name;
|
||||
$output[$i]['geo']['country'] = (isset($countries[$record->country->isoCode])) ? $countries[$record->country->isoCode] : Locale::getText('locale.country.unknown');
|
||||
} catch (\Exception $e) {
|
||||
|
@ -376,7 +376,7 @@ $utopia->patch('/v1/users/:userId/status')
|
|||
throw new Exception('User not found', 404);
|
||||
}
|
||||
|
||||
$user = $projectDB->updateDocument(array_merge($user->getArrayCopy(), [
|
||||
$user = $projectDB->updateDocument(\array_merge($user->getArrayCopy(), [
|
||||
'status' => (int)$status,
|
||||
]));
|
||||
|
||||
|
@ -391,12 +391,12 @@ $utopia->patch('/v1/users/:userId/status')
|
|||
continue;
|
||||
}
|
||||
|
||||
$oauth2Keys[] = 'oauth2'.ucfirst($key);
|
||||
$oauth2Keys[] = 'oauth2'.ucfirst($key).'AccessToken';
|
||||
$oauth2Keys[] = 'oauth2'.\ucfirst($key);
|
||||
$oauth2Keys[] = 'oauth2'.\ucfirst($key).'AccessToken';
|
||||
}
|
||||
|
||||
$response
|
||||
->json(array_merge($user->getArrayCopy(array_merge([
|
||||
->json(\array_merge($user->getArrayCopy(\array_merge([
|
||||
'$id',
|
||||
'status',
|
||||
'email',
|
||||
|
@ -424,11 +424,11 @@ $utopia->patch('/v1/users/:userId/prefs')
|
|||
throw new Exception('User not found', 404);
|
||||
}
|
||||
|
||||
$old = json_decode($user->getAttribute('prefs', '{}'), true);
|
||||
$old = \json_decode($user->getAttribute('prefs', '{}'), true);
|
||||
$old = ($old) ? $old : [];
|
||||
|
||||
$user = $projectDB->updateDocument(array_merge($user->getArrayCopy(), [
|
||||
'prefs' => json_encode(array_merge($old, $prefs)),
|
||||
$user = $projectDB->updateDocument(\array_merge($user->getArrayCopy(), [
|
||||
'prefs' => \json_encode(\array_merge($old, $prefs)),
|
||||
]));
|
||||
|
||||
if (false === $user) {
|
||||
|
@ -438,7 +438,7 @@ $utopia->patch('/v1/users/:userId/prefs')
|
|||
$prefs = $user->getAttribute('prefs', '');
|
||||
|
||||
try {
|
||||
$prefs = json_decode($prefs, true);
|
||||
$prefs = \json_decode($prefs, true);
|
||||
$prefs = ($prefs) ? $prefs : [];
|
||||
} catch (\Exception $error) {
|
||||
throw new Exception('Failed to parse prefs', 500);
|
||||
|
|
|
@ -175,9 +175,9 @@ $utopia->post('/v1/mock/tests/general/upload')
|
|||
->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']];
|
||||
$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') {
|
||||
|
@ -192,7 +192,7 @@ $utopia->post('/v1/mock/tests/general/upload')
|
|||
}
|
||||
|
||||
foreach ($file['tmp_name'] as $i => $tmpName) {
|
||||
if(md5(file_get_contents($tmpName)) !== 'd80e7e6999a3eb2ae0d631a96fe135a4') {
|
||||
if(\md5(\file_get_contents($tmpName)) !== 'd80e7e6999a3eb2ae0d631a96fe135a4') {
|
||||
throw new Exception('Wrong file uploaded', 400);
|
||||
}
|
||||
}
|
||||
|
@ -230,7 +230,7 @@ $utopia->get('/v1/mock/tests/general/set-cookie')
|
|||
->label('sdk.description', 'Mock a set cookie request for SDK tests')
|
||||
->action(
|
||||
function () use ($response) {
|
||||
$response->addCookie('cookieName', 'cookieValue', time() + 31536000, '/', 'localhost', true, true);
|
||||
$response->addCookie('cookieName', 'cookieValue', \time() + 31536000, '/', 'localhost', true, true);
|
||||
}
|
||||
);
|
||||
|
||||
|
@ -271,7 +271,7 @@ $utopia->get('/v1/mock/tests/general/oauth2')
|
|||
->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]));
|
||||
$response->redirect($redirectURI.'?'.\http_build_query(['code' => 'abcdef', 'state' => $state]));
|
||||
}
|
||||
);
|
||||
|
||||
|
@ -348,17 +348,17 @@ $utopia->shutdown(function() use ($response, $request, &$result, $utopia) {
|
|||
|
||||
$route = $utopia->match($request);
|
||||
$path = APP_STORAGE_CACHE.'/tests.json';
|
||||
$tests = (file_exists($path)) ? json_decode(file_get_contents($path), true) : [];
|
||||
$tests = (\file_exists($path)) ? \json_decode(\file_get_contents($path), true) : [];
|
||||
|
||||
if(!is_array($tests)) {
|
||||
if(!\is_array($tests)) {
|
||||
throw new Exception('Failed to read results', 500);
|
||||
}
|
||||
|
||||
$result[$route->getMethod() . ':' . $route->getURL()] = true;
|
||||
|
||||
$tests = array_merge($tests, $result);
|
||||
$tests = \array_merge($tests, $result);
|
||||
|
||||
if(!file_put_contents($path, json_encode($tests), LOCK_EX)) {
|
||||
if(!\file_put_contents($path, \json_encode($tests), LOCK_EX)) {
|
||||
throw new Exception('Failed to save resutls', 500);
|
||||
}
|
||||
|
||||
|
|
|
@ -31,7 +31,7 @@ $utopia->init(function () use ($utopia, $request, $response, $register, $user, $
|
|||
//TODO make sure we get array here
|
||||
|
||||
foreach ($request->getParams() as $key => $value) { // Set request params as potential abuse keys
|
||||
$timeLimit->setParam('{param-'.$key.'}', (is_array($value)) ? json_encode($value) : $value);
|
||||
$timeLimit->setParam('{param-'.$key.'}', (\is_array($value)) ? \json_encode($value) : $value);
|
||||
}
|
||||
|
||||
$abuse = new Abuse($timeLimit);
|
||||
|
|
|
@ -37,7 +37,7 @@ $utopia->init(function () use ($utopia, $response, $request, $layout) {
|
|||
|
||||
$response
|
||||
->addHeader('Cache-Control', 'public, max-age='.$time)
|
||||
->addHeader('Expires', date('D, d M Y H:i:s', time() + $time).' GMT') // 45 days cache
|
||||
->addHeader('Expires', \date('D, d M Y H:i:s', \time() + $time).' GMT') // 45 days cache
|
||||
->addHeader('X-UA-Compatible', 'IE=Edge'); // Deny IE browsers from going into quirks mode
|
||||
|
||||
$route = $utopia->match($request);
|
||||
|
|
|
@ -168,18 +168,18 @@ $utopia->get('/open-api-2.json')
|
|||
function ($platform, $extensions, $tests) use ($response, $request, $utopia, $services) {
|
||||
function fromCamelCase($input)
|
||||
{
|
||||
preg_match_all('!([A-Z][A-Z0-9]*(?=$|[A-Z][a-z0-9])|[A-Za-z][a-z0-9]+)!', $input, $matches);
|
||||
\preg_match_all('!([A-Z][A-Z0-9]*(?=$|[A-Z][a-z0-9])|[A-Za-z][a-z0-9]+)!', $input, $matches);
|
||||
$ret = $matches[0];
|
||||
foreach ($ret as &$match) {
|
||||
$match = $match == strtoupper($match) ? strtolower($match) : lcfirst($match);
|
||||
$match = $match == \strtoupper($match) ? \strtolower($match) : \lcfirst($match);
|
||||
}
|
||||
|
||||
return implode('_', $ret);
|
||||
return \implode('_', $ret);
|
||||
}
|
||||
|
||||
function fromCamelCaseToDash($input)
|
||||
{
|
||||
return str_replace([' ', '_'], '-', strtolower(preg_replace('/([a-zA-Z])(?=[A-Z])/', '$1-', $input)));
|
||||
return \str_replace([' ', '_'], '-', \strtolower(\preg_replace('/([a-zA-Z])(?=[A-Z])/', '$1-', $input)));
|
||||
}
|
||||
|
||||
foreach ($services as $service) { /* @noinspection PhpIncludeInspection */
|
||||
|
@ -196,7 +196,7 @@ $utopia->get('/open-api-2.json')
|
|||
}
|
||||
|
||||
/** @noinspection PhpIncludeInspection */
|
||||
include_once realpath(__DIR__.'/../../'.$service['controller']);
|
||||
include_once \realpath(__DIR__.'/../../'.$service['controller']);
|
||||
}
|
||||
|
||||
$security = [
|
||||
|
@ -295,7 +295,7 @@ $utopia->get('/open-api-2.json')
|
|||
'url' => 'https://raw.githubusercontent.com/appwrite/appwrite/master/LICENSE',
|
||||
],
|
||||
],
|
||||
'host' => parse_url($request->getServer('_APP_HOME', Config::getParam('domain')), PHP_URL_HOST),
|
||||
'host' => \parse_url($request->getServer('_APP_HOME', Config::getParam('domain')), PHP_URL_HOST),
|
||||
'basePath' => '/v1',
|
||||
'schemes' => ['https'],
|
||||
'consumes' => ['application/json', 'multipart/form-data'],
|
||||
|
@ -374,11 +374,11 @@ $utopia->get('/open-api-2.json')
|
|||
continue;
|
||||
}
|
||||
|
||||
if($platform !== APP_PLATFORM_CONSOLE && !in_array($platforms[$platform], $route->getLabel('sdk.platform', []))) {
|
||||
if($platform !== APP_PLATFORM_CONSOLE && !\in_array($platforms[$platform], $route->getLabel('sdk.platform', []))) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$url = str_replace('/v1', '', $route->getURL());
|
||||
$url = \str_replace('/v1', '', $route->getURL());
|
||||
$scope = $route->getLabel('scope', '');
|
||||
$hide = $route->getLabel('sdk.hide', false);
|
||||
$consumes = ['application/json'];
|
||||
|
@ -387,14 +387,14 @@ $utopia->get('/open-api-2.json')
|
|||
continue;
|
||||
}
|
||||
|
||||
$desc = (!empty($route->getLabel('sdk.description', ''))) ? realpath('../'.$route->getLabel('sdk.description', '')) : null;
|
||||
$desc = (!empty($route->getLabel('sdk.description', ''))) ? \realpath('../'.$route->getLabel('sdk.description', '')) : null;
|
||||
|
||||
$temp = [
|
||||
'summary' => $route->getDesc(),
|
||||
'operationId' => $route->getLabel('sdk.method', uniqid()),
|
||||
'operationId' => $route->getLabel('sdk.method', \uniqid()),
|
||||
'consumes' => [],
|
||||
'tags' => [$route->getLabel('sdk.namespace', 'default')],
|
||||
'description' => ($desc) ? file_get_contents($desc) : '',
|
||||
'description' => ($desc) ? \file_get_contents($desc) : '',
|
||||
|
||||
// 'responses' => [
|
||||
// 200 => [
|
||||
|
@ -440,7 +440,7 @@ $utopia->get('/open-api-2.json')
|
|||
];
|
||||
|
||||
foreach ($route->getParams() as $name => $param) {
|
||||
$validator = (is_callable($param['validator'])) ? $param['validator']() : $param['validator']; /* @var $validator \Utopia\Validator */
|
||||
$validator = (\is_callable($param['validator'])) ? $param['validator']() : $param['validator']; /* @var $validator \Utopia\Validator */
|
||||
|
||||
$node = [
|
||||
'name' => $name,
|
||||
|
@ -448,14 +448,14 @@ $utopia->get('/open-api-2.json')
|
|||
'required' => !$param['optional'],
|
||||
];
|
||||
|
||||
switch ((!empty($validator)) ? get_class($validator) : '') {
|
||||
switch ((!empty($validator)) ? \get_class($validator) : '') {
|
||||
case 'Utopia\Validator\Text':
|
||||
$node['type'] = 'string';
|
||||
$node['x-example'] = '['.strtoupper(fromCamelCase($node['name'])).']';
|
||||
$node['x-example'] = '['.\strtoupper(fromCamelCase($node['name'])).']';
|
||||
break;
|
||||
case 'Appwrite\Database\Validator\UID':
|
||||
$node['type'] = 'string';
|
||||
$node['x-example'] = '['.strtoupper(fromCamelCase($node['name'])).']';
|
||||
$node['x-example'] = '['.\strtoupper(fromCamelCase($node['name'])).']';
|
||||
break;
|
||||
case 'Utopia\Validator\Email':
|
||||
$node['type'] = 'string';
|
||||
|
@ -517,11 +517,11 @@ $utopia->get('/open-api-2.json')
|
|||
break;
|
||||
}
|
||||
|
||||
if ($param['optional'] && !is_null($param['default'])) { // Param has default value
|
||||
if ($param['optional'] && !\is_null($param['default'])) { // Param has default value
|
||||
$node['default'] = $param['default'];
|
||||
}
|
||||
|
||||
if (false !== strpos($url, ':'.$name)) { // Param is in URL path
|
||||
if (false !== \strpos($url, ':'.$name)) { // Param is in URL path
|
||||
$node['in'] = 'path';
|
||||
$temp['parameters'][] = $node;
|
||||
} elseif ($key == 'GET') { // Param is in query
|
||||
|
@ -537,12 +537,12 @@ $utopia->get('/open-api-2.json')
|
|||
}
|
||||
}
|
||||
|
||||
$url = str_replace(':'.$name, '{'.$name.'}', $url);
|
||||
$url = \str_replace(':'.$name, '{'.$name.'}', $url);
|
||||
}
|
||||
|
||||
$temp['consumes'] = $consumes;
|
||||
|
||||
$output['paths'][$url][strtolower($route->getMethod())] = $temp;
|
||||
$output['paths'][$url][\strtolower($route->getMethod())] = $temp;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -550,7 +550,7 @@ $utopia->get('/open-api-2.json')
|
|||
var_dump($mock['name']);
|
||||
}*/
|
||||
|
||||
ksort($output['paths']);
|
||||
\ksort($output['paths']);
|
||||
|
||||
$response
|
||||
->json($output);
|
||||
|
|
26
app/init.php
26
app/init.php
|
@ -7,7 +7,7 @@
|
|||
* Set configuration, framework resources, app constants
|
||||
*
|
||||
*/
|
||||
if (file_exists(__DIR__.'/../vendor/autoload.php')) {
|
||||
if (\file_exists(__DIR__.'/../vendor/autoload.php')) {
|
||||
require_once __DIR__.'/../vendor/autoload.php';
|
||||
}
|
||||
|
||||
|
@ -68,22 +68,22 @@ Config::setParam('domain', $request->getServer('HTTP_HOST', ''));
|
|||
Config::setParam('domainVerification', false);
|
||||
Config::setParam('version', $request->getServer('_APP_VERSION', 'UNKNOWN'));
|
||||
Config::setParam('protocol', $request->getServer('HTTP_X_FORWARDED_PROTO', $request->getServer('REQUEST_SCHEME', 'https')));
|
||||
Config::setParam('port', (string) parse_url(Config::getParam('protocol').'://'.$request->getServer('HTTP_HOST', ''), PHP_URL_PORT));
|
||||
Config::setParam('hostname', parse_url(Config::getParam('protocol').'://'.$request->getServer('HTTP_HOST', null), PHP_URL_HOST));
|
||||
Config::setParam('port', (string) \parse_url(Config::getParam('protocol').'://'.$request->getServer('HTTP_HOST', ''), PHP_URL_PORT));
|
||||
Config::setParam('hostname', \parse_url(Config::getParam('protocol').'://'.$request->getServer('HTTP_HOST', null), PHP_URL_HOST));
|
||||
|
||||
Resque::setBackend($request->getServer('_APP_REDIS_HOST', '')
|
||||
.':'.$request->getServer('_APP_REDIS_PORT', ''));
|
||||
|
||||
define('COOKIE_DOMAIN',
|
||||
\define('COOKIE_DOMAIN',
|
||||
(
|
||||
$request->getServer('HTTP_HOST', null) === 'localhost' ||
|
||||
$request->getServer('HTTP_HOST', null) === 'localhost:'.Config::getParam('port') ||
|
||||
(filter_var(Config::getParam('hostname'), FILTER_VALIDATE_IP) !== false)
|
||||
(\filter_var(Config::getParam('hostname'), FILTER_VALIDATE_IP) !== false)
|
||||
)
|
||||
? null
|
||||
: '.'.Config::getParam('hostname')
|
||||
);
|
||||
define('COOKIE_SAMESITE', Response::COOKIE_SAMESITE_NONE);
|
||||
\define('COOKIE_SAMESITE', Response::COOKIE_SAMESITE_NONE);
|
||||
|
||||
/*
|
||||
* Registry
|
||||
|
@ -152,7 +152,7 @@ $register->set('smtp', function () use ($request) {
|
|||
$mail->SMTPAutoTLS = false;
|
||||
$mail->CharSet = 'UTF-8';
|
||||
|
||||
$from = urldecode($request->getServer('_APP_SYSTEM_EMAIL_NAME', APP_NAME.' Server'));
|
||||
$from = \urldecode($request->getServer('_APP_SYSTEM_EMAIL_NAME', APP_NAME.' Server'));
|
||||
$email = $request->getServer('_APP_SYSTEM_EMAIL_ADDRESS', APP_EMAIL_TEAM);
|
||||
|
||||
$mail->setFrom($email, $from);
|
||||
|
@ -219,14 +219,14 @@ Locale::setLanguage('zh-tw', include __DIR__.'/config/locales/zh-tw.php');
|
|||
|
||||
Locale::setDefault('en');
|
||||
|
||||
if (in_array($locale, Config::getParam('locales'))) {
|
||||
if (\in_array($locale, Config::getParam('locales'))) {
|
||||
Locale::setDefault($locale);
|
||||
}
|
||||
|
||||
stream_context_set_default([ // Set global user agent and http settings
|
||||
\stream_context_set_default([ // Set global user agent and http settings
|
||||
'http' => [
|
||||
'method' => 'GET',
|
||||
'user_agent' => sprintf(APP_USERAGENT,
|
||||
'user_agent' => \sprintf(APP_USERAGENT,
|
||||
Config::getParam('version'),
|
||||
$request->getServer('_APP_SYSTEM_SECURITY_EMAIL_ADDRESS', APP_EMAIL_SECURITY)),
|
||||
'timeout' => 2,
|
||||
|
@ -268,7 +268,7 @@ $response->addHeader('X-Debug-Fallback', 'false');
|
|||
if(empty($session['id']) && empty($session['secret'])) {
|
||||
$response->addHeader('X-Debug-Fallback', 'true');
|
||||
$fallback = $request->getHeader('X-Fallback-Cookies', '');
|
||||
$fallback = json_decode($fallback, true);
|
||||
$fallback = \json_decode($fallback, true);
|
||||
$session = Auth::decodeSession(((isset($fallback[Auth::$cookieName])) ? $fallback[Auth::$cookieName] : ''));
|
||||
}
|
||||
|
||||
|
@ -310,7 +310,7 @@ $register->get('smtp')
|
|||
->setFrom(
|
||||
$request->getServer('_APP_SYSTEM_EMAIL_ADDRESS', APP_EMAIL_TEAM),
|
||||
($project->getId() === 'console')
|
||||
? urldecode($request->getServer('_APP_SYSTEM_EMAIL_NAME', APP_NAME.' Server'))
|
||||
: sprintf(Locale::getText('account.emails.team'), $project->getAttribute('name')
|
||||
? \urldecode($request->getServer('_APP_SYSTEM_EMAIL_NAME', APP_NAME.' Server'))
|
||||
: \sprintf(Locale::getText('account.emails.team'), $project->getAttribute('name')
|
||||
)
|
||||
);
|
||||
|
|
|
@ -22,7 +22,7 @@ $cli
|
|||
|
||||
Console::log('Issue a TLS certificate for master domain ('.$domain.')');
|
||||
|
||||
ResqueScheduler::enqueueAt(time() + 30, 'v1-certificates', 'CertificatesV1', [
|
||||
ResqueScheduler::enqueueAt(\time() + 30, 'v1-certificates', 'CertificatesV1', [
|
||||
'document' => [],
|
||||
'domain' => $domain,
|
||||
'validateTarget' => false,
|
||||
|
@ -103,7 +103,7 @@ $cli
|
|||
Console::log('🟢 HTTP force option is enabled');
|
||||
}
|
||||
|
||||
sleep(0.2);
|
||||
\sleep(0.2);
|
||||
|
||||
try {
|
||||
Console::log("\n".'Checking connectivity...');
|
||||
|
@ -164,9 +164,9 @@ $cli
|
|||
$host = $request->getServer('_APP_STATSD_HOST', 'telegraf');
|
||||
$port = $request->getServer('_APP_STATSD_PORT', 8125);
|
||||
|
||||
if($fp = @fsockopen('udp://'.$host, $port, $errCode, $errStr, 2)){
|
||||
if($fp = @\fsockopen('udp://'.$host, $port, $errCode, $errStr, 2)){
|
||||
Console::success('StatsD..............connected 👍');
|
||||
fclose($fp);
|
||||
\fclose($fp);
|
||||
} else {
|
||||
Console::error('StatsD...........disconnected 👎');
|
||||
}
|
||||
|
@ -174,14 +174,14 @@ $cli
|
|||
$host = $request->getServer('_APP_INFLUXDB_HOST', '');
|
||||
$port = $request->getServer('_APP_INFLUXDB_PORT', '');
|
||||
|
||||
if($fp = @fsockopen($host, $port, $errCode, $errStr, 2)){
|
||||
if($fp = @\fsockopen($host, $port, $errCode, $errStr, 2)){
|
||||
Console::success('InfluxDB............connected 👍');
|
||||
fclose($fp);
|
||||
\fclose($fp);
|
||||
} else {
|
||||
Console::error('InfluxDB.........disconnected 👎');
|
||||
}
|
||||
|
||||
sleep(0.2);
|
||||
\sleep(0.2);
|
||||
|
||||
Console::log('');
|
||||
Console::log('Checking volumes...');
|
||||
|
@ -194,14 +194,14 @@ $cli
|
|||
] as $key => $volume) {
|
||||
$device = new Local($volume);
|
||||
|
||||
if (is_readable($device->getRoot())) {
|
||||
if (\is_readable($device->getRoot())) {
|
||||
Console::success('🟢 '.$key.' Volume is readable');
|
||||
}
|
||||
else {
|
||||
Console::error('🔴 '.$key.' Volume is unreadable');
|
||||
}
|
||||
|
||||
if (is_writable($device->getRoot())) {
|
||||
if (\is_writable($device->getRoot())) {
|
||||
Console::success('🟢 '.$key.' Volume is writeable');
|
||||
}
|
||||
else {
|
||||
|
@ -209,7 +209,7 @@ $cli
|
|||
}
|
||||
}
|
||||
|
||||
sleep(0.2);
|
||||
\sleep(0.2);
|
||||
|
||||
Console::log('');
|
||||
Console::log('Checking disk space usage...');
|
||||
|
@ -225,7 +225,7 @@ $cli
|
|||
$percentage = (($device->getPartitionTotalSpace() - $device->getPartitionFreeSpace())
|
||||
/ $device->getPartitionTotalSpace()) * 100;
|
||||
|
||||
$message = $key.' Volume has '.Storage::human($device->getPartitionFreeSpace()) . ' free space ('.round($percentage, 2).'% used)';
|
||||
$message = $key.' Volume has '.Storage::human($device->getPartitionFreeSpace()) . ' free space ('.\round($percentage, 2).'% used)';
|
||||
|
||||
if ($percentage < 80) {
|
||||
Console::success('🟢 ' . $message);
|
||||
|
@ -238,10 +238,10 @@ $cli
|
|||
|
||||
try {
|
||||
Console::log('');
|
||||
$version = json_decode(@file_get_contents($request->getServer('_APP_HOME', 'http://localhost').'/v1/health/version'), true);
|
||||
$version = \json_decode(@\file_get_contents($request->getServer('_APP_HOME', 'http://localhost').'/v1/health/version'), true);
|
||||
|
||||
if($version && isset($version['version'])) {
|
||||
if(version_compare($version['version'], $request->getServer('_APP_VERSION', 'UNKNOWN')) === 0) {
|
||||
if(\version_compare($version['version'], $request->getServer('_APP_VERSION', 'UNKNOWN')) === 0) {
|
||||
Console::info('You are running the latest version of '.APP_NAME.'! 🥳');
|
||||
}
|
||||
else {
|
||||
|
|
|
@ -38,7 +38,7 @@ $callbacks = [
|
|||
'orderCast' => 'string',
|
||||
]);
|
||||
|
||||
$sum = count($all);
|
||||
$sum = \count($all);
|
||||
|
||||
Console::log('Migrating: '.$offset.' / '.$projectDB->getSum());
|
||||
|
||||
|
@ -97,17 +97,17 @@ function fixDocument(Document $document) {
|
|||
|
||||
if($document->getAttribute('$collection') === Database::SYSTEM_COLLECTION_PROJECTS){
|
||||
foreach($providers as $key => $provider) {
|
||||
if(!empty($document->getAttribute('usersOauth'.ucfirst($key).'Appid'))) {
|
||||
if(!empty($document->getAttribute('usersOauth'.\ucfirst($key).'Appid'))) {
|
||||
$document
|
||||
->setAttribute('usersOauth2'.ucfirst($key).'Appid', $document->getAttribute('usersOauth'.ucfirst($key).'Appid', ''))
|
||||
->removeAttribute('usersOauth'.ucfirst($key).'Appid')
|
||||
->setAttribute('usersOauth2'.\ucfirst($key).'Appid', $document->getAttribute('usersOauth'.\ucfirst($key).'Appid', ''))
|
||||
->removeAttribute('usersOauth'.\ucfirst($key).'Appid')
|
||||
;
|
||||
}
|
||||
|
||||
if(!empty($document->getAttribute('usersOauth'.ucfirst($key).'Secret'))) {
|
||||
if(!empty($document->getAttribute('usersOauth'.\ucfirst($key).'Secret'))) {
|
||||
$document
|
||||
->setAttribute('usersOauth2'.ucfirst($key).'Secret', $document->getAttribute('usersOauth'.ucfirst($key).'Secret', ''))
|
||||
->removeAttribute('usersOauth'.ucfirst($key).'Secret')
|
||||
->setAttribute('usersOauth2'.\ucfirst($key).'Secret', $document->getAttribute('usersOauth'.\ucfirst($key).'Secret', ''))
|
||||
->removeAttribute('usersOauth'.\ucfirst($key).'Secret')
|
||||
;
|
||||
}
|
||||
}
|
||||
|
@ -115,17 +115,17 @@ function fixDocument(Document $document) {
|
|||
|
||||
if($document->getAttribute('$collection') === Database::SYSTEM_COLLECTION_USERS) {
|
||||
foreach($providers as $key => $provider) {
|
||||
if(!empty($document->getAttribute('oauth'.ucfirst($key)))) {
|
||||
if(!empty($document->getAttribute('oauth'.\ucfirst($key)))) {
|
||||
$document
|
||||
->setAttribute('oauth2'.ucfirst($key), $document->getAttribute('oauth'.ucfirst($key), ''))
|
||||
->removeAttribute('oauth'.ucfirst($key))
|
||||
->setAttribute('oauth2'.\ucfirst($key), $document->getAttribute('oauth'.\ucfirst($key), ''))
|
||||
->removeAttribute('oauth'.\ucfirst($key))
|
||||
;
|
||||
}
|
||||
|
||||
if(!empty($document->getAttribute('oauth'.ucfirst($key).'AccessToken'))) {
|
||||
if(!empty($document->getAttribute('oauth'.\ucfirst($key).'AccessToken'))) {
|
||||
$document
|
||||
->setAttribute('oauth2'.ucfirst($key).'AccessToken', $document->getAttribute('oauth'.ucfirst($key).'AccessToken', ''))
|
||||
->removeAttribute('oauth'.ucfirst($key).'AccessToken')
|
||||
->setAttribute('oauth2'.\ucfirst($key).'AccessToken', $document->getAttribute('oauth'.\ucfirst($key).'AccessToken', ''))
|
||||
->removeAttribute('oauth'.\ucfirst($key).'AccessToken')
|
||||
;
|
||||
}
|
||||
}
|
||||
|
@ -141,7 +141,7 @@ function fixDocument(Document $document) {
|
|||
if($document->getAttribute('$collection') === Database::SYSTEM_COLLECTION_PLATFORMS) {
|
||||
if($document->getAttribute('url', null) !== null) {
|
||||
$document
|
||||
->setAttribute('hostname', parse_url($document->getAttribute('url', $document->getAttribute('hostname', '')), PHP_URL_HOST))
|
||||
->setAttribute('hostname', \parse_url($document->getAttribute('url', $document->getAttribute('hostname', '')), PHP_URL_HOST))
|
||||
->removeAttribute('url')
|
||||
;
|
||||
}
|
||||
|
@ -159,7 +159,7 @@ function fixDocument(Document $document) {
|
|||
$attr = fixDocument($attr);
|
||||
}
|
||||
|
||||
if(is_array($attr)) {
|
||||
if(\is_array($attr)) {
|
||||
foreach($attr as &$child) {
|
||||
if($child instanceof Document) {
|
||||
$child = fixDocument($child);
|
||||
|
@ -207,7 +207,7 @@ $cli
|
|||
],
|
||||
]);
|
||||
|
||||
$sum = count($projects);
|
||||
$sum = \count($projects);
|
||||
$offset = $offset + $limit;
|
||||
|
||||
Console::log('Fetched '.$sum.' projects...');
|
||||
|
|
|
@ -29,20 +29,20 @@ $cli
|
|||
->action(function () use ($warning, $version) {
|
||||
function getSSLPage($url)
|
||||
{
|
||||
$ch = curl_init();
|
||||
curl_setopt($ch, CURLOPT_HEADER, false);
|
||||
curl_setopt($ch, CURLOPT_URL, $url);
|
||||
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
|
||||
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
$result = curl_exec($ch);
|
||||
curl_close($ch);
|
||||
$ch = \curl_init();
|
||||
\curl_setopt($ch, CURLOPT_HEADER, false);
|
||||
\curl_setopt($ch, CURLOPT_URL, $url);
|
||||
\curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
|
||||
\curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
|
||||
\curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
$result = \curl_exec($ch);
|
||||
\curl_close($ch);
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
$platforms = Config::getParam('platforms');
|
||||
$selected = strtolower(Console::confirm('Choose SDK ("*" for all):'));
|
||||
$selected = \strtolower(Console::confirm('Choose SDK ("*" for all):'));
|
||||
$message = Console::confirm('Please enter your commit message:');
|
||||
$production = (Console::confirm('Type "Appwrite" to deploy for production') == 'Appwrite');
|
||||
|
||||
|
@ -63,14 +63,14 @@ $cli
|
|||
$spec = getSSLPage('https://appwrite.io/v1/open-api-2.json?extensions=1&platform='.$language['family']);
|
||||
$spec = getSSLPage('https://localhost/v1/open-api-2.json?extensions=1&platform='.$language['family']);
|
||||
|
||||
$result = realpath(__DIR__.'/..').'/sdks/'.$key.'-'.$language['key'];
|
||||
$target = realpath(__DIR__.'/..').'/sdks/git/'.$language['key'].'/';
|
||||
$readme = realpath(__DIR__ . '/../../docs/sdks/'.$language['key'].'/README.md');
|
||||
$readme = ($readme) ? file_get_contents($readme) : '';
|
||||
$examples = realpath(__DIR__ . '/../../docs/sdks/'.$language['key'].'/EXAMPLES.md');
|
||||
$examples = ($examples) ? file_get_contents($examples) : '';
|
||||
$changelog = realpath(__DIR__ . '/../../docs/sdks/'.$language['key'].'/CHANGELOG.md');
|
||||
$changelog = ($changelog) ? file_get_contents($changelog) : '# Change Log';
|
||||
$result = \realpath(__DIR__.'/..').'/sdks/'.$key.'-'.$language['key'];
|
||||
$target = \realpath(__DIR__.'/..').'/sdks/git/'.$language['key'].'/';
|
||||
$readme = \realpath(__DIR__ . '/../../docs/sdks/'.$language['key'].'/README.md');
|
||||
$readme = ($readme) ? \file_get_contents($readme) : '';
|
||||
$examples = \realpath(__DIR__ . '/../../docs/sdks/'.$language['key'].'/EXAMPLES.md');
|
||||
$examples = ($examples) ? \file_get_contents($examples) : '';
|
||||
$changelog = \realpath(__DIR__ . '/../../docs/sdks/'.$language['key'].'/CHANGELOG.md');
|
||||
$changelog = ($changelog) ? \file_get_contents($changelog) : '# Change Log';
|
||||
$warning = ($language['beta']) ? '**This SDK is compatible with Appwrite server version ' . $version . '. For older versions, please check previous releases.**' : '';
|
||||
$license = 'BSD-3-Clause';
|
||||
$licenseContent = 'Copyright (c) 2019 Appwrite (https://appwrite.io) and individual contributors.
|
||||
|
@ -186,7 +186,7 @@ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
|||
$gitUrl = 'git@github.com:aw-tests/'.$language['gitRepoName'].'.git';
|
||||
}
|
||||
|
||||
exec('rm -rf '.$target.' && \
|
||||
\exec('rm -rf '.$target.' && \
|
||||
mkdir -p '.$target.' && \
|
||||
cd '.$target.' && \
|
||||
git init && \
|
||||
|
@ -201,7 +201,7 @@ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
|||
|
||||
Console::success("Pushed {$language['name']} SDK to {$gitUrl}");
|
||||
|
||||
exec('rm -rf '.$target);
|
||||
\exec('rm -rf '.$target);
|
||||
|
||||
Console::success("Remove temp directory '{$target}' for {$language['name']} SDK");
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
require_once __DIR__.'/../init.php';
|
||||
|
||||
cli_set_process_title('Audits V1 Worker');
|
||||
\cli_set_process_title('Audits V1 Worker');
|
||||
|
||||
echo APP_NAME.' audits worker v1 has started';
|
||||
|
||||
|
|
|
@ -9,7 +9,7 @@ use Appwrite\Network\Validator\CNAME;
|
|||
|
||||
require_once __DIR__.'/../init.php';
|
||||
|
||||
cli_set_process_title('Certificates V1 Worker');
|
||||
\cli_set_process_title('Certificates V1 Worker');
|
||||
|
||||
echo APP_NAME.' certificates worker v1 has started';
|
||||
|
||||
|
@ -51,7 +51,7 @@ class CertificatesV1
|
|||
$domain = new Domain((!empty($domain)) ? $domain : '');
|
||||
$expiry = 60 * 60 * 24 * 30 * 2; // 60 days
|
||||
$safety = 60 * 60; // 1 hour
|
||||
$renew = (time() + $expiry);
|
||||
$renew = (\time() + $expiry);
|
||||
|
||||
if(empty($domain->get())) {
|
||||
throw new Exception('Missing domain');
|
||||
|
@ -101,13 +101,13 @@ class CertificatesV1
|
|||
|
||||
if(!empty($certificate)
|
||||
&& isset($certificate['issueDate'])
|
||||
&& (($certificate['issueDate'] + ($expiry)) > time())) { // Check last issue time
|
||||
&& (($certificate['issueDate'] + ($expiry)) > \time())) { // Check last issue time
|
||||
throw new Exception('Renew isn\'t required');
|
||||
}
|
||||
|
||||
$staging = (Config::getParam('env') === App::MODE_TYPE_PRODUCTION) ? '' : ' --dry-run';
|
||||
|
||||
$response = shell_exec("certbot certonly --webroot --noninteractive --agree-tos{$staging} \
|
||||
$response = \shell_exec("certbot certonly --webroot --noninteractive --agree-tos{$staging} \
|
||||
--email ".$request->getServer('_APP_SYSTEM_EMAIL_ADDRESS', 'security@localhost.test')." \
|
||||
-w ".APP_STORAGE_CERTIFICATES." \
|
||||
-d {$domain->get()}");
|
||||
|
@ -118,39 +118,39 @@ class CertificatesV1
|
|||
|
||||
$path = APP_STORAGE_CERTIFICATES.'/'.$domain->get();
|
||||
|
||||
if(!is_readable($path)) {
|
||||
if (!mkdir($path, 0755, true)) {
|
||||
if(!\is_readable($path)) {
|
||||
if (!\mkdir($path, 0755, true)) {
|
||||
throw new Exception('Failed to create path...');
|
||||
}
|
||||
}
|
||||
|
||||
if(!@rename('/etc/letsencrypt/live/'.$domain->get().'/cert.pem', APP_STORAGE_CERTIFICATES.'/'.$domain->get().'/cert.pem')) {
|
||||
throw new Exception('Failed to rename certificate cert.pem: '.json_encode($response));
|
||||
if(!@\rename('/etc/letsencrypt/live/'.$domain->get().'/cert.pem', APP_STORAGE_CERTIFICATES.'/'.$domain->get().'/cert.pem')) {
|
||||
throw new Exception('Failed to rename certificate cert.pem: '.\json_encode($response));
|
||||
}
|
||||
|
||||
if(!@rename('/etc/letsencrypt/live/'.$domain->get().'/chain.pem', APP_STORAGE_CERTIFICATES.'/'.$domain->get().'/chain.pem')) {
|
||||
throw new Exception('Failed to rename certificate chain.pem: '.json_encode($response));
|
||||
if(!@\rename('/etc/letsencrypt/live/'.$domain->get().'/chain.pem', APP_STORAGE_CERTIFICATES.'/'.$domain->get().'/chain.pem')) {
|
||||
throw new Exception('Failed to rename certificate chain.pem: '.\json_encode($response));
|
||||
}
|
||||
|
||||
if(!@rename('/etc/letsencrypt/live/'.$domain->get().'/fullchain.pem', APP_STORAGE_CERTIFICATES.'/'.$domain->get().'/fullchain.pem')) {
|
||||
throw new Exception('Failed to rename certificate fullchain.pem: '.json_encode($response));
|
||||
if(!@\rename('/etc/letsencrypt/live/'.$domain->get().'/fullchain.pem', APP_STORAGE_CERTIFICATES.'/'.$domain->get().'/fullchain.pem')) {
|
||||
throw new Exception('Failed to rename certificate fullchain.pem: '.\json_encode($response));
|
||||
}
|
||||
|
||||
if(!@rename('/etc/letsencrypt/live/'.$domain->get().'/privkey.pem', APP_STORAGE_CERTIFICATES.'/'.$domain->get().'/privkey.pem')) {
|
||||
throw new Exception('Failed to rename certificate privkey.pem: '.json_encode($response));
|
||||
if(!@\rename('/etc/letsencrypt/live/'.$domain->get().'/privkey.pem', APP_STORAGE_CERTIFICATES.'/'.$domain->get().'/privkey.pem')) {
|
||||
throw new Exception('Failed to rename certificate privkey.pem: '.\json_encode($response));
|
||||
}
|
||||
|
||||
$certificate = array_merge($certificate, [
|
||||
$certificate = \array_merge($certificate, [
|
||||
'$collection' => Database::SYSTEM_COLLECTION_CERTIFICATES,
|
||||
'$permissions' => [
|
||||
'read' => [],
|
||||
'write' => [],
|
||||
],
|
||||
'domain' => $domain->get(),
|
||||
'issueDate' => time(),
|
||||
'issueDate' => \time(),
|
||||
'renewDate' => $renew,
|
||||
'attempts' => 0,
|
||||
'log' => json_encode($response),
|
||||
'log' => \json_encode($response),
|
||||
]);
|
||||
|
||||
$certificate = $consoleDB->createDocument($certificate);
|
||||
|
@ -160,8 +160,8 @@ class CertificatesV1
|
|||
}
|
||||
|
||||
if(!empty($document)) {
|
||||
$document = array_merge($document, [
|
||||
'updated' => time(),
|
||||
$document = \array_merge($document, [
|
||||
'updated' => \time(),
|
||||
'certificateId' => $certificate->getId(),
|
||||
]);
|
||||
|
||||
|
@ -178,7 +178,7 @@ class CertificatesV1
|
|||
- certFile: /storage/certificates/{$domain->get()}/fullchain.pem
|
||||
keyFile: /storage/certificates/{$domain->get()}/privkey.pem";
|
||||
|
||||
if(!file_put_contents(APP_STORAGE_CONFIG.'/'.$domain->get().'.yml', $config)) {
|
||||
if(!\file_put_contents(APP_STORAGE_CONFIG.'/'.$domain->get().'.yml', $config)) {
|
||||
throw new Exception('Failed to save SSL configuration');
|
||||
}
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
require_once __DIR__.'/../init.php';
|
||||
|
||||
cli_set_process_title('Deletes V1 Worker');
|
||||
\cli_set_process_title('Deletes V1 Worker');
|
||||
|
||||
echo APP_NAME.' deletes worker v1 has started';
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
require_once __DIR__.'/../init.php';
|
||||
|
||||
cli_set_process_title('Mails V1 Worker');
|
||||
\cli_set_process_title('Mails V1 Worker');
|
||||
|
||||
echo APP_NAME.' mails worker v1 has started';
|
||||
|
||||
|
@ -32,7 +32,7 @@ class MailsV1
|
|||
$mail->addAddress($recipient, $name);
|
||||
$mail->Subject = $subject;
|
||||
$mail->Body = $body;
|
||||
$mail->AltBody = strip_tags($body);
|
||||
$mail->AltBody = \strip_tags($body);
|
||||
|
||||
try {
|
||||
$mail->send();
|
||||
|
|
|
@ -7,7 +7,7 @@ use Appwrite\Database\Database;
|
|||
use Appwrite\Database\Validator\Authorization;
|
||||
use Cron\CronExpression;
|
||||
|
||||
cli_set_process_title('Tasks V1 Worker');
|
||||
\cli_set_process_title('Tasks V1 Worker');
|
||||
|
||||
echo APP_NAME.' tasks worker v1 has started';
|
||||
|
||||
|
@ -42,7 +42,7 @@ class TasksV1
|
|||
$taskId = (isset($this->args['$id'])) ? $this->args['$id'] : null;
|
||||
$updated = (isset($this->args['updated'])) ? $this->args['updated'] : null;
|
||||
$next = (isset($this->args['next'])) ? $this->args['next'] : null;
|
||||
$delay = time() - $next;
|
||||
$delay = \time() - $next;
|
||||
$errors = [];
|
||||
$timeout = 60 * 5; // 5 minutes
|
||||
$errorLimit = 5;
|
||||
|
@ -59,7 +59,7 @@ class TasksV1
|
|||
|
||||
Authorization::enable();
|
||||
|
||||
if (is_null($task->getId()) || Database::SYSTEM_COLLECTION_TASKS !== $task->getCollection()) {
|
||||
if (\is_null($task->getId()) || Database::SYSTEM_COLLECTION_TASKS !== $task->getCollection()) {
|
||||
throw new Exception('Task Not Found');
|
||||
}
|
||||
|
||||
|
@ -75,69 +75,69 @@ class TasksV1
|
|||
|
||||
$cron = CronExpression::factory($task->getAttribute('schedule'));
|
||||
$next = (int) $cron->getNextRunDate()->format('U');
|
||||
$headers = (is_array($task->getAttribute('httpHeaders', []))) ? $task->getAttribute('httpHeaders', []) : [];
|
||||
$headers = (\is_array($task->getAttribute('httpHeaders', []))) ? $task->getAttribute('httpHeaders', []) : [];
|
||||
|
||||
$task
|
||||
->setAttribute('next', $next)
|
||||
->setAttribute('previous', time())
|
||||
->setAttribute('previous', \time())
|
||||
;
|
||||
|
||||
ResqueScheduler::enqueueAt($next, 'v1-tasks', 'TasksV1', $task->getArrayCopy()); // Async task rescheduale
|
||||
|
||||
$startTime = microtime(true);
|
||||
$startTime = \microtime(true);
|
||||
|
||||
// Execute Task
|
||||
|
||||
$ch = curl_init($task->getAttribute('httpUrl'));
|
||||
$ch = \curl_init($task->getAttribute('httpUrl'));
|
||||
|
||||
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $task->getAttribute('httpMethod'));
|
||||
curl_setopt($ch, CURLOPT_POSTFIELDS, '');
|
||||
curl_setopt($ch, CURLOPT_HEADER, 0);
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
||||
curl_setopt($ch, CURLOPT_USERAGENT, sprintf(APP_USERAGENT,
|
||||
\curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $task->getAttribute('httpMethod'));
|
||||
\curl_setopt($ch, CURLOPT_POSTFIELDS, '');
|
||||
\curl_setopt($ch, CURLOPT_HEADER, 0);
|
||||
\curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
||||
\curl_setopt($ch, CURLOPT_USERAGENT, \sprintf(APP_USERAGENT,
|
||||
Config::getParam('version'),
|
||||
$request->getServer('_APP_SYSTEM_SECURITY_EMAIL_ADDRESS', APP_EMAIL_SECURITY)
|
||||
));
|
||||
curl_setopt(
|
||||
\curl_setopt(
|
||||
$ch,
|
||||
CURLOPT_HTTPHEADER,
|
||||
array_merge($headers, [
|
||||
\array_merge($headers, [
|
||||
'X-'.APP_NAME.'-Task-ID: '.$task->getAttribute('$id', ''),
|
||||
'X-'.APP_NAME.'-Task-Name: '.$task->getAttribute('name', ''),
|
||||
])
|
||||
);
|
||||
curl_setopt($ch, CURLOPT_HEADER, true); // we want headers
|
||||
curl_setopt($ch, CURLOPT_NOBODY, true);
|
||||
curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
|
||||
\curl_setopt($ch, CURLOPT_HEADER, true); // we want headers
|
||||
\curl_setopt($ch, CURLOPT_NOBODY, true);
|
||||
\curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
|
||||
|
||||
if (!$task->getAttribute('security', true)) {
|
||||
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
|
||||
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
|
||||
\curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
|
||||
\curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
|
||||
}
|
||||
|
||||
$httpUser = $task->getAttribute('httpUser');
|
||||
$httpPass = $task->getAttribute('httpPass');
|
||||
|
||||
if (!empty($httpUser) && !empty($httpPass)) {
|
||||
curl_setopt($ch, CURLOPT_USERPWD, "$httpUser:$httpPass");
|
||||
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
|
||||
\curl_setopt($ch, CURLOPT_USERPWD, "$httpUser:$httpPass");
|
||||
\curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
|
||||
}
|
||||
|
||||
$response = curl_exec($ch);
|
||||
$response = \curl_exec($ch);
|
||||
|
||||
if (false === $response) {
|
||||
$errors[] = curl_error($ch).'Failed to execute task';
|
||||
$errors[] = \curl_error($ch).'Failed to execute task';
|
||||
}
|
||||
|
||||
$code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
||||
$codeFamily = mb_substr($code, 0, 1);
|
||||
$headersSize = curl_getinfo($ch, CURLINFO_HEADER_SIZE);
|
||||
$headers = substr($response, 0, $headersSize);
|
||||
$body = substr($response, $headersSize);
|
||||
$code = \curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
||||
$codeFamily = \mb_substr($code, 0, 1);
|
||||
$headersSize = \curl_getinfo($ch, CURLINFO_HEADER_SIZE);
|
||||
$headers = \substr($response, 0, $headersSize);
|
||||
$body = \substr($response, $headersSize);
|
||||
|
||||
curl_close($ch);
|
||||
\curl_close($ch);
|
||||
|
||||
$totalTime = round(microtime(true) - $startTime, 2);
|
||||
$totalTime = \round(\microtime(true) - $startTime, 2);
|
||||
|
||||
switch ($codeFamily) {
|
||||
case '2':
|
||||
|
@ -157,16 +157,16 @@ class TasksV1
|
|||
->setAttribute('status', ($task->getAttribute('failures') >= $errorLimit) ? 'pause' : 'play')
|
||||
;
|
||||
|
||||
$alert = 'Task "'.$task->getAttribute('name').'" failed to execute with the following errors: '.implode("\n", $errors);
|
||||
$alert = 'Task "'.$task->getAttribute('name').'" failed to execute with the following errors: '.\implode("\n", $errors);
|
||||
}
|
||||
|
||||
$log = json_decode($task->getAttribute('log', '{}'), true);
|
||||
$log = \json_decode($task->getAttribute('log', '{}'), true);
|
||||
|
||||
if (count($log) >= $logLimit) {
|
||||
array_pop($log);
|
||||
if (\count($log) >= $logLimit) {
|
||||
\array_pop($log);
|
||||
}
|
||||
|
||||
array_unshift($log, [
|
||||
\array_unshift($log, [
|
||||
'code' => $code,
|
||||
'duration' => $totalTime,
|
||||
'delay' => $delay,
|
||||
|
@ -176,7 +176,7 @@ class TasksV1
|
|||
]);
|
||||
|
||||
$task
|
||||
->setAttribute('log', json_encode($log))
|
||||
->setAttribute('log', \json_encode($log))
|
||||
->setAttribute('duration', $totalTime)
|
||||
->setAttribute('delay', $delay)
|
||||
;
|
||||
|
|
|
@ -4,7 +4,7 @@ use Utopia\Config\Config;
|
|||
|
||||
require_once __DIR__.'/../init.php';
|
||||
|
||||
cli_set_process_title('Usage V1 Worker');
|
||||
\cli_set_process_title('Usage V1 Worker');
|
||||
|
||||
echo APP_NAME.' usage worker v1 has started';
|
||||
|
||||
|
@ -36,7 +36,7 @@ class UsageV1
|
|||
// the global namespace is prepended to every key (optional)
|
||||
$statsd->setNamespace('appwrite.usage');
|
||||
|
||||
$statsd->increment('requests.all'.$tags.',method='.strtolower($method));
|
||||
$statsd->increment('requests.all'.$tags.',method='.\strtolower($method));
|
||||
|
||||
$statsd->count('network.all'.$tags, $request + $response);
|
||||
$statsd->count('network.inbound'.$tags, $request);
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
require_once __DIR__.'/../init.php';
|
||||
|
||||
cli_set_process_title('Webhooks V1 Worker');
|
||||
\cli_set_process_title('Webhooks V1 Worker');
|
||||
|
||||
echo APP_NAME.' webhooks worker v1 has started';
|
||||
|
||||
|
@ -27,7 +27,7 @@ class WebhooksV1
|
|||
// Event
|
||||
$projectId = $this->args['projectId'];
|
||||
$event = $this->args['event'];
|
||||
$payload = json_encode($this->args['payload']);
|
||||
$payload = \json_encode($this->args['payload']);
|
||||
|
||||
// Webhook
|
||||
|
||||
|
@ -37,12 +37,12 @@ class WebhooksV1
|
|||
|
||||
Authorization::enable();
|
||||
|
||||
if (is_null($project->getId()) || Database::SYSTEM_COLLECTION_PROJECTS !== $project->getCollection()) {
|
||||
if (\is_null($project->getId()) || Database::SYSTEM_COLLECTION_PROJECTS !== $project->getCollection()) {
|
||||
throw new Exception('Project Not Found');
|
||||
}
|
||||
|
||||
foreach ($project->getAttribute('webhooks', []) as $webhook) {
|
||||
if (!(isset($webhook['events']) && is_array($webhook['events']) && in_array($event, $webhook['events']))) {
|
||||
if (!(isset($webhook['events']) && \is_array($webhook['events']) && \in_array($event, $webhook['events']))) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -53,22 +53,22 @@ class WebhooksV1
|
|||
$httpUser = (isset($webhook['httpUser'])) ? $webhook['httpUser'] : null;
|
||||
$httpPass = (isset($webhook['httpPass'])) ? $webhook['httpPass'] : null;
|
||||
|
||||
$ch = curl_init($url);
|
||||
$ch = \curl_init($url);
|
||||
|
||||
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
|
||||
curl_setopt($ch, CURLOPT_POSTFIELDS, $payload);
|
||||
curl_setopt($ch, CURLOPT_HEADER, 0);
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
||||
curl_setopt($ch, CURLOPT_USERAGENT, sprintf(APP_USERAGENT,
|
||||
\curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
|
||||
\curl_setopt($ch, CURLOPT_POSTFIELDS, $payload);
|
||||
\curl_setopt($ch, CURLOPT_HEADER, 0);
|
||||
\curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
||||
\curl_setopt($ch, CURLOPT_USERAGENT, \sprintf(APP_USERAGENT,
|
||||
Config::getParam('version'),
|
||||
$request->getServer('_APP_SYSTEM_SECURITY_EMAIL_ADDRESS', APP_EMAIL_SECURITY)
|
||||
));
|
||||
curl_setopt(
|
||||
\curl_setopt(
|
||||
$ch,
|
||||
CURLOPT_HTTPHEADER,
|
||||
[
|
||||
'Content-Type: application/json',
|
||||
'Content-Length: '.strlen($payload),
|
||||
'Content-Length: '.\strlen($payload),
|
||||
'X-'.APP_NAME.'-Webhook-Event: '.$event,
|
||||
'X-'.APP_NAME.'-Webhook-Name: '.$name,
|
||||
'X-'.APP_NAME.'-Webhook-Signature: '.$signature,
|
||||
|
@ -76,24 +76,24 @@ class WebhooksV1
|
|||
);
|
||||
|
||||
if (!$security) {
|
||||
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
|
||||
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
|
||||
\curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
|
||||
\curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
|
||||
}
|
||||
|
||||
if (!empty($httpUser) && !empty($httpPass)) {
|
||||
curl_setopt($ch, CURLOPT_USERPWD, "$httpUser:$httpPass");
|
||||
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
|
||||
\curl_setopt($ch, CURLOPT_USERPWD, "$httpUser:$httpPass");
|
||||
\curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
|
||||
}
|
||||
|
||||
if (false === curl_exec($ch)) {
|
||||
$errors[] = curl_error($ch).' in event '.$event.' for webhook '.$name;
|
||||
if (false === \curl_exec($ch)) {
|
||||
$errors[] = \curl_error($ch).' in event '.$event.' for webhook '.$name;
|
||||
}
|
||||
|
||||
curl_close($ch);
|
||||
\curl_close($ch);
|
||||
}
|
||||
|
||||
if (!empty($errors)) {
|
||||
throw new Exception(implode(" / \n\n", $errors));
|
||||
throw new Exception(\implode(" / \n\n", $errors));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -32,11 +32,11 @@
|
|||
|
||||
"appwrite/php-clamav": "1.0.*",
|
||||
|
||||
"utopia-php/framework": "0.3.4",
|
||||
"utopia-php/framework": "0.3.5",
|
||||
"utopia-php/abuse": "0.2.*",
|
||||
"utopia-php/audit": "0.3.*",
|
||||
"utopia-php/cache": "0.2.*",
|
||||
"utopia-php/cli": "0.6.1",
|
||||
"utopia-php/cli": "0.6.2",
|
||||
"utopia-php/config": "0.2.*",
|
||||
"utopia-php/locale": "0.2.*",
|
||||
"utopia-php/registry": "0.2.*",
|
||||
|
|
110
composer.lock
generated
110
composer.lock
generated
|
@ -4,7 +4,7 @@
|
|||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
||||
"This file is @generated automatically"
|
||||
],
|
||||
"content-hash": "b40a5280315184407b21232e6c607b85",
|
||||
"content-hash": "9deec50e5a99197511b5efbcaa9593bd",
|
||||
"packages": [
|
||||
{
|
||||
"name": "appwrite/php-clamav",
|
||||
|
@ -1311,16 +1311,16 @@
|
|||
},
|
||||
{
|
||||
"name": "utopia-php/abuse",
|
||||
"version": "0.2.0",
|
||||
"version": "0.2.1",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/utopia-php/abuse.git",
|
||||
"reference": "8a014449fe92b5275ef5006ac7f7ecaaec23e64d"
|
||||
"reference": "b485eddeda335c4f7d1a16fbf5544e37bdf195ac"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/utopia-php/abuse/zipball/8a014449fe92b5275ef5006ac7f7ecaaec23e64d",
|
||||
"reference": "8a014449fe92b5275ef5006ac7f7ecaaec23e64d",
|
||||
"url": "https://api.github.com/repos/utopia-php/abuse/zipball/b485eddeda335c4f7d1a16fbf5544e37bdf195ac",
|
||||
"reference": "b485eddeda335c4f7d1a16fbf5544e37bdf195ac",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
|
@ -1354,20 +1354,20 @@
|
|||
"upf",
|
||||
"utopia"
|
||||
],
|
||||
"time": "2019-12-28T19:43:47+00:00"
|
||||
"time": "2020-06-20T11:35:08+00:00"
|
||||
},
|
||||
{
|
||||
"name": "utopia-php/audit",
|
||||
"version": "0.3.0",
|
||||
"version": "0.3.1",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/utopia-php/audit.git",
|
||||
"reference": "ed624c324835859b68521099de13c01c6928703f"
|
||||
"reference": "7bcceba05ed640fe910e7b6b0c82d998fb9d6495"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/utopia-php/audit/zipball/ed624c324835859b68521099de13c01c6928703f",
|
||||
"reference": "ed624c324835859b68521099de13c01c6928703f",
|
||||
"url": "https://api.github.com/repos/utopia-php/audit/zipball/7bcceba05ed640fe910e7b6b0c82d998fb9d6495",
|
||||
"reference": "7bcceba05ed640fe910e7b6b0c82d998fb9d6495",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
|
@ -1401,20 +1401,20 @@
|
|||
"upf",
|
||||
"utopia"
|
||||
],
|
||||
"time": "2020-04-17T19:42:29+00:00"
|
||||
"time": "2020-06-20T11:36:43+00:00"
|
||||
},
|
||||
{
|
||||
"name": "utopia-php/cache",
|
||||
"version": "0.2.0",
|
||||
"version": "0.2.1",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/utopia-php/cache.git",
|
||||
"reference": "7c0dbf1ae1c216a2ab8c3fdb7f2c0166a2e0988d"
|
||||
"reference": "52a20ae1d5e3f5be11492c4bb0af9cf2a2c07e5d"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/utopia-php/cache/zipball/7c0dbf1ae1c216a2ab8c3fdb7f2c0166a2e0988d",
|
||||
"reference": "7c0dbf1ae1c216a2ab8c3fdb7f2c0166a2e0988d",
|
||||
"url": "https://api.github.com/repos/utopia-php/cache/zipball/52a20ae1d5e3f5be11492c4bb0af9cf2a2c07e5d",
|
||||
"reference": "52a20ae1d5e3f5be11492c4bb0af9cf2a2c07e5d",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
|
@ -1448,20 +1448,20 @@
|
|||
"upf",
|
||||
"utopia"
|
||||
],
|
||||
"time": "2019-12-09T13:02:50+00:00"
|
||||
"time": "2020-06-20T11:43:40+00:00"
|
||||
},
|
||||
{
|
||||
"name": "utopia-php/cli",
|
||||
"version": "0.6.1",
|
||||
"version": "0.6.2",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/utopia-php/cli.git",
|
||||
"reference": "0e88da425122f81020e90d575cbe80232f364b68"
|
||||
"reference": "8ad0371ce045b60034ebcb2b001b6e88bdcc3670"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/utopia-php/cli/zipball/0e88da425122f81020e90d575cbe80232f364b68",
|
||||
"reference": "0e88da425122f81020e90d575cbe80232f364b68",
|
||||
"url": "https://api.github.com/repos/utopia-php/cli/zipball/8ad0371ce045b60034ebcb2b001b6e88bdcc3670",
|
||||
"reference": "8ad0371ce045b60034ebcb2b001b6e88bdcc3670",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
|
@ -1496,20 +1496,20 @@
|
|||
"upf",
|
||||
"utopia"
|
||||
],
|
||||
"time": "2020-06-18T23:00:19+00:00"
|
||||
"time": "2020-06-20T11:37:51+00:00"
|
||||
},
|
||||
{
|
||||
"name": "utopia-php/config",
|
||||
"version": "0.2.0",
|
||||
"version": "0.2.1",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/utopia-php/config.git",
|
||||
"reference": "f1f41d3863eb00bd2837b45c2e17e8b5da1cf46d"
|
||||
"reference": "48c5009c33b8426260ee7425100e716d7ed7f693"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/utopia-php/config/zipball/f1f41d3863eb00bd2837b45c2e17e8b5da1cf46d",
|
||||
"reference": "f1f41d3863eb00bd2837b45c2e17e8b5da1cf46d",
|
||||
"url": "https://api.github.com/repos/utopia-php/config/zipball/48c5009c33b8426260ee7425100e716d7ed7f693",
|
||||
"reference": "48c5009c33b8426260ee7425100e716d7ed7f693",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
|
@ -1542,7 +1542,7 @@
|
|||
"upf",
|
||||
"utopia"
|
||||
],
|
||||
"time": "2020-03-28T10:24:18+00:00"
|
||||
"time": "2020-06-20T11:38:58+00:00"
|
||||
},
|
||||
{
|
||||
"name": "utopia-php/domains",
|
||||
|
@ -1596,16 +1596,16 @@
|
|||
},
|
||||
{
|
||||
"name": "utopia-php/framework",
|
||||
"version": "0.3.3",
|
||||
"version": "0.3.5",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/utopia-php/framework.git",
|
||||
"reference": "dae7464b257663cd250e58244b21781a996134c2"
|
||||
"reference": "ca2ebe37936983d786f57bae8ee6e006299f4942"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/utopia-php/framework/zipball/dae7464b257663cd250e58244b21781a996134c2",
|
||||
"reference": "dae7464b257663cd250e58244b21781a996134c2",
|
||||
"url": "https://api.github.com/repos/utopia-php/framework/zipball/ca2ebe37936983d786f57bae8ee6e006299f4942",
|
||||
"reference": "ca2ebe37936983d786f57bae8ee6e006299f4942",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
|
@ -1636,20 +1636,20 @@
|
|||
"php",
|
||||
"upf"
|
||||
],
|
||||
"time": "2020-06-18T23:28:10+00:00"
|
||||
"time": "2020-06-20T11:33:46+00:00"
|
||||
},
|
||||
{
|
||||
"name": "utopia-php/locale",
|
||||
"version": "0.2.0",
|
||||
"version": "0.2.1",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/utopia-php/locale.git",
|
||||
"reference": "e3e5f16b190e0ddc654ef2fd86f6280d7acc41b1"
|
||||
"reference": "f2ed7f0b50fe961d65600871e8f8d9dea3167500"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/utopia-php/locale/zipball/e3e5f16b190e0ddc654ef2fd86f6280d7acc41b1",
|
||||
"reference": "e3e5f16b190e0ddc654ef2fd86f6280d7acc41b1",
|
||||
"url": "https://api.github.com/repos/utopia-php/locale/zipball/f2ed7f0b50fe961d65600871e8f8d9dea3167500",
|
||||
"reference": "f2ed7f0b50fe961d65600871e8f8d9dea3167500",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
|
@ -1682,20 +1682,20 @@
|
|||
"upf",
|
||||
"utopia"
|
||||
],
|
||||
"time": "2019-12-09T13:03:33+00:00"
|
||||
"time": "2020-06-20T11:41:46+00:00"
|
||||
},
|
||||
{
|
||||
"name": "utopia-php/registry",
|
||||
"version": "0.2.0",
|
||||
"version": "0.2.1",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/utopia-php/registry.git",
|
||||
"reference": "ca38e4b9b1079fb375463c6a7df3eecc2cb91d10"
|
||||
"reference": "2cd2d318067a6b310c35c9f3ad73d2ce3c1ca7d5"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/utopia-php/registry/zipball/ca38e4b9b1079fb375463c6a7df3eecc2cb91d10",
|
||||
"reference": "ca38e4b9b1079fb375463c6a7df3eecc2cb91d10",
|
||||
"url": "https://api.github.com/repos/utopia-php/registry/zipball/2cd2d318067a6b310c35c9f3ad73d2ce3c1ca7d5",
|
||||
"reference": "2cd2d318067a6b310c35c9f3ad73d2ce3c1ca7d5",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
|
@ -1729,7 +1729,7 @@
|
|||
"upf",
|
||||
"utopia"
|
||||
],
|
||||
"time": "2019-12-09T13:04:53+00:00"
|
||||
"time": "2020-06-20T11:46:06+00:00"
|
||||
}
|
||||
],
|
||||
"packages-dev": [
|
||||
|
@ -1739,7 +1739,7 @@
|
|||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/appwrite/sdk-generator",
|
||||
"reference": "5183b758ec53db3b6e9529892cacebf842773675"
|
||||
"reference": "2b9a55bc447b8b856a8b9dc8c5c86a2c61a6ed3a"
|
||||
},
|
||||
"require": {
|
||||
"ext-curl": "*",
|
||||
|
@ -1769,7 +1769,7 @@
|
|||
}
|
||||
],
|
||||
"description": "Appwrite PHP library for generating API SDKs for multiple programming languages and platforms",
|
||||
"time": "2020-06-18T12:20:14+00:00"
|
||||
"time": "2020-06-20T07:38:05+00:00"
|
||||
},
|
||||
{
|
||||
"name": "doctrine/instantiator",
|
||||
|
@ -2092,12 +2092,12 @@
|
|||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/phpDocumentor/ReflectionCommon.git",
|
||||
"reference": "985f414b55eca4296ffc99db960a97b3cc8fbcea"
|
||||
"reference": "cf8df60735d98fd18070b7cab0019ba0831e219c"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/phpDocumentor/ReflectionCommon/zipball/985f414b55eca4296ffc99db960a97b3cc8fbcea",
|
||||
"reference": "985f414b55eca4296ffc99db960a97b3cc8fbcea",
|
||||
"url": "https://api.github.com/repos/phpDocumentor/ReflectionCommon/zipball/cf8df60735d98fd18070b7cab0019ba0831e219c",
|
||||
"reference": "cf8df60735d98fd18070b7cab0019ba0831e219c",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
|
@ -2133,7 +2133,7 @@
|
|||
"reflection",
|
||||
"static analysis"
|
||||
],
|
||||
"time": "2020-04-27T09:34:19+00:00"
|
||||
"time": "2020-06-19T17:42:03+00:00"
|
||||
},
|
||||
{
|
||||
"name": "phpdocumentor/reflection-docblock",
|
||||
|
@ -2141,12 +2141,12 @@
|
|||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/phpDocumentor/ReflectionDocBlock.git",
|
||||
"reference": "5892a510fe31de9c4200e6f9ae30e91dc5cd5a41"
|
||||
"reference": "790426f28bfcbfc1a6f1d59ee8c986edfa45395c"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/phpDocumentor/ReflectionDocBlock/zipball/5892a510fe31de9c4200e6f9ae30e91dc5cd5a41",
|
||||
"reference": "5892a510fe31de9c4200e6f9ae30e91dc5cd5a41",
|
||||
"url": "https://api.github.com/repos/phpDocumentor/ReflectionDocBlock/zipball/790426f28bfcbfc1a6f1d59ee8c986edfa45395c",
|
||||
"reference": "790426f28bfcbfc1a6f1d59ee8c986edfa45395c",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
|
@ -2186,7 +2186,7 @@
|
|||
}
|
||||
],
|
||||
"description": "With this component, a library can provide support for annotations via DocBlocks or otherwise retrieve information that is embedded in a DocBlock.",
|
||||
"time": "2020-06-18T20:57:11+00:00"
|
||||
"time": "2020-06-19T18:58:43+00:00"
|
||||
},
|
||||
{
|
||||
"name": "phpdocumentor/type-resolver",
|
||||
|
@ -2194,12 +2194,12 @@
|
|||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/phpDocumentor/TypeResolver.git",
|
||||
"reference": "95d8782070ccd738295bbe4483f8760f998ad64d"
|
||||
"reference": "94f3ddc5d77e49daadadd33b798b933e52dde82c"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/phpDocumentor/TypeResolver/zipball/95d8782070ccd738295bbe4483f8760f998ad64d",
|
||||
"reference": "95d8782070ccd738295bbe4483f8760f998ad64d",
|
||||
"url": "https://api.github.com/repos/phpDocumentor/TypeResolver/zipball/94f3ddc5d77e49daadadd33b798b933e52dde82c",
|
||||
"reference": "94f3ddc5d77e49daadadd33b798b933e52dde82c",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
|
@ -2232,7 +2232,7 @@
|
|||
}
|
||||
],
|
||||
"description": "A PSR-5 based resolver of Class names, Types and Structural Element Names",
|
||||
"time": "2020-05-13T13:46:15+00:00"
|
||||
"time": "2020-06-19T19:40:27+00:00"
|
||||
},
|
||||
{
|
||||
"name": "phpspec/prophecy",
|
||||
|
|
|
@ -82,7 +82,7 @@ class Auth
|
|||
*/
|
||||
public static function encodeSession($id, $secret)
|
||||
{
|
||||
return base64_encode(json_encode([
|
||||
return \base64_encode(\json_encode([
|
||||
'id' => $id,
|
||||
'secret' => $secret,
|
||||
]));
|
||||
|
@ -99,14 +99,14 @@ class Auth
|
|||
*/
|
||||
public static function decodeSession($session)
|
||||
{
|
||||
$session = json_decode(base64_decode($session), true);
|
||||
$session = \json_decode(\base64_decode($session), true);
|
||||
$default = ['id' => null, 'secret' => ''];
|
||||
|
||||
if (!is_array($session)) {
|
||||
if (!\is_array($session)) {
|
||||
return $default;
|
||||
}
|
||||
|
||||
return array_merge($default, $session);
|
||||
return \array_merge($default, $session);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -120,7 +120,7 @@ class Auth
|
|||
*/
|
||||
public static function hash($string)
|
||||
{
|
||||
return hash('sha256', $string);
|
||||
return \hash('sha256', $string);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -134,7 +134,7 @@ class Auth
|
|||
*/
|
||||
public static function passwordHash($string)
|
||||
{
|
||||
return password_hash($string, PASSWORD_BCRYPT, array('cost' => 8));
|
||||
return \password_hash($string, PASSWORD_BCRYPT, array('cost' => 8));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -147,7 +147,7 @@ class Auth
|
|||
*/
|
||||
public static function passwordVerify($plain, $hash)
|
||||
{
|
||||
return password_verify($plain, $hash);
|
||||
return \password_verify($plain, $hash);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -163,7 +163,7 @@ class Auth
|
|||
*/
|
||||
public static function passwordGenerator(int $length = 20):string
|
||||
{
|
||||
return bin2hex(random_bytes($length));
|
||||
return \bin2hex(\random_bytes($length));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -179,7 +179,7 @@ class Auth
|
|||
*/
|
||||
public static function tokenGenerator(int $length = 128):string
|
||||
{
|
||||
return bin2hex(random_bytes($length));
|
||||
return \bin2hex(\random_bytes($length));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -199,7 +199,7 @@ class Auth
|
|||
isset($token['expire']) &&
|
||||
$token['type'] == $type &&
|
||||
$token['secret'] === self::hash($secret) &&
|
||||
$token['expire'] >= time()) {
|
||||
$token['expire'] >= \time()) {
|
||||
return $token->getId();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -95,7 +95,7 @@ abstract class OAuth2
|
|||
protected function addScope(string $scope):OAuth2
|
||||
{
|
||||
// Add a scope to the scopes array if it isn't already present
|
||||
if (!in_array($scope, $this->scopes)){
|
||||
if (!\in_array($scope, $this->scopes)){
|
||||
$this->scopes[] = $scope;
|
||||
}
|
||||
return $this;
|
||||
|
@ -120,7 +120,7 @@ abstract class OAuth2
|
|||
*/
|
||||
public function parseState(string $state)
|
||||
{
|
||||
return json_decode($state, true);
|
||||
return \json_decode($state, true);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -133,24 +133,24 @@ abstract class OAuth2
|
|||
*/
|
||||
protected function request(string $method, string $url = '', array $headers = [], string $payload = ''):string
|
||||
{
|
||||
$ch = curl_init($url);
|
||||
$ch = \curl_init($url);
|
||||
|
||||
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method);
|
||||
curl_setopt($ch, CURLOPT_HEADER, 0);
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
||||
curl_setopt($ch, CURLOPT_USERAGENT, '');
|
||||
\curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method);
|
||||
\curl_setopt($ch, CURLOPT_HEADER, 0);
|
||||
\curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
||||
\curl_setopt($ch, CURLOPT_USERAGENT, '');
|
||||
|
||||
if (!empty($payload)) {
|
||||
curl_setopt($ch, CURLOPT_POSTFIELDS, $payload);
|
||||
\curl_setopt($ch, CURLOPT_POSTFIELDS, $payload);
|
||||
}
|
||||
|
||||
$headers[] = 'Content-length: '.strlen($payload);
|
||||
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
|
||||
$headers[] = 'Content-length: '.\strlen($payload);
|
||||
\curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
|
||||
|
||||
// Send the request & save response to $response
|
||||
$response = curl_exec($ch);
|
||||
$response = \curl_exec($ch);
|
||||
|
||||
curl_close($ch);
|
||||
\curl_close($ch);
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
|
|
@ -38,7 +38,7 @@ class Amazon extends OAuth2
|
|||
*/
|
||||
public function parseState(string $state)
|
||||
{
|
||||
return json_decode(html_entity_decode($state), true);
|
||||
return \json_decode(\html_entity_decode($state), true);
|
||||
}
|
||||
|
||||
|
||||
|
@ -47,11 +47,11 @@ class Amazon extends OAuth2
|
|||
*/
|
||||
public function getLoginURL(): string
|
||||
{
|
||||
return 'https://www.amazon.com/ap/oa?'.http_build_query([
|
||||
return 'https://www.amazon.com/ap/oa?'.\http_build_query([
|
||||
'response_type' => 'code',
|
||||
'client_id' => $this->appID,
|
||||
'scope' => implode(' ', $this->getScopes()),
|
||||
'state' => json_encode($this->state),
|
||||
'scope' => \implode(' ', $this->getScopes()),
|
||||
'state' => \json_encode($this->state),
|
||||
'redirect_uri' => $this->callback
|
||||
]);
|
||||
}
|
||||
|
@ -68,7 +68,7 @@ class Amazon extends OAuth2
|
|||
'POST',
|
||||
'https://api.amazon.com/auth/o2/token',
|
||||
$headers,
|
||||
http_build_query([
|
||||
\http_build_query([
|
||||
'code' => $code,
|
||||
'client_id' => $this->appID ,
|
||||
'client_secret' => $this->appSecret,
|
||||
|
@ -76,7 +76,7 @@ class Amazon extends OAuth2
|
|||
'grant_type' => 'authorization_code'
|
||||
])
|
||||
);
|
||||
$accessToken = json_decode($accessToken, true);
|
||||
$accessToken = \json_decode($accessToken, true);
|
||||
|
||||
if (isset($accessToken['access_token'])) {
|
||||
return $accessToken['access_token'];
|
||||
|
@ -141,8 +141,8 @@ class Amazon extends OAuth2
|
|||
protected function getUser(string $accessToken): array
|
||||
{
|
||||
if (empty($this->user)) {
|
||||
$user = $this->request('GET', 'https://api.amazon.com/user/profile?access_token='.urlencode($accessToken));
|
||||
$this->user = json_decode($user, true);
|
||||
$user = $this->request('GET', 'https://api.amazon.com/user/profile?access_token='.\urlencode($accessToken));
|
||||
$this->user = \json_decode($user, true);
|
||||
}
|
||||
return $this->user;
|
||||
}
|
||||
|
|
|
@ -41,13 +41,13 @@ class Apple extends OAuth2
|
|||
*/
|
||||
public function getLoginURL(): string
|
||||
{
|
||||
return 'https://appleid.apple.com/auth/authorize?'.http_build_query([
|
||||
return 'https://appleid.apple.com/auth/authorize?'.\http_build_query([
|
||||
'client_id' => $this->appID,
|
||||
'redirect_uri' => $this->callback,
|
||||
'state' => json_encode($this->state),
|
||||
'state' => \json_encode($this->state),
|
||||
'response_type' => 'code',
|
||||
'response_mode' => 'form_post',
|
||||
'scope' => implode(' ', $this->getScopes())
|
||||
'scope' => \implode(' ', $this->getScopes())
|
||||
]);
|
||||
}
|
||||
|
||||
|
@ -63,7 +63,7 @@ class Apple extends OAuth2
|
|||
'POST',
|
||||
'https://appleid.apple.com/auth/token',
|
||||
$headers,
|
||||
http_build_query([
|
||||
\http_build_query([
|
||||
'grant_type' => 'authorization_code',
|
||||
'code' => $code,
|
||||
'client_id' => $this->appID,
|
||||
|
@ -72,10 +72,10 @@ class Apple extends OAuth2
|
|||
])
|
||||
);
|
||||
|
||||
$accessToken = json_decode($accessToken, true);
|
||||
$accessToken = \json_decode($accessToken, true);
|
||||
|
||||
$this->claims = (isset($accessToken['id_token'])) ? explode('.', $accessToken['id_token']) : [0 => '', 1 => ''];
|
||||
$this->claims = (isset($this->claims[1])) ? json_decode(base64_decode($this->claims[1]), true) : [];
|
||||
$this->claims = (isset($accessToken['id_token'])) ? \explode('.', $accessToken['id_token']) : [0 => '', 1 => ''];
|
||||
$this->claims = (isset($this->claims[1])) ? \json_decode(\base64_decode($this->claims[1]), true) : [];
|
||||
|
||||
if (isset($accessToken['access_token'])) {
|
||||
return $accessToken['access_token'];
|
||||
|
@ -135,7 +135,7 @@ class Apple extends OAuth2
|
|||
protected function getAppSecret():string
|
||||
{
|
||||
try {
|
||||
$secret = json_decode($this->appSecret, true);
|
||||
$secret = \json_decode($this->appSecret, true);
|
||||
} catch (\Throwable $th) {
|
||||
throw new Exception('Invalid secret');
|
||||
}
|
||||
|
@ -152,19 +152,19 @@ class Apple extends OAuth2
|
|||
|
||||
$claims = [
|
||||
'iss' => $teamID,
|
||||
'iat' => time(),
|
||||
'exp' => time() + 86400*180,
|
||||
'iat' => \time(),
|
||||
'exp' => \time() + 86400*180,
|
||||
'aud' => 'https://appleid.apple.com',
|
||||
'sub' => $bundleID,
|
||||
];
|
||||
|
||||
$pkey = openssl_pkey_get_private($keyfile);
|
||||
$pkey = \openssl_pkey_get_private($keyfile);
|
||||
|
||||
$payload = $this->encode(json_encode($headers)).'.'.$this->encode(json_encode($claims));
|
||||
$payload = $this->encode(\json_encode($headers)).'.'.$this->encode(\json_encode($claims));
|
||||
|
||||
$signature = '';
|
||||
|
||||
$success = openssl_sign($payload, $signature, $pkey, OPENSSL_ALGO_SHA256);
|
||||
$success = \openssl_sign($payload, $signature, $pkey, OPENSSL_ALGO_SHA256);
|
||||
|
||||
if (!$success) return '';
|
||||
|
||||
|
@ -176,7 +176,7 @@ class Apple extends OAuth2
|
|||
*/
|
||||
protected function encode($data)
|
||||
{
|
||||
return str_replace(['+', '/', '='], ['-', '_', ''], base64_encode($data));
|
||||
return \str_replace(['+', '/', '='], ['-', '_', ''], \base64_encode($data));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -184,8 +184,8 @@ class Apple extends OAuth2
|
|||
*/
|
||||
protected function retrievePositiveInteger(string $data): string
|
||||
{
|
||||
while ('00' === mb_substr($data, 0, 2, '8bit') && mb_substr($data, 2, 2, '8bit') > '7f') {
|
||||
$data = mb_substr($data, 2, null, '8bit');
|
||||
while ('00' === \mb_substr($data, 0, 2, '8bit') && \mb_substr($data, 2, 2, '8bit') > '7f') {
|
||||
$data = \mb_substr($data, 2, null, '8bit');
|
||||
}
|
||||
|
||||
return $data;
|
||||
|
|
|
@ -32,11 +32,11 @@ class Bitbucket extends OAuth2
|
|||
*/
|
||||
public function getLoginURL(): string
|
||||
{
|
||||
return 'https://bitbucket.org/site/oauth2/authorize?'.http_build_query([
|
||||
return 'https://bitbucket.org/site/oauth2/authorize?'.\http_build_query([
|
||||
'response_type' => 'code',
|
||||
'client_id' => $this->appID,
|
||||
'scope' => implode(' ', $this->getScopes()),
|
||||
'state' => json_encode($this->state),
|
||||
'scope' => \implode(' ', $this->getScopes()),
|
||||
'state' => \json_encode($this->state),
|
||||
]);
|
||||
}
|
||||
|
||||
|
@ -54,7 +54,7 @@ class Bitbucket extends OAuth2
|
|||
'POST',
|
||||
'https://bitbucket.org/site/oauth2/access_token',
|
||||
$headers,
|
||||
http_build_query([
|
||||
\http_build_query([
|
||||
'code' => $code,
|
||||
'client_id' => $this->appID,
|
||||
'client_secret' => $this->appSecret,
|
||||
|
@ -62,7 +62,7 @@ class Bitbucket extends OAuth2
|
|||
])
|
||||
);
|
||||
|
||||
$accessToken = json_decode($accessToken, true);
|
||||
$accessToken = \json_decode($accessToken, true);
|
||||
|
||||
if (isset($accessToken['access_token'])) {
|
||||
return $accessToken['access_token'];
|
||||
|
@ -127,11 +127,11 @@ class Bitbucket extends OAuth2
|
|||
protected function getUser(string $accessToken): array
|
||||
{
|
||||
if (empty($this->user)) {
|
||||
$user = $this->request('GET', 'https://api.bitbucket.org/2.0/user?access_token='.urlencode($accessToken));
|
||||
$this->user = json_decode($user, true);
|
||||
$user = $this->request('GET', 'https://api.bitbucket.org/2.0/user?access_token='.\urlencode($accessToken));
|
||||
$this->user = \json_decode($user, true);
|
||||
|
||||
$email = $this->request('GET', 'https://api.bitbucket.org/2.0/user/emails?access_token='.urlencode($accessToken));
|
||||
$this->user['email'] = json_decode($email, true)['values'][0]['email'];
|
||||
$email = $this->request('GET', 'https://api.bitbucket.org/2.0/user/emails?access_token='.\urlencode($accessToken));
|
||||
$this->user['email'] = \json_decode($email, true)['values'][0]['email'];
|
||||
}
|
||||
return $this->user;
|
||||
}
|
||||
|
|
|
@ -44,10 +44,10 @@ class Bitly extends OAuth2
|
|||
public function getLoginURL():string
|
||||
{
|
||||
return $this->endpoint . 'authorize?'.
|
||||
http_build_query([
|
||||
\http_build_query([
|
||||
'client_id' => $this->appID,
|
||||
'redirect_uri' => $this->callback,
|
||||
'state' => json_encode($this->state)
|
||||
'state' => \json_encode($this->state)
|
||||
]);
|
||||
}
|
||||
|
||||
|
@ -62,19 +62,19 @@ class Bitly extends OAuth2
|
|||
'POST',
|
||||
$this->resourceEndpoint . 'oauth/access_token',
|
||||
["Content-Type: application/x-www-form-urlencoded"],
|
||||
http_build_query([
|
||||
\http_build_query([
|
||||
"client_id" => $this->appID,
|
||||
"client_secret" => $this->appSecret,
|
||||
"code" => $code,
|
||||
"redirect_uri" => $this->callback,
|
||||
"state" => json_encode($this->state)
|
||||
"state" => \json_encode($this->state)
|
||||
])
|
||||
);
|
||||
|
||||
$result = null;
|
||||
|
||||
if ($response) {
|
||||
parse_str($response, $result);
|
||||
\parse_str($response, $result);
|
||||
return $result['access_token'];
|
||||
}
|
||||
|
||||
|
@ -137,12 +137,12 @@ class Bitly extends OAuth2
|
|||
protected function getUser(string $accessToken)
|
||||
{
|
||||
$headers = [
|
||||
'Authorization: Bearer '. urlencode($accessToken),
|
||||
'Authorization: Bearer '. \urlencode($accessToken),
|
||||
"Accept: application/json"
|
||||
];
|
||||
|
||||
if (empty($this->user)) {
|
||||
$this->user = json_decode($this->request('GET', $this->resourceEndpoint . "v4/user", $headers), true);
|
||||
$this->user = \json_decode($this->request('GET', $this->resourceEndpoint . "v4/user", $headers), true);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -41,11 +41,11 @@ class Discord extends OAuth2
|
|||
public function getLoginURL(): string
|
||||
{
|
||||
$url = $this->endpoint . '/oauth2/authorize?'.
|
||||
http_build_query([
|
||||
\http_build_query([
|
||||
'response_type' => 'code',
|
||||
'client_id' => $this->appID,
|
||||
'state' => json_encode($this->state),
|
||||
'scope' => implode(' ', $this->getScopes()),
|
||||
'state' => \json_encode($this->state),
|
||||
'scope' => \implode(' ', $this->getScopes()),
|
||||
'redirect_uri' => $this->callback
|
||||
]);
|
||||
|
||||
|
@ -63,17 +63,17 @@ class Discord extends OAuth2
|
|||
'POST',
|
||||
$this->endpoint . '/oauth2/token',
|
||||
['Content-Type: application/x-www-form-urlencoded'],
|
||||
http_build_query([
|
||||
\http_build_query([
|
||||
'grant_type' => 'authorization_code',
|
||||
'code' => $code,
|
||||
'redirect_uri' => $this->callback,
|
||||
'client_id' => $this->appID,
|
||||
'client_secret' => $this->appSecret,
|
||||
'scope' => implode(' ', $this->scope)
|
||||
'scope' => \implode(' ', $this->scope)
|
||||
])
|
||||
);
|
||||
|
||||
$accessToken = json_decode($accessToken, true);
|
||||
$accessToken = \json_decode($accessToken, true);
|
||||
|
||||
if (isset($accessToken['access_token'])) {
|
||||
return $accessToken['access_token'];
|
||||
|
@ -141,9 +141,9 @@ class Discord extends OAuth2
|
|||
$user = $this->request(
|
||||
'GET',
|
||||
$this->endpoint . '/users/@me',
|
||||
['Authorization: Bearer '.urlencode($accessToken)]
|
||||
['Authorization: Bearer '.\urlencode($accessToken)]
|
||||
);
|
||||
$this->user = json_decode($user, true);
|
||||
$this->user = \json_decode($user, true);
|
||||
}
|
||||
|
||||
return $this->user;
|
||||
|
|
|
@ -33,10 +33,10 @@ class Dropbox extends OAuth2
|
|||
*/
|
||||
public function getLoginURL(): string
|
||||
{
|
||||
return 'https://www.dropbox.com/oauth2/authorize?'.http_build_query([
|
||||
return 'https://www.dropbox.com/oauth2/authorize?'.\http_build_query([
|
||||
'client_id' => $this->appID,
|
||||
'redirect_uri' => $this->callback,
|
||||
'state' => json_encode($this->state),
|
||||
'state' => \json_encode($this->state),
|
||||
'response_type' => 'code'
|
||||
]);
|
||||
}
|
||||
|
@ -53,7 +53,7 @@ class Dropbox extends OAuth2
|
|||
'POST',
|
||||
'https://api.dropboxapi.com/oauth2/token',
|
||||
$headers,
|
||||
http_build_query([
|
||||
\http_build_query([
|
||||
'code' => $code,
|
||||
'client_id' => $this->appID,
|
||||
'client_secret' => $this->appSecret,
|
||||
|
@ -62,7 +62,7 @@ class Dropbox extends OAuth2
|
|||
])
|
||||
);
|
||||
|
||||
$accessToken = json_decode($accessToken, true);
|
||||
$accessToken = \json_decode($accessToken, true);
|
||||
|
||||
if (isset($accessToken['access_token'])) {
|
||||
return $accessToken['access_token'];
|
||||
|
@ -127,9 +127,9 @@ class Dropbox extends OAuth2
|
|||
protected function getUser(string $accessToken): array
|
||||
{
|
||||
if (empty($this->user)) {
|
||||
$headers[] = 'Authorization: Bearer '. urlencode($accessToken);
|
||||
$headers[] = 'Authorization: Bearer '. \urlencode($accessToken);
|
||||
$user = $this->request('POST', 'https://api.dropboxapi.com/2/users/get_current_account', $headers);
|
||||
$this->user = json_decode($user, true);
|
||||
$this->user = \json_decode($user, true);
|
||||
}
|
||||
|
||||
return $this->user;
|
||||
|
|
|
@ -36,11 +36,11 @@ class Facebook extends OAuth2
|
|||
*/
|
||||
public function getLoginURL():string
|
||||
{
|
||||
return 'https://www.facebook.com/'.$this->version.'/dialog/oauth?'.http_build_query([
|
||||
return 'https://www.facebook.com/'.$this->version.'/dialog/oauth?'.\http_build_query([
|
||||
'client_id'=> $this->appID,
|
||||
'redirect_uri' => $this->callback,
|
||||
'scope' => implode(' ', $this->getScopes()),
|
||||
'state' => json_encode($this->state)
|
||||
'scope' => \implode(' ', $this->getScopes()),
|
||||
'state' => \json_encode($this->state)
|
||||
]);
|
||||
}
|
||||
|
||||
|
@ -53,7 +53,7 @@ class Facebook extends OAuth2
|
|||
{
|
||||
$accessToken = $this->request(
|
||||
'GET',
|
||||
'https://graph.facebook.com/'.$this->version.'/oauth/access_token?'.http_build_query([
|
||||
'https://graph.facebook.com/'.$this->version.'/oauth/access_token?'.\http_build_query([
|
||||
'client_id' => $this->appID,
|
||||
'redirect_uri' => $this->callback,
|
||||
'client_secret' => $this->appSecret,
|
||||
|
@ -61,7 +61,7 @@ class Facebook extends OAuth2
|
|||
])
|
||||
);
|
||||
|
||||
$accessToken = json_decode($accessToken, true);
|
||||
$accessToken = \json_decode($accessToken, true);
|
||||
|
||||
if (isset($accessToken['access_token'])) {
|
||||
return $accessToken['access_token'];
|
||||
|
@ -126,9 +126,9 @@ class Facebook extends OAuth2
|
|||
protected function getUser(string $accessToken):array
|
||||
{
|
||||
if (empty($this->user)) {
|
||||
$user = $this->request('GET', 'https://graph.facebook.com/'.$this->version.'/me?fields=email,name&access_token='.urlencode($accessToken));
|
||||
$user = $this->request('GET', 'https://graph.facebook.com/'.$this->version.'/me?fields=email,name&access_token='.\urlencode($accessToken));
|
||||
|
||||
$this->user = json_decode($user, true);
|
||||
$this->user = \json_decode($user, true);
|
||||
}
|
||||
|
||||
return $this->user;
|
||||
|
|
|
@ -31,11 +31,11 @@ class Github extends OAuth2
|
|||
*/
|
||||
public function getLoginURL():string
|
||||
{
|
||||
return 'https://github.com/login/oauth/authorize?'. http_build_query([
|
||||
return 'https://github.com/login/oauth/authorize?'. \http_build_query([
|
||||
'client_id' => $this->appID,
|
||||
'redirect_uri' => $this->callback,
|
||||
'scope' => implode(' ', $this->getScopes()),
|
||||
'state' => json_encode($this->state)
|
||||
'scope' => \implode(' ', $this->getScopes()),
|
||||
'state' => \json_encode($this->state)
|
||||
]);
|
||||
|
||||
}
|
||||
|
@ -51,7 +51,7 @@ class Github extends OAuth2
|
|||
'POST',
|
||||
'https://github.com/login/oauth/access_token',
|
||||
[],
|
||||
http_build_query([
|
||||
\http_build_query([
|
||||
'client_id' => $this->appID,
|
||||
'redirect_uri' => $this->callback,
|
||||
'client_secret' => $this->appSecret,
|
||||
|
@ -61,7 +61,7 @@ class Github extends OAuth2
|
|||
|
||||
$output = [];
|
||||
|
||||
parse_str($accessToken, $output);
|
||||
\parse_str($accessToken, $output);
|
||||
|
||||
if (isset($output['access_token'])) {
|
||||
return $output['access_token'];
|
||||
|
@ -93,7 +93,7 @@ class Github extends OAuth2
|
|||
*/
|
||||
public function getUserEmail(string $accessToken):string
|
||||
{
|
||||
$emails = json_decode($this->request('GET', 'https://api.github.com/user/emails', ['Authorization: token '.urlencode($accessToken)]), true);
|
||||
$emails = \json_decode($this->request('GET', 'https://api.github.com/user/emails', ['Authorization: token '.\urlencode($accessToken)]), true);
|
||||
|
||||
foreach ($emails as $email) {
|
||||
if ($email['primary'] && $email['verified']) {
|
||||
|
@ -128,7 +128,7 @@ class Github extends OAuth2
|
|||
protected function getUser(string $accessToken)
|
||||
{
|
||||
if (empty($this->user)) {
|
||||
$this->user = json_decode($this->request('GET', 'https://api.github.com/user', ['Authorization: token '.urlencode($accessToken)]), true);
|
||||
$this->user = \json_decode($this->request('GET', 'https://api.github.com/user', ['Authorization: token '.\urlencode($accessToken)]), true);
|
||||
}
|
||||
|
||||
return $this->user;
|
||||
|
|
|
@ -34,11 +34,11 @@ class Gitlab extends OAuth2
|
|||
*/
|
||||
public function getLoginURL(): string
|
||||
{
|
||||
return 'https://gitlab.com/oauth/authorize?'.http_build_query([
|
||||
return 'https://gitlab.com/oauth/authorize?'.\http_build_query([
|
||||
'client_id' => $this->appID,
|
||||
'redirect_uri' => $this->callback,
|
||||
'scope' => implode(' ', $this->getScopes()),
|
||||
'state' => json_encode($this->state),
|
||||
'scope' => \implode(' ', $this->getScopes()),
|
||||
'state' => \json_encode($this->state),
|
||||
'response_type' => 'code'
|
||||
]);
|
||||
}
|
||||
|
@ -52,7 +52,7 @@ class Gitlab extends OAuth2
|
|||
{
|
||||
$accessToken = $this->request(
|
||||
'POST',
|
||||
'https://gitlab.com/oauth/token?'.http_build_query([
|
||||
'https://gitlab.com/oauth/token?'.\http_build_query([
|
||||
'code' => $code,
|
||||
'client_id' => $this->appID,
|
||||
'client_secret' => $this->appSecret,
|
||||
|
@ -61,7 +61,7 @@ class Gitlab extends OAuth2
|
|||
])
|
||||
);
|
||||
|
||||
$accessToken = json_decode($accessToken, true);
|
||||
$accessToken = \json_decode($accessToken, true);
|
||||
|
||||
if (isset($accessToken['access_token'])) {
|
||||
return $accessToken['access_token'];
|
||||
|
@ -126,8 +126,8 @@ class Gitlab extends OAuth2
|
|||
protected function getUser(string $accessToken): array
|
||||
{
|
||||
if (empty($this->user)) {
|
||||
$user = $this->request('GET', 'https://gitlab.com/api/v4/user?access_token='.urlencode($accessToken));
|
||||
$this->user = json_decode($user, true);
|
||||
$user = $this->request('GET', 'https://gitlab.com/api/v4/user?access_token='.\urlencode($accessToken));
|
||||
$this->user = \json_decode($user, true);
|
||||
}
|
||||
|
||||
return $this->user;
|
||||
|
|
|
@ -43,11 +43,11 @@ class Google extends OAuth2
|
|||
*/
|
||||
public function getLoginURL(): string
|
||||
{
|
||||
return 'https://accounts.google.com/o/oauth2/v2/auth?'. http_build_query([
|
||||
return 'https://accounts.google.com/o/oauth2/v2/auth?'. \http_build_query([
|
||||
'client_id' => $this->appID,
|
||||
'redirect_uri' => $this->callback,
|
||||
'scope' => implode(' ', $this->getScopes()),
|
||||
'state' => json_encode($this->state),
|
||||
'scope' => \implode(' ', $this->getScopes()),
|
||||
'state' => \json_encode($this->state),
|
||||
'response_type' => 'code'
|
||||
]);
|
||||
}
|
||||
|
@ -61,7 +61,7 @@ class Google extends OAuth2
|
|||
{
|
||||
$accessToken = $this->request(
|
||||
'POST',
|
||||
'https://oauth2.googleapis.com/token?'.http_build_query([
|
||||
'https://oauth2.googleapis.com/token?'.\http_build_query([
|
||||
'code' => $code,
|
||||
'client_id' => $this->appID,
|
||||
'client_secret' => $this->appSecret,
|
||||
|
@ -71,7 +71,7 @@ class Google extends OAuth2
|
|||
])
|
||||
);
|
||||
|
||||
$accessToken = json_decode($accessToken, true);
|
||||
$accessToken = \json_decode($accessToken, true);
|
||||
|
||||
if (isset($accessToken['access_token'])) {
|
||||
return $accessToken['access_token'];
|
||||
|
@ -136,8 +136,8 @@ class Google extends OAuth2
|
|||
protected function getUser(string $accessToken): array
|
||||
{
|
||||
if (empty($this->user)) {
|
||||
$user = $this->request('GET', 'https://www.googleapis.com/oauth2/v2/userinfo?access_token='.urlencode($accessToken));
|
||||
$this->user = json_decode($user, true);
|
||||
$user = $this->request('GET', 'https://www.googleapis.com/oauth2/v2/userinfo?access_token='.\urlencode($accessToken));
|
||||
$this->user = \json_decode($user, true);
|
||||
}
|
||||
|
||||
return $this->user;
|
||||
|
|
|
@ -45,12 +45,12 @@ class LinkedIn extends OAuth2
|
|||
*/
|
||||
public function getLoginURL():string
|
||||
{
|
||||
return 'https://www.linkedin.com/oauth/v2/authorization?'.http_build_query([
|
||||
return 'https://www.linkedin.com/oauth/v2/authorization?'.\http_build_query([
|
||||
'response_type' => 'code',
|
||||
'client_id' => $this->appID,
|
||||
'redirect_uri' => $this->callback,
|
||||
'scope' => implode(' ', $this->getScopes()),
|
||||
'state' => json_encode($this->state),
|
||||
'scope' => \implode(' ', $this->getScopes()),
|
||||
'state' => \json_encode($this->state),
|
||||
]);
|
||||
}
|
||||
|
||||
|
@ -65,7 +65,7 @@ class LinkedIn extends OAuth2
|
|||
'POST',
|
||||
'https://www.linkedin.com/oauth/v2/accessToken',
|
||||
['Content-Type: application/x-www-form-urlencoded'],
|
||||
http_build_query([
|
||||
\http_build_query([
|
||||
'grant_type' => 'authorization_code',
|
||||
'code' => $code,
|
||||
'redirect_uri' => $this->callback,
|
||||
|
@ -74,7 +74,7 @@ class LinkedIn extends OAuth2
|
|||
])
|
||||
);
|
||||
|
||||
$accessToken = json_decode($accessToken, true);
|
||||
$accessToken = \json_decode($accessToken, true);
|
||||
|
||||
if (isset($accessToken['access_token'])) {
|
||||
return $accessToken['access_token'];
|
||||
|
@ -106,7 +106,7 @@ class LinkedIn extends OAuth2
|
|||
*/
|
||||
public function getUserEmail(string $accessToken):string
|
||||
{
|
||||
$email = json_decode($this->request('GET', 'https://api.linkedin.com/v2/emailAddress?q=members&projection=(elements*(handle~))', ['Authorization: Bearer '.urlencode($accessToken)]), true);
|
||||
$email = \json_decode($this->request('GET', 'https://api.linkedin.com/v2/emailAddress?q=members&projection=(elements*(handle~))', ['Authorization: Bearer '.\urlencode($accessToken)]), true);
|
||||
|
||||
if (
|
||||
isset($email['elements']) &&
|
||||
|
@ -149,7 +149,7 @@ class LinkedIn extends OAuth2
|
|||
protected function getUser(string $accessToken)
|
||||
{
|
||||
if (empty($this->user)) {
|
||||
$this->user = json_decode($this->request('GET', 'https://api.linkedin.com/v2/me', ['Authorization: Bearer '.urlencode($accessToken)]), true);
|
||||
$this->user = \json_decode($this->request('GET', 'https://api.linkedin.com/v2/me', ['Authorization: Bearer '.\urlencode($accessToken)]), true);
|
||||
}
|
||||
|
||||
return $this->user;
|
||||
|
|
|
@ -36,11 +36,11 @@ class Microsoft extends OAuth2
|
|||
*/
|
||||
public function getLoginURL(): string
|
||||
{
|
||||
return 'https://login.microsoftonline.com/common/oauth2/v2.0/authorize?'.http_build_query([
|
||||
return 'https://login.microsoftonline.com/common/oauth2/v2.0/authorize?'.\http_build_query([
|
||||
'client_id' => $this->appID,
|
||||
'redirect_uri' => $this->callback,
|
||||
'state'=> json_encode($this->state),
|
||||
'scope'=> implode(' ', $this->getScopes()),
|
||||
'state'=> \json_encode($this->state),
|
||||
'scope'=> \implode(' ', $this->getScopes()),
|
||||
'response_type' => 'code',
|
||||
'response_mode' => 'query'
|
||||
]);
|
||||
|
@ -59,17 +59,17 @@ class Microsoft extends OAuth2
|
|||
'POST',
|
||||
'https://login.microsoftonline.com/common/oauth2/v2.0/token',
|
||||
$headers,
|
||||
http_build_query([
|
||||
\http_build_query([
|
||||
'code' => $code,
|
||||
'client_id' => $this->appID,
|
||||
'client_secret' => $this->appSecret,
|
||||
'redirect_uri' => $this->callback,
|
||||
'scope' => implode(' ', $this->getScopes()),
|
||||
'scope' => \implode(' ', $this->getScopes()),
|
||||
'grant_type' => 'authorization_code'
|
||||
])
|
||||
);
|
||||
|
||||
$accessToken = json_decode($accessToken, true);
|
||||
$accessToken = \json_decode($accessToken, true);
|
||||
|
||||
if (isset($accessToken['access_token'])) {
|
||||
return $accessToken['access_token'];
|
||||
|
@ -134,9 +134,9 @@ class Microsoft extends OAuth2
|
|||
protected function getUser(string $accessToken): array
|
||||
{
|
||||
if (empty($this->user)) {
|
||||
$headers[] = 'Authorization: Bearer '. urlencode($accessToken);
|
||||
$headers[] = 'Authorization: Bearer '. \urlencode($accessToken);
|
||||
$user = $this->request('GET', 'https://graph.microsoft.com/v1.0/me', $headers);
|
||||
$this->user = json_decode($user, true);
|
||||
$this->user = \json_decode($user, true);
|
||||
}
|
||||
|
||||
return $this->user;
|
||||
|
|
|
@ -36,11 +36,11 @@ class Mock extends OAuth2
|
|||
*/
|
||||
public function getLoginURL():string
|
||||
{
|
||||
return 'http://localhost/'.$this->version.'/mock/tests/general/oauth2?'. http_build_query([
|
||||
return 'http://localhost/'.$this->version.'/mock/tests/general/oauth2?'. \http_build_query([
|
||||
'client_id' => $this->appID,
|
||||
'redirect_uri' => $this->callback,
|
||||
'scope' => implode(' ', $this->getScopes()),
|
||||
'state' => json_encode($this->state)
|
||||
'scope' => \implode(' ', $this->getScopes()),
|
||||
'state' => \json_encode($this->state)
|
||||
]);
|
||||
}
|
||||
|
||||
|
@ -54,7 +54,7 @@ class Mock extends OAuth2
|
|||
$accessToken = $this->request(
|
||||
'GET',
|
||||
'http://localhost/'.$this->version.'/mock/tests/general/oauth2/token?'.
|
||||
http_build_query([
|
||||
\http_build_query([
|
||||
'client_id' => $this->appID,
|
||||
'redirect_uri' => $this->callback,
|
||||
'client_secret' => $this->appSecret,
|
||||
|
@ -62,7 +62,7 @@ class Mock extends OAuth2
|
|||
])
|
||||
);
|
||||
|
||||
$accessToken = json_decode($accessToken, true); //
|
||||
$accessToken = \json_decode($accessToken, true); //
|
||||
|
||||
if (isset($accessToken['access_token'])) {
|
||||
return $accessToken['access_token'];
|
||||
|
@ -127,9 +127,9 @@ class Mock extends OAuth2
|
|||
protected function getUser(string $accessToken):array
|
||||
{
|
||||
if (empty($this->user)) {
|
||||
$user = $this->request('GET', 'http://localhost/'.$this->version.'/mock/tests/general/oauth2/user?token='.urlencode($accessToken));
|
||||
$user = $this->request('GET', 'http://localhost/'.$this->version.'/mock/tests/general/oauth2/user?token='.\urlencode($accessToken));
|
||||
|
||||
$this->user = json_decode($user, true);
|
||||
$this->user = \json_decode($user, true);
|
||||
}
|
||||
|
||||
return $this->user;
|
||||
|
|
|
@ -50,14 +50,14 @@ class Paypal extends OAuth2
|
|||
public function getLoginURL(): string
|
||||
{
|
||||
$url = $this->endpoint[$this->environment] . 'connect/?'.
|
||||
http_build_query([
|
||||
\http_build_query([
|
||||
'flowEntry' => 'static',
|
||||
'response_type' => 'code',
|
||||
'client_id' => $this->appID,
|
||||
'scope' => implode(' ', $this->getScopes()),
|
||||
'scope' => \implode(' ', $this->getScopes()),
|
||||
// paypal is not accepting localhost string into return uri
|
||||
'redirect_uri' => str_replace("localhost", "127.0.0.1", $this->callback),
|
||||
'state' => json_encode($this->state),
|
||||
'redirect_uri' => \str_replace("localhost", "127.0.0.1", $this->callback),
|
||||
'state' => \json_encode($this->state),
|
||||
]);
|
||||
|
||||
return $url;
|
||||
|
@ -73,15 +73,15 @@ class Paypal extends OAuth2
|
|||
$accessToken = $this->request(
|
||||
'POST',
|
||||
$this->resourceEndpoint[$this->environment] . 'oauth2/token',
|
||||
['Authorization: Basic ' . base64_encode($this->appID . ':' . $this->appSecret)],
|
||||
http_build_query([
|
||||
['Authorization: Basic ' . \base64_encode($this->appID . ':' . $this->appSecret)],
|
||||
\http_build_query([
|
||||
'code' => $code,
|
||||
'grant_type' => 'authorization_code',
|
||||
])
|
||||
);
|
||||
|
||||
|
||||
$accessToken = json_decode($accessToken, true);
|
||||
$accessToken = \json_decode($accessToken, true);
|
||||
|
||||
|
||||
if (isset($accessToken['access_token'])) {
|
||||
|
@ -148,7 +148,7 @@ class Paypal extends OAuth2
|
|||
{
|
||||
$header = [
|
||||
'Content-Type: application/json',
|
||||
'Authorization: Bearer '.urlencode($accessToken),
|
||||
'Authorization: Bearer '.\urlencode($accessToken),
|
||||
];
|
||||
if (empty($this->user)) {
|
||||
$user = $this->request(
|
||||
|
@ -156,7 +156,7 @@ class Paypal extends OAuth2
|
|||
$this->resourceEndpoint[$this->environment] . 'identity/oauth2/userinfo?schema=paypalv1.1',
|
||||
$header
|
||||
);
|
||||
$this->user = json_decode($user, true);
|
||||
$this->user = \json_decode($user, true);
|
||||
}
|
||||
|
||||
return $this->user;
|
||||
|
|
|
@ -38,7 +38,7 @@ class Salesforce extends OAuth2
|
|||
*/
|
||||
public function parseState(string $state)
|
||||
{
|
||||
return json_decode(html_entity_decode($state), true);
|
||||
return \json_decode(\html_entity_decode($state), true);
|
||||
}
|
||||
|
||||
|
||||
|
@ -47,12 +47,12 @@ class Salesforce extends OAuth2
|
|||
*/
|
||||
public function getLoginURL(): string
|
||||
{
|
||||
return 'https://login.salesforce.com/services/oauth2/authorize?'.http_build_query([
|
||||
return 'https://login.salesforce.com/services/oauth2/authorize?'.\http_build_query([
|
||||
'response_type' => 'code',
|
||||
'client_id' => $this->appID,
|
||||
'redirect_uri'=> $this->callback,
|
||||
'scope'=> implode(' ', $this->getScopes()),
|
||||
'state' => json_encode($this->state)
|
||||
'scope'=> \implode(' ', $this->getScopes()),
|
||||
'state' => \json_encode($this->state)
|
||||
]);
|
||||
}
|
||||
|
||||
|
@ -64,7 +64,7 @@ class Salesforce extends OAuth2
|
|||
public function getAccessToken(string $code): string
|
||||
{
|
||||
$headers = [
|
||||
"Authorization: Basic " . base64_encode($this->appID . ":" . $this->appSecret),
|
||||
"Authorization: Basic " . \base64_encode($this->appID . ":" . $this->appSecret),
|
||||
"Content-Type: application/x-www-form-urlencoded",
|
||||
];
|
||||
|
||||
|
@ -72,13 +72,13 @@ class Salesforce extends OAuth2
|
|||
'POST',
|
||||
'https://login.salesforce.com/services/oauth2/token',
|
||||
$headers,
|
||||
http_build_query([
|
||||
\http_build_query([
|
||||
'code' => $code,
|
||||
'redirect_uri' => $this->callback ,
|
||||
'grant_type' => 'authorization_code'
|
||||
])
|
||||
);
|
||||
$accessToken = json_decode($accessToken, true);
|
||||
$accessToken = \json_decode($accessToken, true);
|
||||
|
||||
if (isset($accessToken['access_token'])) {
|
||||
return $accessToken['access_token'];
|
||||
|
@ -143,8 +143,8 @@ class Salesforce extends OAuth2
|
|||
protected function getUser(string $accessToken): array
|
||||
{
|
||||
if (empty($this->user)) {
|
||||
$user = $this->request('GET', 'https://login.salesforce.com/services/oauth2/userinfo?access_token='.urlencode($accessToken));
|
||||
$this->user = json_decode($user, true);
|
||||
$user = $this->request('GET', 'https://login.salesforce.com/services/oauth2/userinfo?access_token='.\urlencode($accessToken));
|
||||
$this->user = \json_decode($user, true);
|
||||
}
|
||||
return $this->user;
|
||||
}
|
||||
|
|
|
@ -35,11 +35,11 @@ class Slack extends OAuth2
|
|||
public function getLoginURL():string
|
||||
{
|
||||
// https://api.slack.com/docs/oauth#step_1_-_sending_users_to_authorize_and_or_install
|
||||
return 'https://slack.com/oauth/authorize?'.http_build_query([
|
||||
return 'https://slack.com/oauth/authorize?'.\http_build_query([
|
||||
'client_id'=> $this->appID,
|
||||
'scope' => implode(' ', $this->getScopes()),
|
||||
'scope' => \implode(' ', $this->getScopes()),
|
||||
'redirect_uri' => $this->callback,
|
||||
'state' => json_encode($this->state)
|
||||
'state' => \json_encode($this->state)
|
||||
]);
|
||||
}
|
||||
|
||||
|
@ -53,7 +53,7 @@ class Slack extends OAuth2
|
|||
// https://api.slack.com/docs/oauth#step_3_-_exchanging_a_verification_code_for_an_access_token
|
||||
$accessToken = $this->request(
|
||||
'GET',
|
||||
'https://slack.com/api/oauth.access?'.http_build_query([
|
||||
'https://slack.com/api/oauth.access?'.\http_build_query([
|
||||
'client_id' => $this->appID,
|
||||
'client_secret' => $this->appSecret,
|
||||
'code' => $code,
|
||||
|
@ -61,7 +61,7 @@ class Slack extends OAuth2
|
|||
])
|
||||
);
|
||||
|
||||
$accessToken = json_decode($accessToken, true); //
|
||||
$accessToken = \json_decode($accessToken, true); //
|
||||
|
||||
if (isset($accessToken['access_token'])) {
|
||||
return $accessToken['access_token'];
|
||||
|
@ -130,10 +130,10 @@ class Slack extends OAuth2
|
|||
// https://api.slack.com/methods/users.identity
|
||||
$user = $this->request(
|
||||
'GET',
|
||||
'https://slack.com/api/users.identity?token='.urlencode($accessToken)
|
||||
'https://slack.com/api/users.identity?token='.\urlencode($accessToken)
|
||||
);
|
||||
|
||||
$this->user = json_decode($user, true);
|
||||
$this->user = \json_decode($user, true);
|
||||
}
|
||||
|
||||
return $this->user;
|
||||
|
|
|
@ -46,12 +46,12 @@ class Spotify extends OAuth2
|
|||
public function getLoginURL():string
|
||||
{
|
||||
return $this->endpoint . 'authorize?'.
|
||||
http_build_query([
|
||||
\http_build_query([
|
||||
'response_type' => 'code',
|
||||
'client_id' => $this->appID,
|
||||
'scope' => implode(' ', $this->getScopes()),
|
||||
'scope' => \implode(' ', $this->getScopes()),
|
||||
'redirect_uri' => $this->callback,
|
||||
'state' => json_encode($this->state)
|
||||
'state' => \json_encode($this->state)
|
||||
]);
|
||||
}
|
||||
|
||||
|
@ -62,12 +62,12 @@ class Spotify extends OAuth2
|
|||
*/
|
||||
public function getAccessToken(string $code):string
|
||||
{
|
||||
$header = "Authorization: Basic " . base64_encode($this->appID . ":" . $this->appSecret);
|
||||
$result = json_decode($this->request(
|
||||
$header = "Authorization: Basic " . \base64_encode($this->appID . ":" . $this->appSecret);
|
||||
$result = \json_decode($this->request(
|
||||
'POST',
|
||||
$this->endpoint . 'api/token',
|
||||
[$header],
|
||||
http_build_query([
|
||||
\http_build_query([
|
||||
"code" => $code,
|
||||
"grant_type" => "authorization_code",
|
||||
"redirect_uri" => $this->callback
|
||||
|
@ -137,8 +137,8 @@ class Spotify extends OAuth2
|
|||
protected function getUser(string $accessToken)
|
||||
{
|
||||
if (empty($this->user)) {
|
||||
$this->user = json_decode($this->request('GET',
|
||||
$this->resourceEndpoint . "me", ['Authorization: Bearer '.urlencode($accessToken)]), true);
|
||||
$this->user = \json_decode($this->request('GET',
|
||||
$this->resourceEndpoint . "me", ['Authorization: Bearer '.\urlencode($accessToken)]), true);
|
||||
}
|
||||
|
||||
return $this->user;
|
||||
|
|
|
@ -46,13 +46,13 @@ class Twitch extends OAuth2
|
|||
public function getLoginURL():string
|
||||
{
|
||||
return $this->endpoint . 'authorize?'.
|
||||
http_build_query([
|
||||
\http_build_query([
|
||||
'response_type' => 'code',
|
||||
'client_id' => $this->appID,
|
||||
'scope' => implode(' ', $this->getScopes()),
|
||||
'scope' => \implode(' ', $this->getScopes()),
|
||||
'redirect_uri' => $this->callback,
|
||||
'force_verify' => true,
|
||||
'state' => json_encode($this->state)
|
||||
'state' => \json_encode($this->state)
|
||||
]);
|
||||
}
|
||||
|
||||
|
@ -63,11 +63,11 @@ class Twitch extends OAuth2
|
|||
*/
|
||||
public function getAccessToken(string $code):string
|
||||
{
|
||||
$result = json_decode($this->request(
|
||||
$result = \json_decode($this->request(
|
||||
'POST',
|
||||
$this->endpoint . 'token',
|
||||
[],
|
||||
http_build_query([
|
||||
\http_build_query([
|
||||
"client_id" => $this->appID,
|
||||
"client_secret" => $this->appSecret,
|
||||
"code" => $code,
|
||||
|
@ -139,8 +139,8 @@ class Twitch extends OAuth2
|
|||
protected function getUser(string $accessToken)
|
||||
{
|
||||
if (empty($this->user)) {
|
||||
$this->user = json_decode($this->request('GET',
|
||||
$this->resourceEndpoint, ['Authorization: Bearer '.urlencode($accessToken)]), true)['data']['0'];
|
||||
$this->user = \json_decode($this->request('GET',
|
||||
$this->resourceEndpoint, ['Authorization: Bearer '.\urlencode($accessToken)]), true)['data']['0'];
|
||||
}
|
||||
|
||||
return $this->user;
|
||||
|
|
|
@ -44,13 +44,13 @@ class Vk extends OAuth2
|
|||
*/
|
||||
public function getLoginURL(): string
|
||||
{
|
||||
return 'https://oauth.vk.com/authorize?' . http_build_query([
|
||||
return 'https://oauth.vk.com/authorize?' . \http_build_query([
|
||||
'client_id' => $this->appID,
|
||||
'redirect_uri' => $this->callback,
|
||||
'response_type' => 'code',
|
||||
'state' => json_encode($this->state),
|
||||
'state' => \json_encode($this->state),
|
||||
'v' => $this->version,
|
||||
'scope' => implode(' ', $this->getScopes())
|
||||
'scope' => \implode(' ', $this->getScopes())
|
||||
]);
|
||||
}
|
||||
|
||||
|
@ -66,14 +66,14 @@ class Vk extends OAuth2
|
|||
'POST',
|
||||
'https://oauth.vk.com/access_token?',
|
||||
$headers,
|
||||
http_build_query([
|
||||
\http_build_query([
|
||||
'code' => $code,
|
||||
'client_id' => $this->appID,
|
||||
'client_secret' => $this->appSecret,
|
||||
'redirect_uri' => $this->callback
|
||||
])
|
||||
);
|
||||
$accessToken = json_decode($accessToken, true);
|
||||
$accessToken = \json_decode($accessToken, true);
|
||||
|
||||
if (isset($accessToken['email'])) {
|
||||
$this->user['email'] = $accessToken['email'];
|
||||
|
@ -147,14 +147,14 @@ class Vk extends OAuth2
|
|||
if (empty($this->user['name'])) {
|
||||
$user = $this->request(
|
||||
'GET',
|
||||
'https://api.vk.com/method/users.get?'. http_build_query([
|
||||
'https://api.vk.com/method/users.get?'. \http_build_query([
|
||||
'v' => $this->version,
|
||||
'fields' => 'id,name,email,first_name,last_name',
|
||||
'access_token' => $accessToken
|
||||
])
|
||||
);
|
||||
|
||||
$user = json_decode($user, true);
|
||||
$user = \json_decode($user, true);
|
||||
$this->user['name'] = $user['response'][0]['first_name'] ." ".$user['response'][0]['last_name'];
|
||||
}
|
||||
return $this->user;
|
||||
|
|
|
@ -49,7 +49,7 @@ class Yahoo extends OAuth2
|
|||
*/
|
||||
public function parseState(string $state)
|
||||
{
|
||||
return json_decode(html_entity_decode($state), true);
|
||||
return \json_decode(\html_entity_decode($state), true);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -58,12 +58,12 @@ class Yahoo extends OAuth2
|
|||
public function getLoginURL():string
|
||||
{
|
||||
return $this->endpoint . 'request_auth?'.
|
||||
http_build_query([
|
||||
\http_build_query([
|
||||
'response_type' => 'code',
|
||||
'client_id' => $this->appID,
|
||||
'scope' => implode(' ', $this->getScopes()),
|
||||
'scope' => \implode(' ', $this->getScopes()),
|
||||
'redirect_uri' => $this->callback,
|
||||
'state' => json_encode($this->state)
|
||||
'state' => \json_encode($this->state)
|
||||
]);
|
||||
}
|
||||
|
||||
|
@ -75,15 +75,15 @@ class Yahoo extends OAuth2
|
|||
public function getAccessToken(string $code):string
|
||||
{
|
||||
$header = [
|
||||
"Authorization: Basic " . base64_encode($this->appID . ":" . $this->appSecret),
|
||||
"Authorization: Basic " . \base64_encode($this->appID . ":" . $this->appSecret),
|
||||
"Content-Type: application/x-www-form-urlencoded",
|
||||
];
|
||||
|
||||
$result = json_decode($this->request(
|
||||
$result = \json_decode($this->request(
|
||||
'POST',
|
||||
$this->endpoint . 'get_token',
|
||||
$header,
|
||||
http_build_query([
|
||||
\http_build_query([
|
||||
"code" => $code,
|
||||
"grant_type" => "authorization_code",
|
||||
"redirect_uri" => $this->callback
|
||||
|
@ -153,8 +153,8 @@ class Yahoo extends OAuth2
|
|||
protected function getUser(string $accessToken)
|
||||
{
|
||||
if (empty($this->user)) {
|
||||
$this->user = json_decode($this->request('GET',
|
||||
$this->resourceEndpoint, ['Authorization: Bearer '.urlencode($accessToken)]), true);
|
||||
$this->user = \json_decode($this->request('GET',
|
||||
$this->resourceEndpoint, ['Authorization: Bearer '.\urlencode($accessToken)]), true);
|
||||
}
|
||||
|
||||
return $this->user;
|
||||
|
|
|
@ -36,7 +36,7 @@ class Yandex extends OAuth2
|
|||
*/
|
||||
public function parseState(string $state)
|
||||
{
|
||||
return json_decode(html_entity_decode($state), true);
|
||||
return \json_decode(\html_entity_decode($state), true);
|
||||
}
|
||||
|
||||
|
||||
|
@ -45,11 +45,11 @@ class Yandex extends OAuth2
|
|||
*/
|
||||
public function getLoginURL(): string
|
||||
{
|
||||
return 'https://oauth.yandex.com/authorize?'.http_build_query([
|
||||
return 'https://oauth.yandex.com/authorize?'.\http_build_query([
|
||||
'response_type' => 'code',
|
||||
'client_id' => $this->appID,
|
||||
'scope'=> implode(' ', $this->getScopes()),
|
||||
'state' => json_encode($this->state)
|
||||
'scope'=> \implode(' ', $this->getScopes()),
|
||||
'state' => \json_encode($this->state)
|
||||
]);
|
||||
}
|
||||
|
||||
|
@ -61,7 +61,7 @@ class Yandex extends OAuth2
|
|||
public function getAccessToken(string $code): string
|
||||
{
|
||||
$headers = [
|
||||
"Authorization: Basic " . base64_encode($this->appID . ":" . $this->appSecret),
|
||||
"Authorization: Basic " . \base64_encode($this->appID . ":" . $this->appSecret),
|
||||
"Content-Type: application/x-www-form-urlencoded",
|
||||
];
|
||||
|
||||
|
@ -69,12 +69,12 @@ class Yandex extends OAuth2
|
|||
'POST',
|
||||
'https://oauth.yandex.com/token',
|
||||
$headers,
|
||||
http_build_query([
|
||||
\http_build_query([
|
||||
'code' => $code,
|
||||
'grant_type' => 'authorization_code'
|
||||
])
|
||||
);
|
||||
$accessToken = json_decode($accessToken, true);
|
||||
$accessToken = \json_decode($accessToken, true);
|
||||
|
||||
if (isset($accessToken['access_token'])) {
|
||||
return $accessToken['access_token'];
|
||||
|
@ -139,11 +139,11 @@ class Yandex extends OAuth2
|
|||
protected function getUser(string $accessToken): array
|
||||
{
|
||||
if (empty($this->user)) {
|
||||
$user = $this->request('GET', 'https://login.yandex.ru/info?'.http_build_query([
|
||||
$user = $this->request('GET', 'https://login.yandex.ru/info?'.\http_build_query([
|
||||
'format' => 'json',
|
||||
'oauth_token' => $accessToken
|
||||
]));
|
||||
$this->user = json_decode($user, true);
|
||||
$this->user = \json_decode($user, true);
|
||||
}
|
||||
return $this->user;
|
||||
}
|
||||
|
|
|
@ -34,7 +34,7 @@ class Password extends Validator
|
|||
*/
|
||||
public function isValid($value)
|
||||
{
|
||||
if (strlen($value) < 6 || strlen($value) > 32) {
|
||||
if (\strlen($value) < 6 || \strlen($value) > 32) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
@ -113,11 +113,11 @@ class MySQL extends Adapter
|
|||
$output = [
|
||||
'$id' => null,
|
||||
'$collection' => null,
|
||||
'$permissions' => (!empty($document['permissions'])) ? json_decode($document['permissions'], true) : [],
|
||||
'$permissions' => (!empty($document['permissions'])) ? \json_decode($document['permissions'], true) : [],
|
||||
];
|
||||
|
||||
foreach ($properties as &$property) {
|
||||
settype($property['value'], $property['primitive']);
|
||||
\settype($property['value'], $property['primitive']);
|
||||
|
||||
if ($property['array']) {
|
||||
$output[$property['key']][] = $property['value'];
|
||||
|
@ -154,9 +154,9 @@ class MySQL extends Adapter
|
|||
public function createDocument(array $data = [], array $unique = [])
|
||||
{
|
||||
$order = 0;
|
||||
$data = array_merge(['$id' => null, '$permissions' => []], $data); // Merge data with default params
|
||||
$signature = md5(json_encode($data, true));
|
||||
$revision = uniqid('', true);
|
||||
$data = \array_merge(['$id' => null, '$permissions' => []], $data); // Merge data with default params
|
||||
$signature = \md5(\json_encode($data, true));
|
||||
$revision = \uniqid('', true);
|
||||
$data['$id'] = (empty($data['$id'])) ? null : $data['$id'];
|
||||
|
||||
/*
|
||||
|
@ -192,7 +192,7 @@ class MySQL extends Adapter
|
|||
SET `key` = :key;
|
||||
');
|
||||
|
||||
$st->bindValue(':key', md5($data['$collection'].':'.$key.'='.$value), PDO::PARAM_STR);
|
||||
$st->bindValue(':key', \md5($data['$collection'].':'.$key.'='.$value), PDO::PARAM_STR);
|
||||
|
||||
if(!$st->execute()) {
|
||||
throw new Duplicate('Duplicated Property: '.$key.'='.$value);
|
||||
|
@ -213,9 +213,9 @@ class MySQL extends Adapter
|
|||
$st1->bindValue(':uid', $data['$id'], PDO::PARAM_STR);
|
||||
$st1->bindValue(':revision', $revision, PDO::PARAM_STR);
|
||||
$st1->bindValue(':signature', $signature, PDO::PARAM_STR);
|
||||
$st1->bindValue(':createdAt', date('Y-m-d H:i:s', time()), PDO::PARAM_STR);
|
||||
$st1->bindValue(':updatedAt', date('Y-m-d H:i:s', time()), PDO::PARAM_STR);
|
||||
$st1->bindValue(':permissions', json_encode($data['$permissions']), PDO::PARAM_STR);
|
||||
$st1->bindValue(':createdAt', \date('Y-m-d H:i:s', \time()), PDO::PARAM_STR);
|
||||
$st1->bindValue(':updatedAt', \date('Y-m-d H:i:s', \time()), PDO::PARAM_STR);
|
||||
$st1->bindValue(':permissions', \json_encode($data['$permissions']), PDO::PARAM_STR);
|
||||
|
||||
$st1->execute();
|
||||
|
||||
|
@ -240,7 +240,7 @@ class MySQL extends Adapter
|
|||
|
||||
foreach ($data as $key => $value) { // Prepare properties data
|
||||
|
||||
if (in_array($key, ['$permissions'])) {
|
||||
if (\in_array($key, ['$permissions'])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -292,8 +292,8 @@ class MySQL extends Adapter
|
|||
}
|
||||
|
||||
foreach ($props as $prop) {
|
||||
if (is_array($prop['value'])) {
|
||||
throw new Exception('Value can\'t be an array: '.json_encode($prop['value']));
|
||||
if (\is_array($prop['value'])) {
|
||||
throw new Exception('Value can\'t be an array: '.\json_encode($prop['value']));
|
||||
}
|
||||
$st2->bindValue(':documentUid', $data['$id'], PDO::PARAM_STR);
|
||||
$st2->bindValue(':documentRevision', $revision, PDO::PARAM_STR);
|
||||
|
@ -481,7 +481,7 @@ class MySQL extends Adapter
|
|||
*/
|
||||
public function getCollection(array $options)
|
||||
{
|
||||
$start = microtime(true);
|
||||
$start = \microtime(true);
|
||||
$orderCastMap = [
|
||||
'int' => 'UNSIGNED',
|
||||
'string' => 'CHAR',
|
||||
|
@ -494,11 +494,11 @@ class MySQL extends Adapter
|
|||
$options['orderField'] = (empty($options['orderField'])) ? '$id' : $options['orderField']; // Set default order field
|
||||
$options['orderCast'] = (empty($options['orderCast'])) ? 'string' : $options['orderCast']; // Set default order field
|
||||
|
||||
if (!array_key_exists($options['orderCast'], $orderCastMap)) {
|
||||
if (!\array_key_exists($options['orderCast'], $orderCastMap)) {
|
||||
throw new Exception('Invalid order cast');
|
||||
}
|
||||
|
||||
if (!in_array($options['orderType'], $orderTypeMap)) {
|
||||
if (!\in_array($options['orderType'], $orderTypeMap)) {
|
||||
throw new Exception('Invalid order type');
|
||||
}
|
||||
|
||||
|
@ -514,11 +514,11 @@ class MySQL extends Adapter
|
|||
$value = $filter['value'];
|
||||
$operator = $filter['operator'];
|
||||
|
||||
$path = explode('.', $key);
|
||||
$path = \explode('.', $key);
|
||||
$original = $path;
|
||||
|
||||
if (1 < count($path)) {
|
||||
$key = array_pop($path);
|
||||
if (1 < \count($path)) {
|
||||
$key = \array_pop($path);
|
||||
} else {
|
||||
$path = [];
|
||||
}
|
||||
|
@ -535,7 +535,7 @@ class MySQL extends Adapter
|
|||
//if($path == "''") { // Handle direct attributes queries
|
||||
$where[] = 'JOIN `'.$this->getNamespace().".database.properties` b{$i} ON a.uid IS NOT NULL AND b{$i}.documentUid = a.uid AND (b{$i}.key = {$key} AND b{$i}.value {$operator} {$value})";
|
||||
} else { // Handle direct child attributes queries
|
||||
$len = count($original);
|
||||
$len = \count($original);
|
||||
$prev = 'c'.$i;
|
||||
|
||||
foreach ($original as $y => $part) {
|
||||
|
@ -557,10 +557,10 @@ class MySQL extends Adapter
|
|||
}
|
||||
|
||||
// Sorting
|
||||
$orderPath = explode('.', $options['orderField']);
|
||||
$len = count($orderPath);
|
||||
$orderPath = \explode('.', $options['orderField']);
|
||||
$len = \count($orderPath);
|
||||
$orderKey = 'order_b';
|
||||
$part = $this->getPDO()->quote(implode('', $orderPath), PDO::PARAM_STR);
|
||||
$part = $this->getPDO()->quote(\implode('', $orderPath), PDO::PARAM_STR);
|
||||
$orderSelect = "CASE WHEN {$orderKey}.key = {$part} THEN CAST({$orderKey}.value AS {$orderCastMap[$options['orderCast']]}) END AS sort_ff";
|
||||
|
||||
if (1 === $len) {
|
||||
|
@ -606,9 +606,9 @@ class MySQL extends Adapter
|
|||
}
|
||||
|
||||
$select = 'DISTINCT a.uid';
|
||||
$where = implode("\n", $where);
|
||||
$join = implode("\n", $join);
|
||||
$sorts = implode("\n", $sorts);
|
||||
$where = \implode("\n", $where);
|
||||
$join = \implode("\n", $join);
|
||||
$sorts = \implode("\n", $sorts);
|
||||
$range = "LIMIT {$options['offset']}, {$options['limit']}";
|
||||
$roles = [];
|
||||
|
||||
|
@ -624,10 +624,10 @@ class MySQL extends Adapter
|
|||
FROM `".$this->getNamespace().".database.documents` a {$where}{$join}{$sorts}
|
||||
WHERE status = 0
|
||||
{$search}
|
||||
AND (".implode('||', $roles).")
|
||||
AND (".\implode('||', $roles).")
|
||||
ORDER BY sort_ff {$options['orderType']} %s";
|
||||
|
||||
$st = $this->getPDO()->prepare(sprintf($query, $select, $range));
|
||||
$st = $this->getPDO()->prepare(\sprintf($query, $select, $range));
|
||||
|
||||
$st->execute();
|
||||
|
||||
|
@ -638,7 +638,7 @@ class MySQL extends Adapter
|
|||
$results['data'][] = $node['uid'];
|
||||
}
|
||||
|
||||
$count = $this->getPDO()->prepare(sprintf($query, 'count(DISTINCT a.uid) as sum', ''));
|
||||
$count = $this->getPDO()->prepare(\sprintf($query, 'count(DISTINCT a.uid) as sum', ''));
|
||||
|
||||
$count->execute();
|
||||
|
||||
|
@ -647,11 +647,11 @@ class MySQL extends Adapter
|
|||
$this->resetDebug();
|
||||
|
||||
$this
|
||||
->setDebug('query', preg_replace('/\s+/', ' ', sprintf($query, $select, $range)))
|
||||
->setDebug('time', microtime(true) - $start)
|
||||
->setDebug('filters', count($options['filters']))
|
||||
->setDebug('joins', substr_count($query, 'JOIN'))
|
||||
->setDebug('count', count($results['data']))
|
||||
->setDebug('query', \preg_replace('/\s+/', ' ', \sprintf($query, $select, $range)))
|
||||
->setDebug('time', \microtime(true) - $start)
|
||||
->setDebug('filters', \count($options['filters']))
|
||||
->setDebug('joins', \substr_count($query, 'JOIN'))
|
||||
->setDebug('count', \count($results['data']))
|
||||
->setDebug('sum', (int) $count['sum'])
|
||||
->setDebug('documents', $this->count)
|
||||
;
|
||||
|
@ -670,7 +670,7 @@ class MySQL extends Adapter
|
|||
*/
|
||||
public function getCount(array $options)
|
||||
{
|
||||
$start = microtime(true);
|
||||
$start = \microtime(true);
|
||||
$where = [];
|
||||
$join = [];
|
||||
|
||||
|
@ -680,11 +680,11 @@ class MySQL extends Adapter
|
|||
$key = $filter['key'];
|
||||
$value = $filter['value'];
|
||||
$operator = $filter['operator'];
|
||||
$path = explode('.', $key);
|
||||
$path = \explode('.', $key);
|
||||
$original = $path;
|
||||
|
||||
if (1 < count($path)) {
|
||||
$key = array_pop($path);
|
||||
if (1 < \count($path)) {
|
||||
$key = \array_pop($path);
|
||||
} else {
|
||||
$path = [];
|
||||
}
|
||||
|
@ -696,7 +696,7 @@ class MySQL extends Adapter
|
|||
//if($path == "''") { // Handle direct attributes queries
|
||||
$where[] = 'JOIN `'.$this->getNamespace().".database.properties` b{$i} ON a.uid IS NOT NULL AND b{$i}.documentUid = a.uid AND (b{$i}.key = {$key} AND b{$i}.value {$operator} {$value})";
|
||||
} else { // Handle direct child attributes queries
|
||||
$len = count($original);
|
||||
$len = \count($original);
|
||||
$prev = 'c'.$i;
|
||||
|
||||
foreach ($original as $y => $part) {
|
||||
|
@ -714,8 +714,8 @@ class MySQL extends Adapter
|
|||
}
|
||||
}
|
||||
|
||||
$where = implode("\n", $where);
|
||||
$join = implode("\n", $join);
|
||||
$where = \implode("\n", $where);
|
||||
$join = \implode("\n", $join);
|
||||
$func = 'JOIN `'.$this->getNamespace().".database.properties` b_func ON a.uid IS NOT NULL
|
||||
AND a.uid = b_func.documentUid
|
||||
AND (b_func.key = 'sizeOriginal')";
|
||||
|
@ -732,9 +732,9 @@ class MySQL extends Adapter
|
|||
$query = 'SELECT SUM(b_func.value) as result
|
||||
FROM `'.$this->getNamespace().".database.documents` a {$where}{$join}{$func}
|
||||
WHERE status = 0
|
||||
AND (".implode('||', $roles).')';
|
||||
AND (".\implode('||', $roles).')';
|
||||
|
||||
$st = $this->getPDO()->prepare(sprintf($query));
|
||||
$st = $this->getPDO()->prepare(\sprintf($query));
|
||||
|
||||
$st->execute();
|
||||
|
||||
|
@ -743,10 +743,10 @@ class MySQL extends Adapter
|
|||
$this->resetDebug();
|
||||
|
||||
$this
|
||||
->setDebug('query', preg_replace('/\s+/', ' ', sprintf($query)))
|
||||
->setDebug('time', microtime(true) - $start)
|
||||
->setDebug('filters', count($options['filters']))
|
||||
->setDebug('joins', substr_count($query, 'JOIN'))
|
||||
->setDebug('query', \preg_replace('/\s+/', ' ', \sprintf($query)))
|
||||
->setDebug('time', \microtime(true) - $start)
|
||||
->setDebug('filters', \count($options['filters']))
|
||||
->setDebug('joins', \substr_count($query, 'JOIN'))
|
||||
;
|
||||
|
||||
return (int) (isset($result['result'])) ? $result['result'] : 0;
|
||||
|
@ -757,7 +757,7 @@ class MySQL extends Adapter
|
|||
*/
|
||||
public function getId()
|
||||
{
|
||||
$unique = uniqid();
|
||||
$unique = \uniqid();
|
||||
$attempts = 5;
|
||||
|
||||
for ($i = 1; $i <= $attempts; ++$i) {
|
||||
|
@ -801,7 +801,7 @@ class MySQL extends Adapter
|
|||
$operator = null;
|
||||
|
||||
foreach ($operatorsMap as $node) {
|
||||
if (strpos($filter, $node) !== false) {
|
||||
if (\strpos($filter, $node) !== false) {
|
||||
$operator = $node;
|
||||
break;
|
||||
}
|
||||
|
@ -811,9 +811,9 @@ class MySQL extends Adapter
|
|||
throw new Exception('Invalid operator');
|
||||
}
|
||||
|
||||
$filter = explode($operator, $filter);
|
||||
$filter = \explode($operator, $filter);
|
||||
|
||||
if (count($filter) != 2) {
|
||||
if (\count($filter) != 2) {
|
||||
throw new Exception('Invalid filter expression');
|
||||
}
|
||||
|
||||
|
@ -838,7 +838,7 @@ class MySQL extends Adapter
|
|||
*/
|
||||
protected function getDataType($value)
|
||||
{
|
||||
switch (gettype($value)) {
|
||||
switch (\gettype($value)) {
|
||||
|
||||
case 'string':
|
||||
return self::DATA_TYPE_STRING;
|
||||
|
@ -857,7 +857,7 @@ class MySQL extends Adapter
|
|||
break;
|
||||
|
||||
case 'array':
|
||||
if ((bool) count(array_filter(array_keys($value), 'is_string'))) {
|
||||
if ((bool) \count(\array_filter(\array_keys($value), 'is_string'))) {
|
||||
return self::DATA_TYPE_DICTIONARY;
|
||||
}
|
||||
|
||||
|
@ -869,7 +869,7 @@ class MySQL extends Adapter
|
|||
break;
|
||||
}
|
||||
|
||||
throw new Exception('Unknown data type: '.$value.' ('.gettype($value).')');
|
||||
throw new Exception('Unknown data type: '.$value.' ('.\gettype($value).')');
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -42,11 +42,11 @@ class Redis extends Adapter
|
|||
*/
|
||||
public function getDocument($id)
|
||||
{
|
||||
$output = json_decode($this->getRedis()->get($this->getNamespace().':document-'.$id), true);
|
||||
$output = \json_decode($this->getRedis()->get($this->getNamespace().':document-'.$id), true);
|
||||
|
||||
if (!$output) {
|
||||
$output = $this->adapter->getDocument($id);
|
||||
$this->getRedis()->set($this->getNamespace().':document-'.$id, json_encode($output, JSON_UNESCAPED_UNICODE));
|
||||
$this->getRedis()->set($this->getNamespace().':document-'.$id, \json_encode($output, JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
|
||||
$output = $this->parseRelations($output);
|
||||
|
@ -78,7 +78,7 @@ class Redis extends Adapter
|
|||
foreach ($output['temp-relations'] as $i => $relationship) {
|
||||
$node = $relationship['end'];
|
||||
|
||||
$node = (!empty($nodes[$i])) ? $this->parseRelations(json_decode($nodes[$i], true)) : $this->getDocument($node);
|
||||
$node = (!empty($nodes[$i])) ? $this->parseRelations(\json_decode($nodes[$i], true)) : $this->getDocument($node);
|
||||
|
||||
if (empty($node)) {
|
||||
continue;
|
||||
|
@ -196,7 +196,7 @@ class Redis extends Adapter
|
|||
$nodes = (!empty($keys)) ? $this->getRedis()->mget($keys) : [];
|
||||
|
||||
foreach ($data as $i => &$node) {
|
||||
$temp = (!empty($nodes[$i])) ? $this->parseRelations(json_decode($nodes[$i], true)) : $this->getDocument($node);
|
||||
$temp = (!empty($nodes[$i])) ? $this->parseRelations(\json_decode($nodes[$i], true)) : $this->getDocument($node);
|
||||
|
||||
if (!empty($temp)) {
|
||||
$node = $temp;
|
||||
|
|
|
@ -122,7 +122,7 @@ class Database
|
|||
*/
|
||||
public function getCollection(array $options)
|
||||
{
|
||||
$options = array_merge([
|
||||
$options = \array_merge([
|
||||
'offset' => 0,
|
||||
'limit' => 15,
|
||||
'search' => '',
|
||||
|
@ -142,11 +142,11 @@ class Database
|
|||
}
|
||||
|
||||
if ($options['first']) {
|
||||
$results = reset($results);
|
||||
$results = \reset($results);
|
||||
}
|
||||
|
||||
if ($options['last']) {
|
||||
$results = end($results);
|
||||
$results = \end($results);
|
||||
}
|
||||
|
||||
return $results;
|
||||
|
@ -160,7 +160,7 @@ class Database
|
|||
*/
|
||||
public function getDocument($id, $mock = true)
|
||||
{
|
||||
if (is_null($id)) {
|
||||
if (\is_null($id)) {
|
||||
return new Document([]);
|
||||
}
|
||||
|
||||
|
@ -322,7 +322,7 @@ class Database
|
|||
*/
|
||||
public function getCount(array $options)
|
||||
{
|
||||
$options = array_merge([
|
||||
$options = \array_merge([
|
||||
'filters' => [],
|
||||
], $options);
|
||||
|
||||
|
|
|
@ -24,7 +24,7 @@ class Document extends ArrayObject
|
|||
public function __construct($input = null, $flags = 0, $iterator_class = 'ArrayIterator')
|
||||
{
|
||||
foreach ($input as $key => &$value) {
|
||||
if (is_array($value)) {
|
||||
if (\is_array($value)) {
|
||||
if (isset($value['$id']) || isset($value['$collection'])) {
|
||||
$input[$key] = new self($value);
|
||||
} else {
|
||||
|
@ -76,7 +76,7 @@ class Document extends ArrayObject
|
|||
*/
|
||||
public function getAttribute($name, $default = null)
|
||||
{
|
||||
$name = explode('.', $name);
|
||||
$name = \explode('.', $name);
|
||||
|
||||
$temp = &$this;
|
||||
|
||||
|
@ -109,12 +109,12 @@ class Document extends ArrayObject
|
|||
$this[$key] = $value;
|
||||
break;
|
||||
case self::SET_TYPE_APPEND:
|
||||
$this[$key] = (!isset($this[$key]) || !is_array($this[$key])) ? [] : $this[$key];
|
||||
array_push($this[$key], $value);
|
||||
$this[$key] = (!isset($this[$key]) || !\is_array($this[$key])) ? [] : $this[$key];
|
||||
\array_push($this[$key], $value);
|
||||
break;
|
||||
case self::SET_TYPE_PREPEND:
|
||||
$this[$key] = (!isset($this[$key]) || !is_array($this[$key])) ? [] : $this[$key];
|
||||
array_unshift($this[$key], $value);
|
||||
$this[$key] = (!isset($this[$key]) || !\is_array($this[$key])) ? [] : $this[$key];
|
||||
\array_unshift($this[$key], $value);
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -154,15 +154,15 @@ class Document extends ArrayObject
|
|||
*/
|
||||
public function search($key, $value, $scope = null)
|
||||
{
|
||||
$array = (!is_null($scope)) ? $scope : $this;
|
||||
$array = (!\is_null($scope)) ? $scope : $this;
|
||||
|
||||
if (is_array($array) || $array instanceof self) {
|
||||
if (\is_array($array) || $array instanceof self) {
|
||||
if (isset($array[$key]) && $array[$key] == $value) {
|
||||
return $array;
|
||||
}
|
||||
|
||||
foreach ($array as $k => $v) {
|
||||
if ((is_array($v) || $v instanceof self) && (!empty($v))) {
|
||||
if ((\is_array($v) || $v instanceof self) && (!empty($v))) {
|
||||
$result = $this->search($key, $value, $v);
|
||||
|
||||
if (!empty($result)) {
|
||||
|
@ -210,17 +210,17 @@ class Document extends ArrayObject
|
|||
$output = array();
|
||||
|
||||
foreach ($array as $key => &$value) {
|
||||
if (!empty($whitelist) && !in_array($key, $whitelist)) { // Export only whitelisted fields
|
||||
if (!empty($whitelist) && !\in_array($key, $whitelist)) { // Export only whitelisted fields
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!empty($blacklist) && in_array($key, $blacklist)) { // Don't export blacklisted fields
|
||||
if (!empty($blacklist) && \in_array($key, $blacklist)) { // Don't export blacklisted fields
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($value instanceof self) {
|
||||
$output[$key] = $value->getArrayCopy($whitelist, $blacklist);
|
||||
} elseif (is_array($value)) {
|
||||
} elseif (\is_array($value)) {
|
||||
foreach ($value as $childKey => &$child) {
|
||||
if ($child instanceof self) {
|
||||
$output[$key][$childKey] = $child->getArrayCopy($whitelist, $blacklist);
|
||||
|
|
|
@ -75,14 +75,14 @@ class Authorization extends Validator
|
|||
$permission = null;
|
||||
|
||||
foreach ($permissions[$this->action] as $permission) {
|
||||
$permission = str_replace(':{self}', ':'.$this->document->getId(), $permission);
|
||||
$permission = \str_replace(':{self}', ':'.$this->document->getId(), $permission);
|
||||
|
||||
if (in_array($permission, self::getRoles())) {
|
||||
if (\in_array($permission, self::getRoles())) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
$this->message = 'User is missing '.$this->action.' for "'.$permission.'" permission. Only this scopes "'.json_encode(self::getRoles()).'" is given and only this are allowed "'.json_encode($permissions[$this->action]).'".';
|
||||
$this->message = 'User is missing '.$this->action.' for "'.$permission.'" permission. Only this scopes "'.\json_encode(self::getRoles()).'" is given and only this are allowed "'.\json_encode($permissions[$this->action]).'".';
|
||||
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -38,16 +38,16 @@ class Collection extends Structure
|
|||
public function isValid($document)
|
||||
{
|
||||
$document = new Document(
|
||||
array_merge($this->merge, ($document instanceof Document) ? $document->getArrayCopy() : $document)
|
||||
\array_merge($this->merge, ($document instanceof Document) ? $document->getArrayCopy() : $document)
|
||||
);
|
||||
|
||||
if (is_null($document->getCollection())) {
|
||||
if (\is_null($document->getCollection())) {
|
||||
$this->message = 'Missing collection attribute $collection';
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!in_array($document->getCollection(), $this->collections)) {
|
||||
if (!\in_array($document->getCollection(), $this->collections)) {
|
||||
$this->message = 'Collection is not allowed';
|
||||
|
||||
return false;
|
||||
|
|
|
@ -34,15 +34,15 @@ class Key extends Validator
|
|||
*/
|
||||
public function isValid($value)
|
||||
{
|
||||
if(!is_string($value)) {
|
||||
if(!\is_string($value)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (preg_match('/[^A-Za-z0-9\-\_]/', $value)) {
|
||||
if (\preg_match('/[^A-Za-z0-9\-\_]/', $value)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (mb_strlen($value) > 32) {
|
||||
if (\mb_strlen($value) > 32) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
@ -50,21 +50,21 @@ class Permissions extends Validator
|
|||
*/
|
||||
public function isValid($value)
|
||||
{
|
||||
if (!is_array($value) && !empty($value)) {
|
||||
if (!\is_array($value) && !empty($value)) {
|
||||
$this->message = 'Invalid permissions data structure';
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
foreach ($value as $action => $roles) {
|
||||
if (!in_array($action, ['read', 'write'])) {
|
||||
if (!\in_array($action, ['read', 'write'])) {
|
||||
$this->message = 'Unknown action ("'.$action.'")';
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
foreach ($roles as $role) {
|
||||
if (!is_string($role)) {
|
||||
if (!\is_string($role)) {
|
||||
$this->message = 'Permissions role must be a string';
|
||||
|
||||
return false;
|
||||
|
|
|
@ -124,11 +124,11 @@ class Structure extends Validator
|
|||
*/
|
||||
public function isValid($document)
|
||||
{
|
||||
$document = (is_array($document)) ? new Document($document) : $document;
|
||||
$document = (\is_array($document)) ? new Document($document) : $document;
|
||||
|
||||
$this->id = $document->getId();
|
||||
|
||||
if (is_null($document->getCollection())) {
|
||||
if (\is_null($document->getCollection())) {
|
||||
$this->message = 'Missing collection attribute $collection';
|
||||
|
||||
return false;
|
||||
|
@ -136,14 +136,14 @@ class Structure extends Validator
|
|||
|
||||
$collection = $this->getCollection($document->getCollection());
|
||||
|
||||
if (is_null($collection->getId()) || Database::SYSTEM_COLLECTION_COLLECTIONS != $collection->getCollection()) {
|
||||
if (\is_null($collection->getId()) || Database::SYSTEM_COLLECTION_COLLECTIONS != $collection->getCollection()) {
|
||||
$this->message = 'Collection not found';
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
$array = $document->getArrayCopy();
|
||||
$rules = array_merge($this->rules, $collection->getAttribute('rules', []));
|
||||
$rules = \array_merge($this->rules, $collection->getAttribute('rules', []));
|
||||
|
||||
foreach ($rules as $rule) { // Check all required keys are set
|
||||
if (isset($rule['key']) && !isset($array[$rule['key']])
|
||||
|
@ -208,11 +208,11 @@ class Structure extends Validator
|
|||
}
|
||||
|
||||
if (empty($validator)) { // Error creating validator for property
|
||||
$this->message = 'Unknown rule type "'.$ruleType.'" for property "'.htmlspecialchars($key, ENT_QUOTES, 'UTF-8').'"';
|
||||
$this->message = 'Unknown rule type "'.$ruleType.'" for property "'.\htmlspecialchars($key, ENT_QUOTES, 'UTF-8').'"';
|
||||
|
||||
if (empty($ruleType)) {
|
||||
$this->message = 'Unknown property "'.$key.'" type'.
|
||||
'. Make sure to follow '.strtolower($collection->getAttribute('name', 'unknown')).' collection structure';
|
||||
'. Make sure to follow '.\strtolower($collection->getAttribute('name', 'unknown')).' collection structure';
|
||||
}
|
||||
|
||||
return false;
|
||||
|
@ -232,7 +232,7 @@ class Structure extends Validator
|
|||
}
|
||||
|
||||
if ($ruleArray) { // Array of values validation
|
||||
if (!is_array($value)) {
|
||||
if (!\is_array($value)) {
|
||||
$this->message = 'Property "'.$key.'" must be an array';
|
||||
|
||||
return false;
|
||||
|
@ -260,8 +260,8 @@ class Structure extends Validator
|
|||
}
|
||||
|
||||
if (!empty($array)) { // No fields should be left unvalidated
|
||||
$this->message = 'Unknown properties are not allowed ('.implode(', ', array_keys($array)).') for this collection'.
|
||||
'. Make sure to follow '.strtolower($collection->getAttribute('name', 'unknown')).' collection structure';
|
||||
$this->message = 'Unknown properties are not allowed ('.\implode(', ', \array_keys($array)).') for this collection'.
|
||||
'. Make sure to follow '.\strtolower($collection->getAttribute('name', 'unknown')).' collection structure';
|
||||
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -29,7 +29,7 @@ class UID extends Validator
|
|||
*/
|
||||
public function isValid($value)
|
||||
{
|
||||
if (is_numeric($value)) {
|
||||
if (\is_numeric($value)) {
|
||||
//return false;
|
||||
}
|
||||
|
||||
|
|
|
@ -34,12 +34,12 @@ class CNAME extends Validator
|
|||
public function isValid($domain)
|
||||
{
|
||||
try {
|
||||
$records = dns_get_record($domain, DNS_CNAME);
|
||||
$records = \dns_get_record($domain, DNS_CNAME);
|
||||
} catch (\Throwable $th) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if(!$records || !is_array($records)) {
|
||||
if(!$records || !\is_array($records)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
@ -81,7 +81,7 @@ class Origin extends Validator
|
|||
|
||||
public function getDescription()
|
||||
{
|
||||
if(!array_key_exists($this->client, $this->platforms)) {
|
||||
if(!\array_key_exists($this->client, $this->platforms)) {
|
||||
return 'Unsupported platform';
|
||||
}
|
||||
|
||||
|
@ -99,8 +99,8 @@ class Origin extends Validator
|
|||
*/
|
||||
public function isValid($origin)
|
||||
{
|
||||
$scheme = parse_url($origin, PHP_URL_SCHEME);
|
||||
$host = parse_url($origin, PHP_URL_HOST);
|
||||
$scheme = \parse_url($origin, PHP_URL_SCHEME);
|
||||
$host = \parse_url($origin, PHP_URL_HOST);
|
||||
|
||||
$this->host = $host;
|
||||
$this->client = $scheme;
|
||||
|
@ -109,7 +109,7 @@ class Origin extends Validator
|
|||
return true;
|
||||
}
|
||||
|
||||
if(in_array($host, $this->clients)) {
|
||||
if(\in_array($host, $this->clients)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -20,7 +20,7 @@ class OpenSSL
|
|||
*/
|
||||
public static function encrypt($data, $method, $key, $options = 0, $iv = '', &$tag = null, $aad = '', $tag_length = 16)
|
||||
{
|
||||
return openssl_encrypt($data, $method, $key, $options, $iv, $tag, $aad, $tag_length);
|
||||
return \openssl_encrypt($data, $method, $key, $options, $iv, $tag, $aad, $tag_length);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -36,7 +36,7 @@ class OpenSSL
|
|||
*/
|
||||
public static function decrypt($data, $method, $password, $options = 1, $iv = '', $tag = '', $aad = '')
|
||||
{
|
||||
return openssl_decrypt($data, $method, $password, $options, $iv, $tag, $aad);
|
||||
return \openssl_decrypt($data, $method, $password, $options, $iv, $tag, $aad);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -46,7 +46,7 @@ class OpenSSL
|
|||
*/
|
||||
public static function cipherIVLength($method)
|
||||
{
|
||||
return openssl_cipher_iv_length($method);
|
||||
return \openssl_cipher_iv_length($method);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -57,6 +57,6 @@ class OpenSSL
|
|||
*/
|
||||
public static function randomPseudoBytes($length, &$crypto_strong = null)
|
||||
{
|
||||
return openssl_random_pseudo_bytes($length, $crypto_strong);
|
||||
return \openssl_random_pseudo_bytes($length, $crypto_strong);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -112,9 +112,9 @@ class Resize
|
|||
public function save(string $path = null, string $type = '', int $quality = 75)
|
||||
{
|
||||
// Create directory with write permissions
|
||||
if (null !== $path && !file_exists(dirname($path))) {
|
||||
if (!@mkdir(dirname($path), 0755, true)) {
|
||||
throw new Exception('Can\'t create directory '.dirname($path));
|
||||
if (null !== $path && !\file_exists(\dirname($path))) {
|
||||
if (!@\mkdir(\dirname($path), 0755, true)) {
|
||||
throw new Exception('Can\'t create directory '.\dirname($path));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -134,30 +134,30 @@ class Resize
|
|||
//$this->image->setImageFormat('webp');
|
||||
|
||||
$signature = $this->image->getImageSignature();
|
||||
$temp = '/tmp/temp-'.$signature.'.'.strtolower($this->image->getImageFormat());
|
||||
$temp = '/tmp/temp-'.$signature.'.'.\strtolower($this->image->getImageFormat());
|
||||
$output = '/tmp/output-'.$signature.'.webp';
|
||||
|
||||
// save temp
|
||||
$this->image->writeImages($temp, true);
|
||||
|
||||
// convert temp
|
||||
exec("cwebp -quiet -metadata none -q $quality $temp -o $output");
|
||||
\exec("cwebp -quiet -metadata none -q $quality $temp -o $output");
|
||||
|
||||
$data = file_get_contents($output);
|
||||
$data = \file_get_contents($output);
|
||||
|
||||
//load webp
|
||||
if (empty($path)) {
|
||||
return $data;
|
||||
} else {
|
||||
file_put_contents($path, $data, LOCK_EX);
|
||||
\file_put_contents($path, $data, LOCK_EX);
|
||||
}
|
||||
|
||||
$this->image->clear();
|
||||
$this->image->destroy();
|
||||
|
||||
//delete webp
|
||||
unlink($output);
|
||||
unlink($temp);
|
||||
\unlink($output);
|
||||
\unlink($temp);
|
||||
|
||||
return;
|
||||
|
||||
|
@ -165,7 +165,7 @@ class Resize
|
|||
|
||||
case 'png':
|
||||
/* Scale quality from 0-100 to 0-9 */
|
||||
$scaleQuality = round(($quality / 100) * 9);
|
||||
$scaleQuality = \round(($quality / 100) * 9);
|
||||
|
||||
/* Invert quality setting as 0 is best, not 9 */
|
||||
$invertScaleQuality = 9 - $scaleQuality;
|
||||
|
|
|
@ -28,7 +28,7 @@ class GZIP extends Compression
|
|||
*/
|
||||
public function compress(string $data):string
|
||||
{
|
||||
return gzencode($data);
|
||||
return \gzencode($data);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -40,6 +40,6 @@ class GZIP extends Compression
|
|||
*/
|
||||
public function decompress(string $data):string
|
||||
{
|
||||
return gzdecode($data);
|
||||
return \gzdecode($data);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -56,7 +56,7 @@ class Local extends Device
|
|||
$path = '';
|
||||
|
||||
for ($i = 0; $i < 4; ++$i) {
|
||||
$path = ($i < strlen($filename)) ? $path.DIRECTORY_SEPARATOR.$filename[$i] : $path.DIRECTORY_SEPARATOR.'x';
|
||||
$path = ($i < \strlen($filename)) ? $path.DIRECTORY_SEPARATOR.$filename[$i] : $path.DIRECTORY_SEPARATOR.'x';
|
||||
}
|
||||
|
||||
return $this->getRoot().$path.DIRECTORY_SEPARATOR.$filename;
|
||||
|
@ -76,13 +76,13 @@ class Local extends Device
|
|||
*/
|
||||
public function upload($source, $path):bool
|
||||
{
|
||||
if (!file_exists(dirname($path))) { // Checks if directory path to file exists
|
||||
if (!@mkdir(dirname($path), 0755, true)) {
|
||||
throw new Exception('Can\'t create directory: '.dirname($path));
|
||||
if (!\file_exists(\dirname($path))) { // Checks if directory path to file exists
|
||||
if (!@\mkdir(\dirname($path), 0755, true)) {
|
||||
throw new Exception('Can\'t create directory: '.\dirname($path));
|
||||
}
|
||||
}
|
||||
|
||||
if (move_uploaded_file($source, $path)) {
|
||||
if (\move_uploaded_file($source, $path)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -98,7 +98,7 @@ class Local extends Device
|
|||
*/
|
||||
public function read(string $path):string
|
||||
{
|
||||
return file_get_contents($path);
|
||||
return \file_get_contents($path);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -111,13 +111,13 @@ class Local extends Device
|
|||
*/
|
||||
public function write(string $path, string $data):bool
|
||||
{
|
||||
if (!file_exists(dirname($path))) { // Checks if directory path to file exists
|
||||
if (!@mkdir(dirname($path), 0755, true)) {
|
||||
throw new Exception('Can\'t create directory '.dirname($path));
|
||||
if (!\file_exists(\dirname($path))) { // Checks if directory path to file exists
|
||||
if (!@\mkdir(\dirname($path), 0755, true)) {
|
||||
throw new Exception('Can\'t create directory '.\dirname($path));
|
||||
}
|
||||
}
|
||||
|
||||
return file_put_contents($path, $data);
|
||||
return \file_put_contents($path, $data);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -132,13 +132,13 @@ class Local extends Device
|
|||
*/
|
||||
public function move(string $source, string $target):bool
|
||||
{
|
||||
if (!file_exists(dirname($target))) { // Checks if directory path to file exists
|
||||
if (!@mkdir(dirname($target), 0755, true)) {
|
||||
throw new Exception('Can\'t create directory '.dirname($target));
|
||||
if (!\file_exists(\dirname($target))) { // Checks if directory path to file exists
|
||||
if (!@\mkdir(\dirname($target), 0755, true)) {
|
||||
throw new Exception('Can\'t create directory '.\dirname($target));
|
||||
}
|
||||
}
|
||||
|
||||
if (rename($source, $target)) {
|
||||
if (\rename($source, $target)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -157,17 +157,17 @@ class Local extends Device
|
|||
*/
|
||||
public function delete(string $path, bool $recursive = false):bool
|
||||
{
|
||||
if(is_dir($path) && $recursive) {
|
||||
$files = glob($path.'*', GLOB_MARK); // GLOB_MARK adds a slash to directories returned
|
||||
if(\is_dir($path) && $recursive) {
|
||||
$files = \glob($path.'*', GLOB_MARK); // GLOB_MARK adds a slash to directories returned
|
||||
|
||||
foreach($files as $file) {
|
||||
$this->delete($file, true);
|
||||
}
|
||||
|
||||
rmdir($path);
|
||||
\rmdir($path);
|
||||
}
|
||||
elseif(is_file($path)) {
|
||||
return unlink($path);
|
||||
elseif(\is_file($path)) {
|
||||
return \unlink($path);
|
||||
}
|
||||
|
||||
return false;
|
||||
|
@ -184,7 +184,7 @@ class Local extends Device
|
|||
*/
|
||||
public function getFileSize(string $path):int
|
||||
{
|
||||
return filesize($path);
|
||||
return \filesize($path);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -198,7 +198,7 @@ class Local extends Device
|
|||
*/
|
||||
public function getFileMimeType(string $path):string
|
||||
{
|
||||
return mime_content_type($path);
|
||||
return \mime_content_type($path);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -212,7 +212,7 @@ class Local extends Device
|
|||
*/
|
||||
public function getFileHash(string $path):string
|
||||
{
|
||||
return md5_file($path);
|
||||
return \md5_file($path);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -230,27 +230,27 @@ class Local extends Device
|
|||
{
|
||||
$size = 0;
|
||||
|
||||
$directory = opendir($path);
|
||||
$directory = \opendir($path);
|
||||
|
||||
if (!$directory) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
while (($file = readdir($directory)) !== false) {
|
||||
while (($file = \readdir($directory)) !== false) {
|
||||
// Skip file pointers
|
||||
if ($file[0] == '.') {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Go recursive down, or add the file size
|
||||
if (is_dir($path.$file)) {
|
||||
if (\is_dir($path.$file)) {
|
||||
$size += $this->getDirectorySize($path.$file.DIRECTORY_SEPARATOR);
|
||||
} else {
|
||||
$size += filesize($path.$file);
|
||||
$size += \filesize($path.$file);
|
||||
}
|
||||
}
|
||||
|
||||
closedir($directory);
|
||||
\closedir($directory);
|
||||
|
||||
return $size;
|
||||
}
|
||||
|
@ -264,7 +264,7 @@ class Local extends Device
|
|||
*/
|
||||
public function getPartitionFreeSpace():float
|
||||
{
|
||||
return disk_free_space($this->getRoot());
|
||||
return \disk_free_space($this->getRoot());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -276,6 +276,6 @@ class Local extends Device
|
|||
*/
|
||||
public function getPartitionTotalSpace():float
|
||||
{
|
||||
return disk_total_space($this->getRoot());
|
||||
return \disk_total_space($this->getRoot());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -40,7 +40,7 @@ class S3 extends Device
|
|||
$path = '';
|
||||
|
||||
for ($i = 0; $i < 4; ++$i) {
|
||||
$path = ($i < strlen($filename)) ? $path.DIRECTORY_SEPARATOR.$filename[$i] : $path.DIRECTORY_SEPARATOR.'x';
|
||||
$path = ($i < \strlen($filename)) ? $path.DIRECTORY_SEPARATOR.$filename[$i] : $path.DIRECTORY_SEPARATOR.'x';
|
||||
}
|
||||
|
||||
return $this->getRoot().$path.DIRECTORY_SEPARATOR.$filename;
|
||||
|
|
|
@ -27,7 +27,7 @@ class Storage
|
|||
*/
|
||||
public static function addDevice($name, Device $device)
|
||||
{
|
||||
if (array_key_exists($name, self::$devices)) {
|
||||
if (\array_key_exists($name, self::$devices)) {
|
||||
throw new Exception('The device "'.$name.'" is already listed');
|
||||
}
|
||||
|
||||
|
@ -47,7 +47,7 @@ class Storage
|
|||
*/
|
||||
public static function getDevice($name)
|
||||
{
|
||||
if (!array_key_exists($name, self::$devices)) {
|
||||
if (!\array_key_exists($name, self::$devices)) {
|
||||
throw new Exception('The device "'.$name.'" is not listed');
|
||||
}
|
||||
|
||||
|
@ -65,7 +65,7 @@ class Storage
|
|||
*/
|
||||
public static function exists($name)
|
||||
{
|
||||
return (bool) array_key_exists($name, self::$devices);
|
||||
return (bool) \array_key_exists($name, self::$devices);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -89,6 +89,6 @@ class Storage
|
|||
++$i;
|
||||
}
|
||||
|
||||
return round($bytes, $decimals).$units[$i];
|
||||
return \round($bytes, $decimals).$units[$i];
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,7 +24,7 @@ class FileName extends Validator
|
|||
return false;
|
||||
}
|
||||
|
||||
if (!preg_match('/^[a-zA-Z0-9.]+$/', $name)) {
|
||||
if (!\preg_match('/^[a-zA-Z0-9.]+$/', $name)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
@ -68,23 +68,23 @@ class FileType extends Validator
|
|||
return false;
|
||||
}
|
||||
|
||||
$handle = fopen($path, 'r');
|
||||
$handle = \fopen($path, 'r');
|
||||
|
||||
if (!$handle) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$bytes = fgets($handle, 8);
|
||||
$bytes = \fgets($handle, 8);
|
||||
|
||||
foreach ($this->whiteList as $key) {
|
||||
if (strpos($bytes, $this->types[$key]) === 0) {
|
||||
fclose($handle);
|
||||
if (\strpos($bytes, $this->types[$key]) === 0) {
|
||||
\fclose($handle);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
fclose($handle);
|
||||
\fclose($handle);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -23,13 +23,13 @@ class Template extends View
|
|||
return '';
|
||||
}
|
||||
|
||||
if (is_readable($this->path)) {
|
||||
$template = file_get_contents($this->path); // Include template file
|
||||
if (\is_readable($this->path)) {
|
||||
$template = \file_get_contents($this->path); // Include template file
|
||||
} else {
|
||||
throw new Exception('"'.$this->path.'" template is not readable or not found');
|
||||
}
|
||||
|
||||
$template = str_replace(array_keys($this->params), array_values($this->params), $template);
|
||||
$template = \str_replace(\array_keys($this->params), \array_values($this->params), $template);
|
||||
|
||||
return $template;
|
||||
}
|
||||
|
@ -45,7 +45,7 @@ class Template extends View
|
|||
*/
|
||||
public static function parseURL($url)
|
||||
{
|
||||
return parse_url($url);
|
||||
return \parse_url($url);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -89,10 +89,10 @@ class Template extends View
|
|||
{
|
||||
$parsed = [];
|
||||
|
||||
parse_str($query1, $parsed);
|
||||
\parse_str($query1, $parsed);
|
||||
|
||||
$parsed = array_merge($parsed, $query2);
|
||||
$parsed = \array_merge($parsed, $query2);
|
||||
|
||||
return http_build_query($parsed);
|
||||
return \http_build_query($parsed);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -26,7 +26,7 @@ class URL
|
|||
'fragment' => '',
|
||||
];
|
||||
|
||||
return array_merge($default, parse_url($url));
|
||||
return \array_merge($default, \parse_url($url));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -41,7 +41,7 @@ class URL
|
|||
*/
|
||||
static public function unparse(array $url, array $ommit = []):string
|
||||
{
|
||||
if (isset($url['path']) && mb_substr($url['path'], 0, 1) !== '/') {
|
||||
if (isset($url['path']) && \mb_substr($url['path'], 0, 1) !== '/') {
|
||||
$url['path'] = '/'.$url['path'];
|
||||
}
|
||||
|
||||
|
@ -87,7 +87,7 @@ class URL
|
|||
*/
|
||||
static public function parseQuery(string $query):array
|
||||
{
|
||||
parse_str($query, $result);
|
||||
\parse_str($query, $result);
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
@ -103,6 +103,6 @@ class URL
|
|||
*/
|
||||
static public function unparseQuery(array $query):string
|
||||
{
|
||||
return http_build_query($query);
|
||||
return \http_build_query($query);
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue