Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ashwanthkumar/ioc-php
Simple Inversion of Control system in PHP, implemented as a part of my final year project.
https://github.com/ashwanthkumar/ioc-php
Last synced: about 6 hours ago
JSON representation
Simple Inversion of Control system in PHP, implemented as a part of my final year project.
- Host: GitHub
- URL: https://github.com/ashwanthkumar/ioc-php
- Owner: ashwanthkumar
- Created: 2011-12-07T15:40:43.000Z (almost 13 years ago)
- Default Branch: master
- Last Pushed: 2016-01-16T16:22:25.000Z (almost 9 years ago)
- Last Synced: 2024-04-14T09:19:01.986Z (7 months ago)
- Language: PHP
- Homepage:
- Size: 6.84 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.markdown
Awesome Lists containing this project
README
[![No Maintenance Intended](http://unmaintained.tech/badge.svg)](http://unmaintained.tech/)
# IoC (Inversion of Control) Module of BlueIgnis
#### Written by Ashwanth Kumar \
#### Version 0.1## Introduction
An attempt to create a dependency injection for PHP. Current this module independently implements a IoC container (called Registry) for storing all the Services and their corresponding object to service the request which can be injected dynamically.## Design Goal:
- Add an Annotation @Inject("ServiceName") to dynamically assign the value of the property or object from our little IoC (Inversion of Control) Registry.
- Create a Registry of Services, which are loaded and can always be re-used anytime in the code using @Inject("ServiceName")This module uses [**ARO**](https://github.com/ashwanthkumar/aro-php "Visit ARO project website") in *BlueIgnis* for implementing @Inject style dependency injection. For normal independent usages refer **Usages Example**
## Usage Examples:
### Add a service to the IoC Container
// Load the IoC Module
require_once("/path/to/lib/ioc/IoC.php");
// Create a DB Connection
$dao = new PDO($dsn, $user, $pass);// Get the Registry Instance
$container = Registry::get();
$container->addService("DAO", $dao, "DB Connection"); // Valid
// throws ServiceNameAlreadyTakenException Exception
$container->addService("DAO", new stdClass, "Another sample Object Instance");
### Get a particular Service
// Load the IoC Module
require_once("/path/to/lib/ioc/IoC.php");
// Get the Registry Instance
$registry = Registry::get();
$db = $registry->getService("DAO"); // Valid
$db = $registry->getService("DoNotExist"); // throws ServiceNotFound Exception### Get all the services
// Load the IoC Module
require_once("/path/to/lib/ioc/IoC.php");// Get the Registry Instance
$registry = Registry::get();
$service_list = $registry->listAll();// Loop through the list of services and display its properties
foreach($service_list as $service) {
echo $service['name'] . '\n'; // Name of the service
$obj = $service['object'] . '\n'; // Object Instance
echo $service['description'] . '\n'; // Description of the Service
}