Devs.tw 是讓工程師寫筆記、網誌的平台。歡迎您隨手紀錄、寫作,方便日後搜尋!
https://docs.laravel-excel.com/3.1/exports/collection.html
這個 design pattern 很酷 第一次看到
用實作介面來表示「增減功能」的行為
範例:
namespace App\Exports;
use Maatwebsite\Excel\Concerns\FromQuery;
use Maatwebsite\Excel\Concerns\WithMapping;
use Maatwebsite\Excel\Concerns\WithHeadings;
use Maatwebsite\Excel\Concerns\WithTitle;
use Maatwebsite\Excel\Concerns\FromCollection;
use Maatwebsite\Excel\Concerns\WithColumnFormatting;
use Maatwebsite\Excel\Concerns\WithStrictNullComparison;
use App\User;
use App\Order;
use PhpOffice\PhpSpreadsheet\Shared\Date;
use PhpOffice\PhpSpreadsheet\Style\NumberFormat;
use Maatwebsite\Excel\Concerns\ShouldAutoSize;
class UserPaymentExport implements FromCollection, WithHeadings, WithColumnFormatting, ShouldAutoSize, WithStrictNullComparison
{
//...
}
說來奇怪,OOP 的「介面」初衷應該不是這樣的?
應該是用來規範實作介面的那些類別、確保它們都有提供某些方法才對?