Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/deprecated-packages/defaultautowire
[DEPRECATED] Use Symfony 3.3 instead, see →
https://github.com/deprecated-packages/defaultautowire
autowire autowiring clean-code dependency-injection symfony symplify
Last synced: 10 days ago
JSON representation
[DEPRECATED] Use Symfony 3.3 instead, see →
- Host: GitHub
- URL: https://github.com/deprecated-packages/defaultautowire
- Owner: deprecated-packages
- License: mit
- Created: 2016-01-30T20:31:47.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2017-05-05T11:21:09.000Z (over 7 years ago)
- Last Synced: 2024-11-25T16:46:14.866Z (about 1 month ago)
- Topics: autowire, autowiring, clean-code, dependency-injection, symfony, symplify
- Language: PHP
- Homepage: https://www.tomasvotruba.cz/blog/2017/05/07/how-to-refactor-to-new-dependency-injection-features-in-symfony-3-3/
- Size: 95.7 KB
- Stars: 6
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Default Autowire
[![Build Status](https://img.shields.io/travis/Symplify/DefaultAutowire/master.svg?style=flat-square)](https://travis-ci.org/Symplify/DefaultAutowire)
[![Code Coverage](https://img.shields.io/scrutinizer/coverage/g/Symplify/DefaultAutowire.svg?style=flat-square)](https://scrutinizer-ci.com/g/Symplify/DefaultAutowire)
[![Downloads](https://img.shields.io/packagist/dt/symplify/default-autowire.svg?style=flat-square)](https://packagist.org/packages/symplify/default-autowire)**This bundle turns on autowire for you!**
It turns this:
```yaml
# app/config/config.yml
services:
PriceCalculator:
autowire: trueProductRepository:
autowire: trueUserFactory:
autowire: true
```Into this:
```yaml
# app/config/config.yml
services:
PriceCalculator: ~
ProductRepository: ~
UserFactory: ~
```# Install
```bash
composer require symplify/default-autowire
```Add bundle to `AppKernel.php`:
```php
final class AppKernel extends Kernel
{
public function registerBundles(): array
{
$bundles = [
new Symplify\DefaultAutowire\SymplifyDefaultAutowireBundle(),
// ...
];
}
}
```And that's it!
# Features
## Multiple service of one type? Set preferred one
In case you have multiple connections, entity managers or decorated service,
**you can set default preferred service (name) for each type (class or interface)**.To make it easier for you, there are few default values. You can change them or add new ones.
```yaml
# app/config/cofing.yml
symplify_default_autowire:
autowire_types:
Doctrine\ORM\EntityManager: 'doctrine.orm.default_entity_manager'
Doctrine\ORM\EntityManagerInterface: 'doctrine.orm.default_entity_manager'
Doctrine\Portability\Connection: 'database_connection'
Symfony\Component\EventDispatcher\EventDispatcher: 'event_dispatcher'
Symfony\Component\EventDispatcher\EventDispatcherInterface: 'event_dispatcher'
Symfony\Component\Translation\TranslatorInterface: 'translator'
```## Contributing
Send [issue](https://github.com/Symplify/Symplify/issues) or [pull-request](https://github.com/Symplify/Symplify/pulls) to main repository.