ufo-tech/petrol-prices
Composer 安装命令:
composer require ufo-tech/petrol-prices
包简介
Library to fetch and cache petrol prices from public resources.
README 文档
README
Description
Fuel Price Service is a PHP library for fetching and caching up-to-date fuel prices from various providers.
It supports PSR-compliant interfaces for better integration into modern PHP projects.
Features
- Fetch fuel prices from providers via API.
- Automatic caching with customizable TTL.
- Easy addition of new data providers through interfaces.
- Exception handling for errors during data retrieval.
Installation
Install the library via Composer:
composer require ufo/petrol-prices
Usage
Basic Example
use Ufo\PetrolPrices\FuelPriceService; use Ufo\PetrolPrices\Providers\AutoRiaFuelPriceProvider; use Symfony\Component\Cache\Adapter\FilesystemAdapter; use Symfony\Component\HttpClient\HttpClient; $httpClient = HttpClient::create(); $cache = new FilesystemAdapter(); $provider = new AutoRiaFuelPriceProvider($httpClient); $service = new FuelPriceService($provider, $cache); try { $fuelPrices = $service->getFuelPrices(); echo "Date: {$fuelPrices->date}\n"; echo "A-95 Premium: {$fuelPrices->a95Plus} UAH\n"; echo "A-95: {$fuelPrices->a95} UAH\n"; echo "A-92: {$fuelPrices->a92} UAH\n"; echo "Diesel: {$fuelPrices->diesel} UAH\n"; echo "Gas: {$fuelPrices->gas} UAH\n"; } catch (\Exception $e) { echo "Error: " . $e->getMessage(); }
Usage Without Caching
$service = new FuelPriceService($provider); $fuelPrices = $service->getFuelPrices();
Usage with Custom TTL
$service = new FuelPriceService($provider, $cache, cacheTtl: 7200); // Cache for 2 hours $fuelPrices = $service->getFuelPrices();
Extending
To add a new provider, implement the IFuelPriceProvider interface:
namespace Ufo\PetrolPrices\Interfaces; use Ufo\PetrolPrices\DTO\FuelPrice; interface IFuelPriceProvider { public function getFuelPrices(): FuelPrice; }
Testing
Run tests using PHPUnit:
vendor/bin/phpunit tests/
License
This project is licensed under the MIT License. See the LICENSE file for details.
ufo-tech/petrol-prices 适用场景与选型建议
ufo-tech/petrol-prices 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 57 次下载、GitHub Stars 达 0, 最近一次更新时间为 2024 年 12 月 14 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 ufo-tech/petrol-prices 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 ufo-tech/petrol-prices 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 57
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 18
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-12-14