Download the PHP package bigbit/oddin without Composer
On this page you can find all versions of the php package bigbit/oddin. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package oddin
ODDIN - On Demand Dependency INjection
About
Sometimes coding is a pain. Your boss needs it now or simply you are bored writing all sugar again and again and ...
If you are using DI in your projects, you have to write property declarations and initialize them in constructors. You can use dependency container or define injectable constructor arguments. It depends on framework used. For of PHP7.4.0 only, 7.4.1 breaks functionality, php bug #78904.
With ODDIN you can skip constructor part. Just declare properties and access properties anytime you need. Keep in mind those properties becomes accessible from anywhere by magic __get method. Your preferred IDE will help you deal with that problem
How it works
PHP classes can have magic methods. The get magic method is invoked every time you want to use unset property. DIResolver uses parser to get dependency metadata from class or deprecated property annotations. InjectsOnDemand trait defines magic get method, which handles all our property requests. Once property is initialized by trait, magic method is not called again.
Pros
- less coding
- dependency instantiation on demand (lazy - not before constructor, if properly defined in DI container)
Cons
- all properties becomes public ? all injectables are "public"
- antipattern ? use it only for prototyping, clean the code later.
Purpouse
Cleaner controller classes, less resource demanding. But it's up to you, where you use ODDIN.
Known Issues
- no code fixer yet
Quick start
You can use any DI container, which implements Psr\Container\ContainerInterface. For quick start, you can use Bootstrap class, which uses SmartContainer.
Other frameworks
You can request other frameworks support or write you own bootstrap based on Bootstrap class.
PHP-DI comparison
@todo
Cache Generator
Experimental implementation of cache generator was added. If your project has phpstan installed, it's recommended to install tracy/tracy as well. Oddin uses Psr\SimpleCache\CacheInterface implementations and Symfony as default.
Creating cache is not necessary, but recommended for production environments:
Arguments for cli commands are derived from adapter constructor.
Instantiating cache:
@TODO - Code Fixer
Cli command for fixing code. It will remove class property annotations, declare properties and add constructor or getters and container to constructor.