geovanefss/laravel-api-moloni
Composer 安装命令:
composer require geovanefss/laravel-api-moloni
包简介
A PHP package for interacting with Moloni APIs
README 文档
README
https://packagist.org/packages/geovanefss/laravel-api-moloni
Installation
To install this package, ensure you have Composer installed on your system. Then, run the following command in your project directory:
composer require geovanefss/laravel-api-moloni
Environment Configuration
In your .env file, define the necessary environment variables to configure the Moloni API. This will keep your credentials secure and allow for easy configuration changes.
MOLONI_GRANT_TYPE=password MOLONI_CLIENT_ID=your_client_id MOLONI_CLIENT_SECRET=your_client_secret MOLONI_USERNAME=your_username MOLONI_PASSWORD=your_password
You can adjust these values based on your Moloni API credentials and usage requirements.
Usage Example
Below is an example demonstrating how to use this package in your Laravel project:
<?php require_once('vendor/autoload.php'); use Dotenv\Dotenv; use Geovanefss\LaravelApiMoloni\Exceptions\ApiException; use Geovanefss\LaravelApiMoloni\Exceptions\TokenException; use Geovanefss\LaravelApiMoloni\Exceptions\ValidationException; use Geovanefss\LaravelApiMoloni\Moloni; try { // Load environment variables $dotenv = Dotenv::createUnsafeImmutable(__DIR__); $dotenv->safeLoad(); // Set Moloni API configuration using environment variables $configs = [ // Required (see: https://www.moloni.pt/dev/autenticacao/) 'grant_type' => getenv('MOLONI_GRANT_TYPE'), // Required 'client_id' => getenv('MOLONI_CLIENT_ID'), // Required 'client_secret' => getenv('MOLONI_CLIENT_SECRET'), // Required (for authorize) 'response_type' => getenv('MOLONI_RESPONSE_TYPE'), // Required (for authorize and grant_type: authorization_code) 'redirect_uri' => getenv('MOLONI_REDIRECT_URI'), // Required (for grant_type: authorization_code) 'authorization_code' => getenv('MOLONI_AUTHORIZATION_CODE'), // Required (for grant_type: password) 'username' => getenv('MOLONI_USERNAME'), // Required (for grant_type: password) 'password' => getenv('MOLONI_PASSWORD'), // Required (for grant_type: refresh_token) 'refresh_token' => getenv('MOLONI_REFRESH_TOKEN'), ]; // Initialize Moloni instance $moloni = new Moloni($configs); // Start Debug API $moloni->startDebug(); // default is to not Debug // Stop Debug API $moloni->stopDebug(); // default is to not Debug // Stop Validate API $moloni->stopValidate(); // default is to Validate // Start Validate API $moloni->startValidate(); // default is to Validate // Example: Fetch user profile from Moloni API $resp = $moloni->myProfile()->getMe(); // Output the response in a readable format var_dump(json_encode($resp, JSON_PRETTY_PRINT)); } catch (ApiException | ValidationException | TokenException $e) { // Handle Moloni API-specific exceptions var_dump(get_class($e) . ': ' . $e->toString()); } catch (Exception $e) { // Handle general exceptions var_dump(get_class($e) . ': ' . $e->getMessage()); }
Explanation
Using Environment Variables
By placing the configuration values in the .env file, you avoid hard-coding sensitive data like client credentials and user passwords. This makes the application:
- Easier to configure: Modify
.envfor different environments (e.g., production, staging, development). - More secure: Credentials are not exposed in source code.
Steps Breakdown:
- Environment Setup: Define all the necessary environment variables for the Moloni API configuration in the
.envfile. - Load Environment Variables: The
Dotenvlibrary is used to load these variables dynamically. - Configure the API: Pass the loaded environment variables to the
MoloniAPI configuration array.
Moloni's API Documentation
For more details, please refer to the official Moloni API documentation:
geovanefss/laravel-api-moloni 适用场景与选型建议
geovanefss/laravel-api-moloni 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 267 次下载、GitHub Stars 达 4, 最近一次更新时间为 2024 年 09 月 23 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 geovanefss/laravel-api-moloni 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 geovanefss/laravel-api-moloni 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 267
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 5
- 点击次数: 18
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-09-23