nacosvel / locator
Manages multiple instances, handling default selection, creation, caching, and extension.
Installs: 11
Dependents: 1
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 0
Open Issues: 0
pkg:composer/nacosvel/locator
Requires
- php: ^8.0
- nacosvel/macroable: ^1.0
Requires (Dev)
- code-lts/doctum: ^5.0
This package is auto-updated.
Last update: 2026-02-11 02:34:58 UTC
README
Locator
Manages multiple instances, handling default selection, creation, caching, and extension.
Table of Contents
Installation
You can install the package via Composer:
composer require nacosvel/locator
Usage
Config
return [ 'default' => 'alipay', 'alipay' => [ 'default' => '2021004102600103', '2021004102600102' => [ 'app_id' => '2021004102600102****', ], '2021004102600103' => [ 'app_id' => '2021004102600103****', ], ], 'wechat' => [ 'mch_id' => '190000****', ], ];
Use Cases
use Nacosvel\Locator\Concerns\HasAdapter; use Nacosvel\Locator\Contracts\Adapter; use Nacosvel\Locator\MultipleManager; class Payment implements Adapter { use HasAdapter; public function __construct( protected string $name, protected array $config, ) { // } } $config = require __DIR__ . '/config.php'; $manager = new MultipleManager($config); $manager->extend('alipay', function (string $name, array $config) { return new Payment($name, $config); }); $manager->extend('wechat', function (string $name, array $config) { return new Payment($name, $config); }); var_dump( $manager->instance('alipay')->getName(), $manager->instance('alipay')->getDefaultConfig(), $manager->instance('alipay')->getConfig(), $manager->instance('wechat')->getName(), $manager->instance('wechat')->getDefaultConfig(), $manager->instance('wechat')->getConfig(), );
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!
- Fork the Project
- Create your Feature Branch (
git checkout -b feature/AmazingFeature) - Commit your Changes (
git commit -m 'Add some AmazingFeature') - Push to the Branch (
git push origin feature/AmazingFeature) - Open a Pull Request
Contributors
Thanks goes to these wonderful people:
Contributions of any kind are welcome!
License
Distributed under the MIT License (MIT). Please see License File for more information.