定制 snapflowio/registry 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

snapflowio/registry

最新稳定版本:v0.1.0

Composer 安装命令:

composer require snapflowio/registry

包简介

A simple and lightweight library to pass resources around applications.

README 文档

README

A simple and lightweight library to pass resources around applications.

Installation

composer require snapflowio/registry

Quick Start

<?php

use Snapflow\Registry\Registry;

$registry = new Registry();

// Register a service with a factory callback
$registry->set('database', function () {
    return new PDO('mysql:host=localhost;dbname=myapp', 'user', 'pass');
});

// Get the service (lazy initialization, only created when first accessed)
$db = $registry->get('database');

// Subsequent calls return the same instance
$sameDb = $registry->get('database');

// Register services that always create fresh instances
$registry->set('timestamp', fn () => microtime(true), fresh: true);

// Use contexts for isolation (e.g., per-request, per-test)
$registry->context('testing')->set('database', function () {
    return new PDO('sqlite::memory:');
});

// Check if a service is registered
if ($registry->has('database')) {
    $db = $registry->get('database');
}

// Method chaining
$registry
    ->context('api')
    ->set('logger', fn () => new Logger())
    ->set('cache', fn () => new Cache());

// Info and cleanup
$services = $registry->getRegistered(); // ['database', 'timestamp', 'logger', 'cache']
$currentContext = $registry->getContext(); // 'api'
$registry->clear(); // Clear instances in current context
$registry->remove('cache'); // Remove service completely

License

This library is available under the MIT License.

Copyright

Copyright (c) 2025 Snapflow

统计信息

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

GitHub 信息

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

其他信息

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