drewlabs/libman
Composer 安装命令:
composer require drewlabs/libman
包简介
Libman package is a small PHP utility library used in installing, creating business specific class instance using configuration based approach
README 文档
README
Libman package is a small PHP utility library used in installing, creating business specific class instance using configuration based approach. The package comes YAML and JSON library definitions provider, used by the runtime instance builder.
Concept
- What is a Library ?
A library in the libman package implementation is a pure abstraction arround a PHP object that performs a specific task, or a set of tasks. A PHP object having business domain specific implementation that that must be required by another PHP application.
- Why
Libman
Libman tries to provides an API for building instances of a library (class) at runtime without developper programmatically creating instances. Developper provides configuration values about which type of package manager to use when adding library to the project, the factory class that is used to create an instance of the library.
Using developper configuration, written in YAML/JSON, or any library definition provider, Libman will be capable of create library instance at runtime when required in application code.
Installation
To add the library to your PHP application using composer manager:
composer require drewlabs/libman
Usage
- Create a composer based library
Composer based libraries are PHP library installable using PHP composer package manager. The library manager assume by default that the library factory class is name Factory.
use Drewlabs\Libman\LibraryConfig; use Drewlabs\Libman\LibraryInstallerFactory; // Creates an instance of the library to install // API: LibraryConfig::new(string name, string type, string package) $library = LibraryConfig::new('ClientLibrary', 'composer', 'client/library');
- Create a library configuration using a PHP factory class
A factory class based library configuration is a library configuration, that will use a PHP factory class to create an instance of library.
use Drewlabs\Libman\LibraryConfig; use Drewlabs\Libman\LibraryInstallerFactory; // Creates an instance of the library to install // API : LibraryConfig::new(string name, ?string type, ?string package, string $factoryClass) $library = LibraryConfig::new('ClientLibrary', null, null, ClientLibraryFactory::class);
- Create a library instance using the
LibraryManager
LibraryManager is a PHP class provided by the libman for creating libary instance based on configuration files or database configurations.
The code below use an InMemoryConfigurationRepository class that will read library configuration from a yaml definition file.
use Drewlabs\Libman\LibraryManager; use Drewlabs\Libma\InMemoryConfigurationRepository; use Drewlabs\Libman\YAMLDefinitionsProvider; $repository = new InMemoryConfigurationRepository(YAMLDefinitionsProvider::create('./path/to/libman.yml')); $libManager = new LibraryManager($repository); // Create an instance a composer based library named 'drewlabs/crypt' $libManager->resolveInstance('drewlabs/crypt');
The LibraryManager class comes with static method createInstance that takes a library configuration instance:
use Drewlabs\Libman\LibraryManager; use Drewlabs\Libman\LibraryConfig; // Create an Instance of the library $instance = LibraryManager::createInstance(LibraryConfig::new('ClientLibrary));
API Reference
The API reference for the library can be found at []
drewlabs/libman 适用场景与选型建议
drewlabs/libman 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 415 次下载、GitHub Stars 达 1, 最近一次更新时间为 2022 年 10 月 19 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 drewlabs/libman 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 drewlabs/libman 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 415
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 6
- 依赖项目数: 2
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2022-10-19