nikkiii / laravel-cachet
Laravel的Cachet适配器
Requires
- php: >=5.5.9
- graham-campbell/manager: ~2.2
- guzzlehttp/guzzle: ~6.0
This package is not auto-updated.
Last update: 2024-09-18 09:05:38 UTC
README
Laravel Cachet是Laravel 5的Cachet API包装器。它利用了Graham Campbell的Laravel Manager包。
安装
需要PHP 5.5+或HHVM 3.6+,以及Composer。
要获取Laravel Cachet的最新版本,只需将以下行添加到您的composer.json
文件的require块中
"nikkiii/laravel-cachet": "~1.0.2"
安装Laravel Cachet后,您需要注册服务提供者。打开config/app.php
,并将以下内容添加到providers
键中。
Nikkiii\Cachet\CachetServiceProvider::class
如果您喜欢,可以在config/app.php
文件的aliases
键中注册Cachet外观。
'Cachet' => Nikkiii\Cachet\Facades\Cachet::class
配置
Laravel Cachet需要连接配置。
要开始,您需要发布所有供应商资产
$ php artisan vendor:publish
这将在您的应用中创建一个config/cachet.php
文件,您可以修改它来设置配置。同时,确保检查这个包中原始配置文件在各个版本之间的更改。
有两个配置选项
默认连接名称
此选项('default'
)是您指定希望将以下哪个连接用作您所有工作的默认连接的地方。当然,您可以使用多个连接,一次使用管理器类。此设置的默认值为'main'
。
Cachet连接
此选项('connections'
)是为您的应用设置每个连接的地方。已包含示例配置,但您可以添加您想要的任意数量的连接。
用法
CachetManager
这是最感兴趣的类。它绑定到ioc容器中的'cachet'
,可以通过Facades\Cachet
外观访问。此类通过扩展AbstractManager
实现ManagerInterface
接口。该接口和抽象类都是Graham Campbell的Laravel Manager包的一部分,因此您可能想要查看如何在该存储库中使用管理器类的文档那里。注意,返回的连接类始终是\Nikkiii\Cachet\CachetConnection
的一个实例。
Facades\Cachet
此外观将动态将静态方法调用传递到ioc容器中的'cachet'
对象,默认情况下是CachetManager
类。
CachetServiceProvider
此类没有有趣的公共方法。此类应添加到config/app.php
中的providers数组。此类将设置ioc绑定。
真实示例
在这里,您可以看到这个包的使用是多么简单。默认适配器是main
。在配置文件中输入您的认证信息后,它就可以正常工作了
use Nikkiii\Cachet\Facades\Cachet; // you can alias this in config/app.php if you like // all calls will return either an array if it's a list, or stdClass object if it's data. // however, ping simply returns a boolean. // this'll return a list of components registered in cachet! Cachet::components(); // this'll return the component data for component 1 Cachet::component(1); // this'll return a list of incidents Cachet::incidents();
Cachet管理器将表现得像\Nikkiii\Cachet\CachetConnection
类。如果您想调用特定的连接,可以使用connection
方法
use Nikkiii\Cachet\Facades\Cachet; // the alternative connection is the other example provided in the default config Cachet::connection('alternative')->components();
考虑到这一点,请注意
use Nikkiii\Cachet\Facades\Cachet; // writing this: Cachet::connection('main')->components(); // is identical to writing this: Cachet::components(); // and is also identical to writing this: Cachet::connection()->components(); // this is because the main connection is configured to be the default Cachet::getDefaultConnection(); // this will return main // we can change the default connection Cachet::setDefaultConnection('alternative'); // the default is now alternative
如果您更喜欢使用依赖注入而不是外观,那么您可以轻松地按照以下方式注入管理器
use Nikkiii\Cachet\CachetManager; use Illuminate\Support\Facades\App; // you probably have this aliased already class Foo { protected $cachet; public function __construct(CachetManager $cachet) { $this->cachet = $cachet; } public function bar() { $this->cachet->components(); } } App::make('Foo')->bar();
有关如何使用管理器类的更多信息,请查看https://github.com/GrahamCampbell/Laravel-Manager#usage。
更多信息
目前不支持Metrics API,但将来会支持。这是非常迅速完成的,可能有些混乱。
这个库将来可能会迁移到Laravel的Collections,以更好地支持数组操作,因为它经常返回数据数组。
许可证
Laravel Cachet遵循ISC许可证(ISC)。