a1comms/gae-support-laravel

此包已被弃用,不再维护。作者建议使用 affordablemobiles/g-serverless-support-laravel 包。

Google App Engine 标准环境对 Laravel 应用程序的支持

v9.0.42 2023-12-05 13:30 UTC

README

Google App Engine (GAE) 标准环境对 Laravel 9.x 的支持包。

Latest Stable Version Monthly Downloads Total Downloads Latest Unstable Version License

基于 @shpasser 在 App Engine 标准环境(基于 PHP5.5 运行时)上的原始工作 https://github.com/shpasser/GaeSupportL5

注意:我们只打算支持 Laravel LTS 版本,此版本专门针对 Laravel 9.x

功能

安装

使用 Composer 引入包

"require": {
    "a1comms/gae-support-laravel": "~9.0"
}

Laravel 特定(非 Lumen)

1.composer.json 中添加以下内容

    "scripts": {
        "post-autoload-dump": [
            "php artisan gae:prepare"
        ]
    },

2. 对于 Laravel,在 config/app.php 中包含服务提供者

    'providers' => [
        A1comms\GaeSupportLaravel\GaeSupportServiceProvider::class,
    ];

3. 此外,为了增加功能,包括可选的服务提供者

    'providers' => [
        A1comms\GaeSupportLaravel\Auth\AuthServiceProvider::class,
        A1comms\GaeSupportLaravel\View\ViewServiceProvider::class,
        A1comms\GaeSupportLaravel\Queue\QueueServiceProvider::class,
        A1comms\GaeSupportLaravel\Trace\TraceServiceProvider::class,
    ];

并移除这些服务提供者所替代的相关 Laravel 服务提供者

    'providers' => [
        //Illuminate\View\ViewServiceProvider::class,
        //Illuminate\Queue\QueueServiceProvider::class,
    ];

4. 更新 bootstrap/app.php 以加载覆盖的应用程序类并初始化日志到 Stackdriver

/*
|--------------------------------------------------------------------------
| Create The Application
|--------------------------------------------------------------------------
|
| The first thing we will do is create a new Laravel application instance
| which serves as the "glue" for all the components of Laravel, and is
| the IoC container for the system binding all of the various parts.
|
*/

$app = new A1comms\GaeSupportLaravel\Foundation\Application(
    $_ENV['APP_BASE_PATH'] ?? dirname(__DIR__)
);

5. 更新 app/Exceptions/Handler.php 以启用正确的异常日志到 StackDriver 错误报告和日志

更改以下 use 语句

use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;

到我们的类,这将注入所需的日志钩子

use A1comms\GaeSupportLaravel\Foundation\Exceptions\Handler as ExceptionHandler;

6.config/logging.php 中,配置自定义记录器并将其设置为默认记录器

将紧急日志路径设置到 App Engine 会将其转发到 Stackdriver 日志的位置也是有用的,见下文。

<?php

use A1comms\GaeSupportLaravel\Log\CreateLoggingDriver;

return [
    
    'default' => 'gae',

    'channels' => [
        'gae' => [
            'driver' => 'custom',
            'via' => CreateLoggingDriver::class,
        ],

        'emergency' => [
            'path' => '/var/log/emergency.log',
        ],
    ],

];

7..env 中,设置以下内容

QUEUE_CONNECTION=gae
CACHE_DRIVER=array
SESSION_DRIVER=gae
LOG_CHANNEL=gae

Lumen 特定(非 Laravel)

1. 更新 bootstrap/app.php 以加载覆盖的应用程序类

/*
|--------------------------------------------------------------------------
| Create The Application
|--------------------------------------------------------------------------
|
| Here we will load the environment and create the application instance
| that serves as the central piece of this framework. We'll use this
| application as an "IoC" container and router for this framework.
|
*/

$app = new A1comms\GaeSupportLaravel\Foundation\LumenApplication(
    $_ENV['APP_BASE_PATH'] ?? dirname(__DIR__)
);

2. 更新 app/Exceptions/Handler.php 以启用正确的异常日志到 StackDriver 错误报告和日志

更改以下 use 语句

use Laravel\Lumen\Exceptions\Handler as ExceptionHandler;

到我们的类,这将注入所需的日志钩子

use A1comms\GaeSupportLaravel\Foundation\Exceptions\LumenHandler as ExceptionHandler;

升级(从 Laravel/Lumen 6.x LTS)

Laravel 特定(非 Lumen)

1.composer.json 中更新包版本

"require": {
    "a1comms/gae-support-laravel": "~9.0"
}

2. 遵循所有 6.x ... 9.x 版本的 Laravel 升级步骤

Lumen 特定(非 Laravel)

1.composer.json 中更新包版本

"require": {
    "a1comms/gae-support-laravel": "~9.0"
}

2. 遵循所有 6.x ... 9.x 版本的 Lumen 升级步骤