PHP Classes

COCI: Dependency injection container using closures

Recommend this page to a friend!
  Info   Documentation   View files Files   Install with Composer Install with Composer   Download Download   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
Not enough user ratingsTotal: 49 All time: 10,731 This week: 96Up
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.

Picture of Carlos Carvalho
  Performance   Level  
Name: Carlos Carvalho <contact>
Classes: 8 packages by
Country: Brazil Brazil
Innovation award
Innovation award
Nominee: 2x

Documentation

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 (16)  
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 (16)  /  COC  
File Role Description
  Plain text file Injection.php Class Class source

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

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

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

  Files folder image Files (16)  /  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

The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page.
Install with Composer Install with Composer
 Version Control Unique User Downloads Download Rankings  
 100%
Total:49
This week:0
All time:10,731
This week:96Up