定制 llenon/smart-alias-bundle 二次开发

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

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

llenon/smart-alias-bundle

最新稳定版本:v1.0.6

Composer 安装命令:

composer require llenon/smart-alias-bundle

包简介

A Symfony bundle that automatically registers service aliases and tags using attributes.

README 文档

README

Gere automaticamente aliases de serviços em tempo de execução com base em atributos no Symfony. Suporte a singleton e array de serviços, com cache em produção.

Tests
📦 Compatível com Symfony 7.2+

⚙️ Instalação

composer require llenon/smart-alias-bundle

Se necessário, adicione o bundle manualmente:

// config/bundles.php
return [
    Llenon\SmartAlias\SmartAliasBundle::class => ['all' => true],
];

✨ Como usar

#[SmartAlias] – singleton obrigatório

Use quando apenas uma implementação da interface deve ser registrada. Duplicidades lançarão exceção.

use Llenon\SmartAlias\Attributes\SmartAlias;

#[SmartAlias(ReportProcessorInterface::class)]
class ReportProcessorA implements ReportProcessorInterface
{
    public function process(): void
    {
        // ...
    }
}

No seu serviço:

class ReportHandler
{
    public function __construct(private ReportProcessorInterface $processor)
    {
        $this->processor->process();
    }
}

#[SmartAliasMultiple] – array de serviços

Use quando quiser injeção múltipla:

use Llenon\SmartAlias\Attributes\SmartAliasMultiple;

#[SmartAliasMultiple(ReportProcessorInterface::class)]
class ReportProcessorA implements ReportProcessorInterface {}

#[SmartAliasMultiple(ReportProcessorInterface::class)]
class ReportProcessorB implements ReportProcessorInterface {}

Injetando múltiplos serviços:

class ReportAggregator
{
    public function __construct(
        /** @var ReportProcessorInterface[] */
        private iterable $processors
    ) {
    }
}

🧪 Testes

composer test

🔁 Cache & Modo Dev

  • Em produção, os aliases são cacheados para performance.
  • Em modo dev, os aliases são atualizados automaticamente em cada requisição.
  • Limpe o cache com:
bin/console cache:clear

🧩 Contribuindo

  1. Fork o repositório
  2. Crie sua branch (git checkout -b feature/MinhaFeature)
  3. Commit suas alterações (git commit -am 'add: nova funcionalidade')
  4. Push na sua branch (git push origin feature/MinhaFeature)
  5. Abra um Pull Request

📝 Licença

MIT © lucyannlenon

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-06-03