Repository: appwrite/appwrite
File: app/init/resources.php (PHP)

Code before:
    return $token;
});

Http::setResource('proofForCode', function (): Code {
    $code = new Code();
    $code->setHash(new Sha());
    return $code;
});

Http::setResource('console', function () {
    return new Document(Config::getParam('console'));
}, []);

Http::setResource('authorization', function () {
    return new Authorization();
}, []);

Http::setResource('dbForProject', function (Group $pools, Database $dbForPlatform, Cache $cache, Document $project, Response $response, Publisher $publisher, Publisher $publisherFunctions, Publisher $publisherWebhooks, Event $queueForEvents, Func $queueForFunctions, Webhook $queueForWebhooks, Realtime $queueForRealtime, StatsUsage $queueForStatsUsage, Authorization $authorization) {
    if ($project->isEmpty() || $project->getId() === 'console') {
        return $dbForPlatform;
    }

    $database = $project->getAttribute('database');
    if ($database === null || $database === '') {
        throw new Exception(Exception::GENERAL_SERVER_ERROR, 'Project database is not configured');
    }

    try {
        $dsn = new DSN($database);
    } catch (\InvalidArgumentException) {
        // TODO: Temporary until all projects are using shared tables
        $dsn = new DSN('mysql://' . $database);
    }

    $adapter = new DatabasePool($pools->get($dsn->getHost()));
    $database = new Database($adapter, $cache);

    $database
        ->setDatabase(APP_DATABASE)
        ->setAuthorization($authorization)
        ->setMetadata('host', \gethostname())
        ->setMetadata('project', $project->getId())
        ->setTimeout(APP_DATABASE_TIMEOUT_MILLISECONDS_API)
        ->setMaxQueryValues(APP_DATABASE_QUERY_MAX_VALUES);
    $database->setDocumentType('users', User::class);

    $sharedTables = \explode(',', System::getEnv('_APP_DATABASE_SHARED_TABLES', ''));

    if (\in_array($dsn->getHost(), $sharedTables)) {
        $database
            ->setSharedTables(true)

Review comment (suggestion):
I think we should check if $project->isEmpty, to have even better understanding.


```suggestion
    if ($project->isEmpty()) {
        throw new Exception(Exception::GENERAL_SERVER_ERROR, 'Project is not configured');
    }
    
    $database = $project->getAttribute('database', '');
    if (empty($database)) {
        throw new Exception(Exception::GENERAL_SERVER_ERROR, 'Project database is not configured');
    }
```

Code after:
    return $token;
});

Http::setResource('proofForCode', function (): Code {
    $code = new Code();
    $code->setHash(new Sha());
    return $code;
});

Http::setResource('console', function () {
    return new Document(Config::getParam('console'));
}, []);

Http::setResource('authorization', function () {
    return new Authorization();
}, []);

Http::setResource('dbForProject', function (Group $pools, Database $dbForPlatform, Cache $cache, Document $project, Response $response, Publisher $publisher, Publisher $publisherFunctions, Publisher $publisherWebhooks, Event $queueForEvents, Func $queueForFunctions, Webhook $queueForWebhooks, Realtime $queueForRealtime, StatsUsage $queueForStatsUsage, Authorization $authorization) {
    if ($project->isEmpty() || $project->getId() === 'console') {
        return $dbForPlatform;
    }

    $database = $project->getAttribute('database', '');
    if (empty($database)) {
        throw new Exception(Exception::GENERAL_SERVER_ERROR, 'Project database is not configured');
    }

    try {
        $dsn = new DSN($database);
    } catch (\InvalidArgumentException) {
        // TODO: Temporary until all projects are using shared tables
        $dsn = new DSN('mysql://' . $database);
    }

    $adapter = new DatabasePool($pools->get($dsn->getHost()));
    $database = new Database($adapter, $cache);

    $database
        ->setDatabase(APP_DATABASE)
        ->setAuthorization($authorization)
        ->setMetadata('host', \gethostname())
        ->setMetadata('project', $project->getId())
        ->setTimeout(APP_DATABASE_TIMEOUT_MILLISECONDS_API)
        ->setMaxQueryValues(APP_DATABASE_QUERY_MAX_VALUES);
    $database->setDocumentType('users', User::class);

    $sharedTables = \explode(',', System::getEnv('_APP_DATABASE_SHARED_TABLES', ''));

    if (\in_array($dsn->getHost(), $sharedTables)) {
        $database
            ->setSharedTables(true)