Download the PHP package laborra/php-ioc without Composer
On this page you can find all versions of the php package laborra/php-ioc. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download laborra/php-ioc
More information about laborra/php-ioc
Files in laborra/php-ioc
Package php-ioc
Short Description PHP framework for managing dependency injection
License BSD-3-Clause
Informations about the package php-ioc
PHP Inversion of Control
IoC framework for PHP
Using an Inversion Of Control container you can define the business logic of an application without depending on the specific framework. All the core logic can be placed in simple PHP classes, where dependency are injected by the container.
Installation
The library can be installed using Composer:
Basic Usage
The main library class is AppContext, that can be built using the ContextFactory helper,
Below is an example of context configuration with a bas
Features
The current supported features are:
- Bean definition as request singleton scope
- Definition of relationships between beans
- Constructor arguments
- Class calls after bean creation
- Definition of context parameters
- Configuration based on PHP array, ConfigurationBuilder helper and YAML files
Features available in future releases:
- Prototype scope for beans
- Support for Aspect Oriented Programming
- Cache for configuration and application context
- Support for multiple configuration files
Defining Application Modules
Using an IoC container it is possible to build modularized applications. Each module consists of a set of library classes, a set of dependency and list of bean that must be implemented by the module client. In this way, you can define an entire unit of business logic without referencing any framework or specific environment.
Example of user management module
beans: userService: class: UserService properties: userDAO: @userDAO
When using the module in a complete application, we have to implement the IUserDAO interface and declare it as a context bean.
class SpecificUserDAO implements IUserDAO { function getByUsername ($username) { // Query the database, possible using framework specific helpers // ... }
function create ()
{
// ...
}
}
beans: userDAO: class: SpecificUserDAO
ConfigurationBuilder utility
In order to produce readable and maintenable configuration files, you can use the ConfigurationBuilder class. Below there is an example of a configuration built using this class.
You can extend the configuration builder class to add your own custom methods. Doing so, you can create shortcut to some very often used configuration parts.