PHP Classes
elePHPant
Icontem

COCI: Dependency injection container using closures

Recommend this page to a friend!
  Info   View files Documentation   View files View files (16)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog    
Last Updated Ratings Unique User Downloads Download Rankings
2017-04-04 (2 years ago) RSS 2.0 feedNot enough user ratingsTotal: 44 All time: 9,615 This week: 468Up
Version License PHP version Categories
coci 1.0GNU General Publi...5PHP 5, Design Patterns
Description Author

This class is a dependency injection container using closures.

It can set one or more callback functions that define code that creates objects of given types.

Classes that need to create objects of those types call this container class so it returns an object of the requested type.

  Performance   Level  
Name: carlos carvalho <contact>
Classes: 4 packages by
Country: Brazil Brazil
Age: 36
All time rank: 3368262 in Brazil Brazil
Week rank: 686 Up45 in Brazil Brazil Up
Innovation award
Innovation award
Nominee: 1x

 

Details

COCI

PHP Simple Injection, use classe in project.

Build Status Latest Stable Version Total Downloads Latest Unstable Version License

Install

Composer install

  {
     "require":"carlosocarvalho/coci": "1.0.0"
  }
  

Example use

<?php
  
  require "vendor/autoload.php";
  
  use COC\COCI\Injection;
  $inj = new Injection;

Create Classes Injections with Agregration (Person)

  Class Person(){
     private $person ;
    class function __construct(TypePerson $typePerson){
           $this->person = $typePerson;
     }   
  
  }
  

Create Classes Injections(TypePerson)

  
  
  <?php    
  Class TypePerson(){
    private $type;
    setType($type){
      $this->type;
    }
    getType(){
      return $this->type;
    }
  }
    

Inject Classes Closure

 <?php 
   $inj->set('TypePerson',function(){
      return new TypePerson();
   })
   
  $inj->set('Person',function() use ($inj){
     return new Person($inj->get('TypePerson'));
   });

Inject Classes By Reflection

 <?php 
   
   $inj->get('TypePerson');
  Files folder image Files  
File Role Description
Files folder imageCOC (1 file)
Files folder imageDatabase (1 file)
Files folder imagetests (1 file)
Files folder imagevendor (1 file, 1 directory)
Accessible without login Plain text file .travis.yml Data Auxiliary data
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Plain text file composer.lock Data Auxiliary data
Plain text file index.php Class Class source
Accessible without login Plain text file phpunit.xml Data Auxiliary data
Accessible without login Plain text file README.md Doc. Documentation

  Files folder image Files  /  COC  
File Role Description
  Plain text file Injection.php Class Class source

  Files folder image Files  /  Database  
File Role Description
  Plain text file Connection.php Class Class source

  Files folder image Files  /  tests  
File Role Description
  Plain text file FooTest.php Class Class source

  Files folder image Files  /  vendor  
File Role Description
Files folder imagecomposer (6 files)
  Accessible without login Plain text file autoload.php Aux. Auxiliary script

  Files folder image Files  /  vendor  /  composer  
File Role Description
  Accessible without login Plain text file autoload_classmap.php Aux. Auxiliary script
  Accessible without login Plain text file autoload_namespaces.php Aux. Auxiliary script
  Accessible without login Plain text file autoload_psr4.php Aux. Auxiliary script
  Plain text file autoload_real.php Class Class source
  Plain text file ClassLoader.php Class Class source
  Accessible without login Plain text file installed.json Data Auxiliary data

 Version Control Unique User Downloads Download Rankings  
 100%
Total:44
This week:0
All time:9,615
This week:468Up