hireatlas / super-funds
直接从澳大利亚政府拉取最新的养老金基金列表,直接进入您的Laravel应用程序。
Requires
- guzzlehttp/guzzle: ^7.2
- illuminate/database: ^10.0
- illuminate/http: ^10.0
- illuminate/support: ^10.0
Requires (Dev)
- laravel/pint: ^1.13
- orchestra/testbench: ^8.15
- pestphp/pest: ^2.24
README
此包是围绕澳大利亚政府提供的、列出所有养老金基金和产品(USI标识符)的服务的一个相对轻量级的Laravel包装器。
我们从此URL下载文本文件,然后将其解析为一些DTO,您可以将它们保存到数据库中,或按您喜欢的任何方式使用。
安装
composer require hireatlas/super-funds
此包支持Laravel 10+和PHP 8.1+。
用法
以DTO形式获取养老金基金列表
要获取当前养老金基金的列表,您可以在SuperFunds
类上调用fetch()
方法。这将返回一个包含SuperFundDTO
对象的Collection。
use Atlas\SuperFunds\SuperFunds; /** @var SuperFunds $superFundsFetcher */ $superFundsFetcher = app(SuperFunds::class); $superFunds = $superFundsFetcher->fetch(); dd($superannuationFunds);
将养老金基金列表持久化为Eloquent模型到数据库
该包发布了一个迁移,用于将养老金基金作为Eloquent模型存储到您的数据库中,因此在使用下面的代码之前,请确保先运行php artisan migrate
。
要获取并将当前养老金基金列表持久化到数据库,您可以在SuperFunds
类上调用persist()
方法。
use Atlas\SuperFunds\SuperFunds; /** @var SuperFunds $superFundsFetcher */ $superFundsFetcher = app(SuperFunds::class); $superannuationFunds = $superFundsFetcher->persist(); dd($superannuationFunds);
使用自定义Eloquent模型
您可以通过在SuperFunds
类上调用useModel()
方法来使用自定义Eloquent模型。您应该从App\Providers\AppServiceProvider
中的boot()
方法调用此方法。
use App\Models\SuperFund as CustomSuperFundModel; use Atlas\SuperFunds\SuperFunds; public function boot() { SuperFunds::useModel(CustomSuperFundModel::class); }
禁用迁移
如果您不想使用默认迁移,或者根本不想持久化模型,那么您可以在SuperFunds
类上调用ignoreMigrations()
方法。您应该从App\Providers\AppServiceProvider
中的boot()
方法调用此方法。
use Atlas\SuperFunds\SuperFunds; public function boot() { SuperFunds::ignoreMigrations(); }
通过任务调度定期获取当前列表
该包包括从您的App\Console\Kernel
中调用的命令和作业。它们是等效的,因此使用您喜欢的任何一种方法。
为了避免过载上游服务,请选择一天中的随机时间来获取列表。
use Atlas\SuperFunds\Jobs\UpdateSuperFunds; $schedule->command('super-funds:update')->dailyAt('01:23'); // OR $schedule->job(new UpdateSuperFunds)->dailyAt('01:23');
测试
composer test
变更日志
有关最近更改的更多信息,请参阅变更日志。
安全漏洞
有关如何报告安全漏洞的更多信息,请查看我们的安全策略这里。
鸣谢
许可证
MIT许可证(MIT)。有关更多信息,请参阅许可证文件。