adtechpotok/symfony-aware

意识包

安装: 48

依赖者: 1

建议者: 0

安全: 0

星级: 3

观察者: 1

分支: 0

开放问题: 0

类型:symfony-bundle

0.0.5 2018-06-27 20:38 UTC

This package is not auto-updated.

Last update: 2024-09-29 06:20:09 UTC


README

Build Status License

意识

使用示例

服务
<?php

use Adtechpotok\Aware\Interfaces\EntityManagerAwareInterface;
use Adtechpotok\Aware\Traits\EntityManagerAwareTrait;

class SomeClass implements EntityManagerAwareInterface
{
    use EntityManagerAwareTrait;
    
    public function someMethod()
    {
        dump($this->em); // $em - дефолтный EntityManager, аналог '@doctrine.orm.default_entity_manager'
    }
}
声明服务
services:
    some.service:
        class: SomeClass
        calls:
            - {method: setEntityManager, arguments: ['@doctrine.orm.default_entity_manager']}
匹配表
在 Symfony >= 3.3 中声明服务
services:
    _defaults:
        autowire: true
        
    some.service:
        class: SomeClass

重要! 在声明需要使用标签的服务时,这种方法不适用,因为 Symfony 在 autowire 时会忽略标签。