ceytek-labs/tcmb-services-lite
Composer 安装命令:
composer require ceytek-labs/tcmb-services-lite
包简介
A lightweight library for retrieving exchange rates and other data from TCMB's APIs.
关键字:
README 文档
README
🇹🇷 Türkçe sürüm için buraya tıklayın
TCMB Services Lite
The TCMB (Central Bank of the Republic of Turkey) Services Lite is designed to help you easily utilize various data and APIs provided by the TCMB. Currently, it offers the feature of fetching exchange rates, but it can be expanded in the future to include other APIs from the TCMB.
Disclaimer: This package is not an official product of Central Bank of the Republic of Türkiye (Türkiye Cumhuriyet Merkez Bankası). The developers accept no responsibility for any issues, discrepancies, or damages that may arise from its use.
Requirements
- PHP 8.1 or higher
Installation
You can add this package to your projects using Composer:
composer require ceytek-labs/tcmb-services-lite
Services
TCMB Exchange Rates
The TCMB Exchange Rates retrieves daily exchange rates from the Central Bank of Turkey, providing easy access to various currency information.
Example Usage
Here are a few examples of how you can use the TCMB Exchange Rates class in your PHP projects
TCMB Exchange Rates: Display Raw XML Result from the API
use CeytekLabs\TcmbServicesLite\TcmbExchangeRates; // Displays the raw XML result from the API echo TcmbExchangeRates::make()->response();
TCMB Exchange Rates: Display Raw JSON Result from the API
use CeytekLabs\TcmbServicesLite\TcmbExchangeRates; // Converts the raw XML result from the API to JSON and displays it echo TcmbExchangeRates::make()->jsonContent();
TCMB Exchange Rates: Formatting Exchange Rates
You can receive data from the API in either object or array format. CamelCase is used in object format, and snake_case is used in array format.
use CeytekLabs\TcmbServicesLite\TcmbExchangeRates; use CeytekLabs\TcmbServicesLite\Enums\Format; // Getting data in object format $exchangeRatesObject = TcmbExchangeRates::make()->format(Format::Object)->content(); // Getting data in array format $exchangeRatesArray = TcmbExchangeRates::make()->format(Format::Array)->content();
TCMB Exchange Rates: Getting All Exchange Rates
use CeytekLabs\TcmbServicesLite\TcmbExchangeRates; use CeytekLabs\TcmbServicesLite\Enums\Format; // Getting all exchange rates in object format $currenciesObject = TcmbExchangeRates::make()->format(Format::Object)->currencies(); // Getting all exchange rates in array format $currenciesArray = TcmbExchangeRates::make()->format(Format::Array)->currencies();
TCMB Exchange Rates: Getting a Specific Currency
You can use the currency() method to get data for a specific currency.
use CeytekLabs\TcmbServicesLite\TcmbExchangeRates; use CeytekLabs\TcmbServicesLite\Enums\Format; use CeytekLabs\TcmbServicesLite\Enums\Currency; // For example, getting the Australian Dollar (AUD) rate $australianDollar = TcmbExchangeRates::make() ->format(Format::Object) ->currency(Currency::AustralianDollar) ->find();
TCMB Exchange Rates: Accessing Currency Information
You can access detailed information of a specific currency:
use CeytekLabs\TcmbServicesLite\TcmbExchangeRates; use CeytekLabs\TcmbServicesLite\Enums\Format; use CeytekLabs\TcmbServicesLite\Enums\Currency; // Getting information for the USD currency $exchangeRates = TcmbExchangeRates::make() ->format(Format::Object) ->currency(Currency::UnitedStatesDollar); // Currency code echo $exchangeRates->code(); // "USD" // Turkish name echo $exchangeRates->turkishName(); // "ABD DOLARI" // English name echo $exchangeRates->englishName(); // "US DOLLAR" // Unit amount echo $exchangeRates->unit(); // "1" // Forex buying rate (The buying rate valid in international markets and digital transactions) echo $exchangeRates->forexBuying(); // Forex selling rate (The selling rate valid in international markets and digital transactions) echo $exchangeRates->forexSelling(); // Banknote buying rate (The buying rate valid in cash currency transactions) echo $exchangeRates->banknoteBuying(); // Banknote selling rate (The selling rate valid in cash currency transactions) echo $exchangeRates->banknoteSelling();
TCMB Exchange Rates: Displaying All Data in Object Format
use CeytekLabs\TcmbServicesLite\TcmbExchangeRates; use CeytekLabs\TcmbServicesLite\Enums\Format; print_r(TcmbExchangeRates::make()->format(Format::Object)->content());
Sample output:
stdClass Object ( [attributes] => stdClass Object ( [date] => "2024-09-20 15:30" [bulletinNumber] => "2024/178" ) [currencies] => stdClass Object ( [USD] => stdClass Object ( [code] => "USD" [name] => stdClass Object ( [tr] => "ABD DOLARI" [en] => "US DOLLAR" ) [unit] => "1" [forex] => stdClass Object ( [buying] => "33.9531" [selling] => "34.0142" ) [banknote] => stdClass Object ( [buying] => "33.9293" [selling] => "34.0652" ) ) // Other currencies... ) )
TCMB Exchange Rates: Displaying All Data in Array Format
use CeytekLabs\TcmbServicesLite\TcmbExchangeRates; use CeytekLabs\TcmbServicesLite\Enums\Format; print_r(TcmbExchangeRates::make()->format(Format::Array)->content());
Sample output:
Array ( [attributes] => Array ( [date] => "2024-09-20 15:30" [bulletin_number] => "2024/178" ) [currencies] => Array ( [USD] => Array ( [code] => "USD" [name] => Array ( [tr] => "ABD DOLARI" [en] => "US DOLLAR" ) [unit] => "1" [forex] => Array ( [buying] => "33.9531" [selling] => "34.0142" ) [banknote] => Array ( [buying] => "33.9293" [selling] => "34.0652" ) ) // Other currencies... ) )
TCMB Exchange Rates: Supported Currencies
The package supports the following currencies:
- 🇺🇸 USD: United States Dollar
- 🇦🇺 AUD: Australian Dollar
- 🇩🇰 DKK: Danish Krone
- 🇪🇺 EUR: Euro
- 🇬🇧 GBP: British Pound
- 🇨🇭 CHF: Swiss Franc
- 🇸🇪 SEK: Swedish Krona
- 🇨🇦 CAD: Canadian Dollar
- 🇰🇼 KWD: Kuwaiti Dinar
- 🇳🇴 NOK: Norwegian Krone
- 🇸🇦 SAR: Saudi Riyal
- 🇯🇵 JPY: Japanese Yen
- 🇧🇬 BGN: Bulgarian Lev
- 🇷🇴 RON: Romanian Leu
- 🇷🇺 RUB: Russian Ruble
- 🇮🇷 IRR: Iranian Rial
- 🇨🇳 CNY: Chinese Yuan
- 🇵🇰 PKR: Pakistani Rupee
- 🇶🇦 QAR: Qatari Riyal
- 🇰🇷 KRW: South Korean Won
- 🇦🇿 AZN: Azerbaijani Manat
- 🇦🇪 AED: United Arab Emirates Dirham
Debugging
- If the response from the API is invalid or an error occurs, an
Exceptionwill be thrown. - If the XML format is invalid, you will receive the following error:
Invalid XML format. Please check TcmbExchangeRates::make()->getResponse()
Future Plans
This package can be expanded to include other data and services provided by the TCMB, such as:
- Interest Rates: Fetching interest rates published by the TCMB.
- Inflation Data: Access to current inflation data.
- Other Financial Data: Integrating other statistics and reports provided by the TCMB.
Contributing
If you'd like to contribute, please send a pull request or report an issue.
License
This project is licensed under the MIT License.
ceytek-labs/tcmb-services-lite 适用场景与选型建议
ceytek-labs/tcmb-services-lite 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 5 次下载、GitHub Stars 达 0, 最近一次更新时间为 2024 年 10 月 26 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「php」 「currency」 「turkey」 「forex」 「exchange rates」 「tcmb」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 ceytek-labs/tcmb-services-lite 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 ceytek-labs/tcmb-services-lite 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 ceytek-labs/tcmb-services-lite 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Fixer.io data provider for Peso
Turkey Cities and States - Türkiye İl ve İlçeler (PTT)
TCMB Currenct Converter
Immutable PHP currency converter that's data-agnostic.
Türkiye'nin tüm illeri ve ilçelerinin hiyerarşik yapıda bulabilirsiniz.
Alfabank REST API integration
统计信息
- 总下载量: 5
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 36
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-10-26
