2016-07-14 178 views
1

我試圖找出如何更改Lumen項目上的默認存儲位置(包括它的子文件夾)。由於多種原因,考慮到生產Web服務器的當前配置,Lumen在嘗試編寫日誌編譯刀片視圖時會拋出權限被拒絕異常。流明 - 更改默認存儲路徑

不涉及sysadmin的唯一選擇是將存儲文件夾移動到Web服務器上的tmp文件夾。

在laravel上,似乎有一種名爲「useStoragePath」的方法,但它似乎在Lumen(5.2.x)上不可用。

的默認路徑似乎是 「硬編碼」,我發現這一點:

Project\vendor\laravel\lumen-framework\src\Application.php 

/** 
    * Get the storage path for the application. 
    * 
    * @param string|null $path 
    * @return string 
    */ 
    public function storagePath($path = null) 
    { 
     return $this->basePath().'/storage'.($path ? '/'.$path : $path); 
    } 

而對於日誌(同一個文件):

/** 
    * Get the Monolog handler for the application. 
    * 
    * @return \Monolog\Handler\AbstractHandler 
    */ 
    protected function getMonologHandler() 
    { 
     return (new StreamHandler(storage_path('logs/lumen.log'), Logger::DEBUG)) 
          ->setFormatter(new LineFormatter(null, null, true, true)); 
    } 

底線:有沒有乾淨的方式覆蓋默認存儲路徑牢記這個限制?:

  • 我的t不應該涉及sysadmin(sym鏈接,更改權限等)
  • 不篡改供應商文件夾。

回答

1

On Line 286 of vendor/laravel/lumen-framework/src/helpers.php:

if (! function_exists('storage_path')) { 
    /** 
    * Get the path to the storage folder. 
    * 
    * @param string $path 
    * @return string 
    */ 
    function storage_path($path = '') 
    { 
     return app()->storagePath($path); 
    } 
} 

這裏的關鍵是這一行:

if (! function_exists('storage_path')) 

這意味着,如果尚未定義了一個名爲storage_path功能,然後流明將使用它自己的實現。

您只需編寫自己的函數返回自己的自定義路徑即可。

因爲流明比Laravel少得多,所以你怎麼做完全取決於你。這就是說,我會建議做如下方式:

  1. 將一個你的應用程序目錄
  2. 下稱爲helpers.php文件添加任何及所有自定義輔助功能到這個文件包括你自己storage_path實現
  3. 確保此文件在Lumen本身之前加載。爲此,您需要在composer的自動加載器之前放置您的require語句。

    require_once __DIR__ . '/../app/helpers.php'; 
    require_once __DIR__ . '/../vendor/autoload.php'; 
    
    try { 
        (new Dotenv\Dotenv(__DIR__ . '/../'))->load(); 
    } catch (Dotenv\Exception\InvalidPathException $e) { 
        // 
    } 
    
    .... 
    
:這可以在第一行下 引導/ app.php完成