簡體   English   中英

在 Heroku 上打開 Symfony 應用程序時出現 SQLite 錯誤

[英]SQLite error opening Symfony app on Heroku

錯誤本身:

2021-07-20T23:43:33.993462+00:00 app[web.1]: [20-Jul-2021 23:43:33 UTC] [critical] Uncaught PHP Exception Symfony\Component\ErrorHandler\Error\ClassNotFoundError: "Attempted to load class "SQLite3Cache" from namespace "Doctrine\Common\Cache".
2021-07-20T23:43:33.993688+00:00 app[web.1]: Did you forget a "use" statement for another namespace?" at /app/src/Utils/FilesCache.php line 23

“FilesCache.php”的文件,內容類似於什么的Symfony的文檔中提供了這里有一些補充。

<?php
namespace App\Utils;

use App\Utils\Interfaces\CacheInterface;
use Symfony\Component\Cache\Adapter\FilesystemAdapter;
use Symfony\Component\Cache\Adapter\TagAwareAdapter;
use Doctrine\Common\Cache\CacheProvider;
use Doctrine\Common\Cache\SQLite3Cache;
use Symfony\Component\Cache\Adapter\DoctrineAdapter;


class FilesCache implements CacheInterface
{
    public $cache;

    public function __construct()
    {
        //this is error line 23
        $provider = new SQLite3Cache(new \SQLite3(__DIR__ . '/cache/data.db'), 'TableName');

        $this->cache =  new TagAwareAdapter(
            new DoctrineAdapter(
                $provider,
                $namespace = '',
                $defaultLifetime = 0
            )
        );
    }
}

我已將“pdo_sqlite”和“sqlite3”擴展名添加到“composer.json”。 Composer 更新運行沒有問題。

在將本地項目存儲庫推送到 Heroku 之前,我同時提交了“composer.json”和“composer.lock”,Heroku 運行也沒有問題,並顯示添加了兩個擴展。

remote: -----> Installing platform packages...
remote:        - php (8.0.8)
remote:        - ext-intl (bundled with php)
remote:        - ext-pdo_sqlite (bundled with php)
remote:        - ext-sqlite3 (bundled with php)
remote:        - composer (2.1.3)
remote:        - apache (2.4.48)
remote:        - nginx (1.20.1)

我知道 SQLite 不是生產數據庫的正確選擇,我正在學習一門課程,我想繼續使用它提供的內容。

預先感謝您的任何幫助!

正如評論中提到的,問題是學說/緩存的棄用。 我切換到 PDOAdapter,這解決了這個問題。

 <?php
        namespace App\Utils;
        
        use App\Utils\Interfaces\CacheInterface;
        use Symfony\Component\Cache\Adapter\TagAwareAdapter;
        use Symfony\Component\Cache\Adapter\PdoAdapter;
        use Doctrine\DBAL\Driver\Connection;
        
        
        class FilesCache implements CacheInterface
        {
            public $cache;
    
            public function __construct()
            {
                $connection = \Doctrine\DBAL\DriverManager::getConnection([
                    'url' => 'sqlite:////%kernel.project_dir%/var/cache/data.db'
                ]);
        
                $this->cache =  new TagAwareAdapter(
                    new PdoAdapter(
                        $connection,
                        $namespace = '',
                        $defaultLifetime = 0
                    )
                );
            }
        }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM