sustainable-hustle/astrel-laravel
Composer 安装命令:
composer require sustainable-hustle/astrel-laravel
包简介
Integrate Astrel to your Laravel applications.
README 文档
README
Integrate Astrel to your Laravel applications.
Astrel is a remote config orchestration application that enables you to change anything in your apps without touching your code.
🍿 Are you a visual learner? Here a quick video tutorial to help you get started with Astrel and Laravel.
Installation
Install this package via composer.
composer require sustainable-hustle/astrel-laravel
Add your Astrel API key in your .env file.
ASTREL_API_KEY="sxjTgBJAxkT2TNyKf9vabFI0L07AyItM5o3iiloS"
Finally, listen for Astrel's webhooks to clear the cache.
// routes/web.php use SustainableHustle\Astrel\Facades\Astrel; Astrel::webhookRoute('astrel/webhook'); // Make sure CSRF verification is disabled on that route. class VerifyCsrfToken extends Middleware { protected $except = [ '/astrel/webhook', ]; }
Optionally, publish the astrel config file.
php artisan vendor:publish --tag="astrel-config"
Basic usage
This package provides a facade you can use to retrieve one or many aspects. An aspect is a key/value pair that you configure and updates directly on your Astrel dashboard.
use SustainableHustle\Astrel\Facades\Astrel; Astrel::all(); // Returns all aspects. Astrel::get('slug'); // Returns the value of an aspect by giving its slug. Astrel::get('slug', 'default value'); // Returns the default value if the given aspect has no value.
Alternatively, you may use the astrel helper method to access the Astrel manager or to access a value directly.
astrel()->all(); // Equivalent to Astrel::all(); astrel('slug'); // Equivalent to Astrel::get('slug'); astrel('slug', 'default value'); // Equivalent to Astrel::get('slug', 'default value');
Note that if you'd like to fallback to an environment variable you may also use the astrel_env helper function like so.
astrel_env('my-slug'); // Equivalent to astrel('my-slug', env('MY_SLUG')); astrel_env('my-slug', 'MY_ENV_SLUG'); // Equivalent to astrel('my-slug', env('MY_ENV_SLUG')); astrel_env('my-slug', 'MY_ENV_SLUG', 'default'); // Equivalent to astrel('my-slug', env('MY_ENV_SLUG', 'default'));
Caching
This package automatically caches all retrieved aspects. This ensure your application does not make API calls every single time a value from Astrel is required.
You may use the flush and refetch methods from the Astrel facade to clear the cache as well as refetching its content immediately.
use SustainableHustle\Astrel\Facades\Astrel; Astrel::flush() // Flush the cache for all aspects. Astrel::refetch() // Flush the cache and refetch all aspects immediately.
By default, the cache never expires meaning you will have to manually flush it when necessary. This is because Astrel will send you a webhook whenever something changes so you can flush the cache only when necessary (see section below).
However, if you'd like to customize the cache's lifetime, you may update the cache_lifetime variable in your config/astrel.php file.
Clear the cache when receiving a webhook
As mentioned above, you can configure Astrel to send you a webhook whenever any value gets updated. That means you can use this webhook to clear and immediately refetch all of your aspects.
This package provides a helper method webhookRoute on the Astrel facade that does just that. Simply add this to your routes file and chain any route configuration you might like.
use SustainableHustle\Astrel\Facades\Astrel; Astrel::webhookRoute(); // Register a route that calls `Astrel::refetch()` when triggered. Astrel::webhookRoute('astrel/webhook'); // Provide a custom path to that route. Astrel::webhookRoute('astrel/webhook') // This method returns a Route object so you can chain anything you want. ->name('webhooks.astrel') ->middleware('web');
Additionally, if you're using the default web middleware group, make sure to disable CSRF verification for that route in the VerifyCsrfToken middleware.
class VerifyCsrfToken extends Middleware
{
protected $except = [
- //
+ '/astrel/webhook',
];
}
sustainable-hustle/astrel-laravel 适用场景与选型建议
sustainable-hustle/astrel-laravel 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 736 次下载、GitHub Stars 达 3, 最近一次更新时间为 2021 年 09 月 13 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「laravel」 「astrel」 「remote config」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 sustainable-hustle/astrel-laravel 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 sustainable-hustle/astrel-laravel 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 sustainable-hustle/astrel-laravel 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Allow packages to be installed from a repository or tarball bundle that have multiple packages in the sub-folders
PHP library that allows linking queries from diferent physical databases using mysql pdo database connections
Deploy is an Artisan command with the aim to provide a very simple way to deploy your code into staging and production while ensuring valid version tags are applied.
An php psr4 Autoloader which is autoloading from a remote server.
Alfabank REST API integration
Filesystem abstraction: Many filesystems, one API. Refactored for Legacy PHP 5.3
统计信息
- 总下载量: 736
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 3
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2021-09-13