承接 hesam-mousavi/falcon-container 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

hesam-mousavi/falcon-container

最新稳定版本:1.1.1

Composer 安装命令:

composer require hesam-mousavi/falcon-container

包简介

Powerful 'dependency-injection container'(service container), and 'service-provider' with composite autowiring and binding

README 文档

README

The complexity of existing packages providing service containers and providers led to the creation of this project. Falcon doesn't force you to create a BIND. If a bind exists for an ID, it uses it; otherwise, it proceeds with AUTOWIRE.

Getting Started

  • add this package to your project:
composer require hesam-mousavi/falcon-container
  • add composer autoload:
<?php
require_once __DIR__.'/vendor/autoload.php';
  • then create the container:
$container = \HesamMousavi\FalconContainer\FalconContainer::getInstance();

Singleton Service

If you want to use a service as a singleton:

$container->singleton('test', Test::class);
// Or
$container->singleton(Test::class);

To execute the service in the first case:

$container->get('test');

In the second case:

$container->get(Test::class);

Non-Singleton Service

If you don't want to use the service as a singleton, you need to bind it:

$container->bind('test', Test::class);
// Or
$container->bind(Test::class);

Calling them is the same as with the singleton and both are accessible with get method:

$container->get('test');
$container->get(Test::class);

Using Closures

You can also use closures:

$container->singleton('test', function ($container) {
    return $container->get(Test::class);
});

Example

Suppose we have a class titled Test:

namespace HesamMousavi\FalconContainer;

class Test {}

Result of Calling This Class:

$container = \HesamMousavi\FalconContainer\FalconContainer::getInstance();

$container->singleton('test', \HesamMousavi\FalconContainer\Test::class);
//or
//$container->bind('test', \HesamMousavi\FalconContainer\Test::class);

dump($container->get('test'));
dump($container->get('test'));

Output in Bind Mode:

HesamMousavi\FalconContainer\Test {#6}
HesamMousavi\FalconContainer\Test {#13}

Output in Singleton Mode:

HesamMousavi\FalconContainer\Test {#6}
HesamMousavi\FalconContainer\Test {#6}

Autowire Mode

If the class is not bound and called directly via the get method, it will be automatically resolved using reflection. This means that the autowire mode is always active, and if a bind(or singleton) is defined for a service, it uses it; otherwise, it resolves it automatically.

Using Service Provider in Falcon Container

You can also use service providers. To do this, you need to create a class that extends ServiceProvider. You can have a directory called providers and place your providers there.

Creating a ServiceProvider

namespace HesamMousavi\FalconContainer\Providers;

use HesamMousavi\FalconContainer\FalconServiceProvider;
use HesamMousavi\FalconContainer\Test;

class TestServiceProvider extends FalconServiceProvider {
    public function register() {
        $this->container->singleton('test', Test::class);
    }

    public function boot() {}
}

Registering Providers

Each provider consists of two methods: register and boot. As you know, first the register method of all providers is executed, then the boot method is called.

providers.php File

Then in a file, for example named providers.php, you should include the path to the created provider.

<?php
return [
    \HesamMousavi\FalconContainer\Providers\TestServiceProvider::class,
];

Providers

After creating an instance of the container, you can run all providers by calling the runProviders method and passing the path to the providers.php file.

$container = \HesamMousavi\FalconContainer\FalconContainer::getInstance();
$container->runProviders(__DIR__.'/bootstrap/providers.php');

These steps help you use service providers in your Falcon Container plugin, adding more capabilities to your project. 🚀

hesam-mousavi/falcon-container 适用场景与选型建议

hesam-mousavi/falcon-container 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 25 次下载、GitHub Stars 达 3, 最近一次更新时间为 2024 年 10 月 14 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 hesam-mousavi/falcon-container 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 hesam-mousavi/falcon-container 我们能提供哪些服务?
定制开发 / 二次开发

基于 hesam-mousavi/falcon-container 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-10-14