nacosvel/locator 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

nacosvel/locator

最新稳定版本:v1.0.0

Composer 安装命令:

composer require nacosvel/locator

包简介

Manages multiple instances, handling default selection, creation, caching, and extension.

README 文档

README

Locator

Manages multiple instances, handling default selection, creation, caching, and extension.

GitHub Tag Total Downloads Packagist Version Packagist PHP Version Support Packagist License

Table of Contents
  1. Installation
  2. Usage
  3. Contributing
  4. Contributors
  5. License

Installation

You can install the package via Composer:

composer require nacosvel/locator

[back to top]

Usage

config.php

<?php

return [
    'default' => 'alipay',
    'alipay'  => [
        'default'          => '2021004102600103',
        // 'driver'           => AlipayPaymentManager::class,
        '2021004102600102' => [
            'app_id' => env('ALIPAY_APP_ID', '2021004102600102****'),
        ],
        '2021004102600103' => [
            'app_id' => env('ALIPAY_APP_ID', '2021004102600103****'),
        ],
    ],
    'wechat'  => [
        'mch_id' => env('WECHAT_MCH_ID', '190000****'),
    ],
];

Payment::class

interface Payment
{
}

PaymentManager::class

use Nacosvel\Locator\MultipleInstanceManager;

class PaymentManager extends MultipleInstanceManager
{
    public function __construct(array $config = [])
    {
        parent::__construct($config);
    }

    #[ReturnTypeWillChange]
    public function instance(string $name = null): Payment
    {
        return parent::instance($name);
    }
}

PaymentManager::macro('other', function () {
    //
});

$payment = new PaymentManager(require __DIR__ . '/config.php');

$payment->extend('alipay', function (array $config) {
    return new Alipay($config);
});
$payment->extend('wechat', function (array $config) {
    return new Wechat($config);
});

PaymentManager::instance

$payment->instance(); // alipay

PaymentManager::using

var_dump($payment->getDefaultInstance());// alipay
$payment->using('wechat', function () {
    // wechat
});
var_dump($payment->getDefaultInstance());// alipay

Contributing

Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.

If you have a suggestion that would make this better, please fork the repo and create a pull request. You can also simply open an issue with the tag "enhancement". Don't forget to give the project a star! Thanks again!

  1. Fork the Project
  2. Create your Feature Branch (git checkout -b feature/AmazingFeature)
  3. Commit your Changes (git commit -m 'Add some AmazingFeature')
  4. Push to the Branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

[back to top]

Contributors

Thanks goes to these wonderful people:

contrib.rocks image

Contributions of any kind are welcome!

[back to top]

License

Distributed under the MIT License (MIT). Please see License File for more information.

[back to top]

统计信息

  • 总下载量: 6
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-12-08